-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from vdhicts/feature/initial-version
Initial version
- Loading branch information
Showing
16 changed files
with
704 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
name: Bug report | ||
about: Create a report to help us improve | ||
title: "" | ||
labels: bug | ||
assignees: dvdheiden | ||
|
||
--- | ||
|
||
## Describe the bug | ||
|
||
A clear and concise description of what the bug is. | ||
|
||
## Reproduction | ||
|
||
Steps to reproduce the behavior. | ||
|
||
## Expected behavior | ||
|
||
A clear and concise description of what you expected to happen. | ||
|
||
## Actual behavior | ||
|
||
Describe the behavior as it is right now. | ||
|
||
## Additional information | ||
|
||
Anything else you want to provide. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
name: Feature request | ||
about: Suggest an idea for this project | ||
title: "" | ||
labels: feature | ||
assignees: dvdheiden | ||
|
||
--- | ||
|
||
## Goal | ||
|
||
A clear and concise description of what the problem is. Ex. I think this could be easier when... | ||
|
||
## Additional information | ||
|
||
Add any other context or screenshots about the feature request here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Changes | ||
|
||
Provide a summary of your changes. | ||
|
||
# Checks | ||
|
||
- [ ] The changelog is updated (when applicable) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Keep A Changelog | ||
|
||
on: [push] | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
php-versions: ['8.0', '8.1'] | ||
|
||
name: PHP ${{ matrix.php-versions }} | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php-versions }} | ||
|
||
- name: Install Dependencies | ||
run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress | ||
|
||
- name: Execute tests (Unit and Feature tests) via PHPUnit | ||
run: | | ||
vendor/bin/phpunit | ||
- name: Execute static analysis | ||
run: | | ||
vendor/bin/phpstan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
composer.lock | ||
/vendor/ | ||
/.idea/ | ||
/build/ | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to | ||
[Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [1.0.0] - 2022-02-15 | ||
|
||
### Added | ||
|
||
- Initial version of this parser. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,108 @@ | ||
# keepachangelog-parser | ||
|
||
Parser for the Keep A Changelog standard. | ||
|
||
## Requirements | ||
|
||
This package requires at least PHP 8.0 or newer. | ||
|
||
## Installation | ||
|
||
You can install the package via composer: | ||
|
||
`composer require vdhicts/keepachangelog-parser` | ||
|
||
## Usage | ||
|
||
This package is intended to be easy to use. | ||
|
||
### Parsing the changelog | ||
|
||
```php | ||
$content = file_get_contents('CHANGELOG.md'); | ||
|
||
$parser = new \Vdhicts\KeepAChangelog\Parser(); | ||
$changelog = $parser->parse($content); | ||
``` | ||
|
||
### Accessing the changelog | ||
|
||
The parser will return a `Changelog` models, with contains a collection of `Release` models. The `Release` model | ||
contains a collection of `Section` models. | ||
|
||
The changelog has several methods the retrieve information: | ||
|
||
```php | ||
// Get the description of the changelog, which returns an array of lines | ||
$descriptionHtml = implode('<br>', $changelog->getDescription()); | ||
|
||
// Determine if the changelog has any releases | ||
$changelog->hasReleases(); | ||
|
||
// Get the unreleased section | ||
$unreleased = $changelog->getUnreleased(); | ||
|
||
// Get the latest release | ||
$latestRelease = $changelog->getLatestRelease(); | ||
``` | ||
|
||
The release has several methods to get information about the release: | ||
|
||
```php | ||
// Determine if the current one is the unreleased section | ||
$isUnreleased = $release->isUnreleased(); | ||
|
||
// Get the version for the release | ||
$version = $release->getVersion(); | ||
|
||
// Get the release date, will be null when not released or a date isn't provided | ||
$data = $release->getReleasedAt(); | ||
|
||
// Get a specific section of the release | ||
$added = $release->getSection(Section::ADDED); | ||
|
||
// Get the collection of sections for the release | ||
$sections = $release->getSections(); | ||
``` | ||
|
||
The section consists of a type (like Added, etc.) and an array of entries: | ||
|
||
```php | ||
$type = $section->getType(); | ||
$entries = $section->getEntries(); | ||
|
||
$entriesHtml = implode('<br>', $entries); | ||
``` | ||
|
||
## Tests | ||
|
||
Unit tests are available in the `tests` folder. Run with: | ||
|
||
`composer test` | ||
|
||
When you want a code coverage report which will be generated in the `build/report` folder. Run with: | ||
|
||
`composer test-coverage` | ||
|
||
## Contribution | ||
|
||
Any contribution is welcome, but it should meet the PSR-12 standard and please create one pull request per feature/bug. | ||
In exchange, you will be credited as contributor on this page. | ||
|
||
## Security | ||
|
||
If you discover any security related issues in this or other packages of Vdhicts, please email [email protected] | ||
instead of using the issue tracker. | ||
|
||
## Support | ||
|
||
If you encounter a problem with this parser or has a question about it, feel free to open an issue on GitHub. | ||
|
||
## License | ||
|
||
This package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT). | ||
|
||
## About Vdhicts | ||
|
||
[Vdhicts](https://www.vdhicts.nl) is the name of my personal company for which I work as freelancer. Vdhicts develops | ||
and implements IT solutions for businesses and educational institutions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"name": "vdhicts/keepachangelog-parser", | ||
"description": "Parser for the Keep A Changelog standard", | ||
"keywords": [ | ||
"changelog", | ||
"parser" | ||
], | ||
"homepage": "https://github.com/vdhicts/keepachangelog-parser", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Dick van der Heiden", | ||
"email": "[email protected]", | ||
"homepage": "https://www.vdhicts.nl", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"php": "^8.0|^8.1", | ||
"illuminate/support": "^8.0|^9.0", | ||
"league/commonmark": "^2.2", | ||
"symfony/css-selector": "^6.0", | ||
"symfony/dom-crawler": "^6.0" | ||
}, | ||
"require-dev": { | ||
"phpstan/phpstan": "^1.2", | ||
"phpunit/phpunit": "^9.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Vdhicts\\KeepAChangelog\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Vdhicts\\KeepAChangelog\\Tests\\": "tests" | ||
} | ||
}, | ||
"scripts": { | ||
"test": "vendor/bin/phpunit --no-coverage", | ||
"test-coverage": "vendor/bin/phpunit", | ||
"analyse": "vendor/bin/phpstan" | ||
}, | ||
"config": { | ||
"sort-packages": true | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
parameters: | ||
level: 5 | ||
paths: | ||
- src | ||
- tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> | ||
<coverage> | ||
<include> | ||
<directory suffix=".php">src/</directory> | ||
</include> | ||
<report> | ||
<html outputDirectory="build/coverage"/> | ||
</report> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="Unit Tests"> | ||
<directory>tests/Unit</directory> | ||
</testsuite> | ||
</testsuites> | ||
<logging/> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Vdhicts\KeepAChangelog\Models; | ||
|
||
use Illuminate\Support\Collection; | ||
|
||
class Changelog | ||
{ | ||
private Collection $releases; | ||
private array $description; | ||
|
||
public function __construct(Collection $releases, array $description = []) | ||
{ | ||
$this->releases = $releases; | ||
$this->description = $description; | ||
} | ||
|
||
public function getReleases(): Collection | ||
{ | ||
return $this->releases; | ||
} | ||
|
||
public function hasReleases(): bool | ||
{ | ||
return $this | ||
->releases | ||
->isNotEmpty(); | ||
} | ||
|
||
public function getUnreleased(): ?Release | ||
{ | ||
return $this | ||
->releases | ||
->filter(function (Release $release) { | ||
return $release->isUnreleased(); | ||
}) | ||
->first(); | ||
} | ||
|
||
public function getLatestRelease(): Release | ||
{ | ||
return $this | ||
->releases | ||
->last(); | ||
} | ||
|
||
public function getDescription(): array | ||
{ | ||
return $this->description; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Vdhicts\KeepAChangelog\Models; | ||
|
||
use DateTimeInterface; | ||
use Illuminate\Support\Collection; | ||
|
||
class Release | ||
{ | ||
public const UNRELEASED = 'Unreleased'; | ||
|
||
private string $version; | ||
private ?DateTimeInterface $releasedAt; | ||
private Collection $sections; | ||
|
||
public function __construct(string $version, DateTimeInterface $releasedAt = null) | ||
{ | ||
$this->version = $version; | ||
$this->releasedAt = $releasedAt; | ||
$this->sections = collect(); | ||
} | ||
|
||
public function getVersion(): string | ||
{ | ||
return $this->version; | ||
} | ||
|
||
public function getReleasedAt(): ?DateTimeInterface | ||
{ | ||
return $this->releasedAt; | ||
} | ||
|
||
public function getSections(): Collection | ||
{ | ||
return $this->sections; | ||
} | ||
|
||
public function getSection(string $type): ?Section | ||
{ | ||
return $this | ||
->sections | ||
->get($type); | ||
} | ||
|
||
public function setSection(Section $section): self | ||
{ | ||
$this | ||
->sections | ||
->put($section->getType(), $section); | ||
return $this; | ||
} | ||
|
||
public function isUnreleased(): bool | ||
{ | ||
return $this->version === self::UNRELEASED; | ||
} | ||
} |
Oops, something went wrong.