Skip to content

Commit

Permalink
feat: Order release note issue types (#106)
Browse files Browse the repository at this point in the history
* feat: order release note issue types

* docs: add order in readme
  • Loading branch information
adrianiy committed Dec 1, 2021
1 parent d0794fd commit 9a1eae2
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .releasenotesrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ assets:
decoration:
type/feature: '## :sparkles: '
type/bug: '## :bug: '
order:
- release
- type/feature
- type/bug
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ A **complete markdown** file will be created using your pull request description
- [ignoreTag](/src/configuration#ignore-tag)
- [title](/src/configuration#title)
- [decoration](/src/configuration#decoration)
- [order](/src/configuration#order)
- [preview](/src/configuration#preview)
- [publish](/src/configuration#publish)
- [branch](/src/configuration#branch)
Expand Down
18 changes: 18 additions & 0 deletions src/configuration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [ignoreTag](#ignore-tag)
- [title](#title)
- [decoration](#decoration)
- [order](#order)
- [preview](#preview)
- [publish](#publish)
- [branch](#branch)
Expand Down Expand Up @@ -43,6 +44,7 @@ We support `.yml` and `.json` formats with these options:
| [ignoreTag](#ignore-tag) | `<!--release-notes-ignore-->` | Text inside this comment tag will be ignored in RELEASE NOTES |
| [title](#title) | `RELEASE NOTES` | Title used in output markdown |
| [decoration](#decoration) | [Decoration object](#decoration-object) | Icon decoration for each issue type |
| [order](#order) | `['release', 'refactor', 'enhancement', 'bug', 'style', 'documentation']` | Order of issues in release notes |
| [preview](#preview) | [Preview object](#preview-object) | Customize preview comment |
| [publish](#publish) | `false` | If `true` the output file will be commited to repo |
| [branch](#branch) | `main` | Branch where output will be uploaded |
Expand Down Expand Up @@ -210,6 +212,22 @@ Markdown for a pr tagged with `enhancement` label:
## :zap: Issue title
```

### ORDER
##### Default value `['release', 'refactor', 'enhancement', 'bug', 'style', 'documentation']`

Customize how your issues will be sort in release notes, as usually you'll need to group issues of one kind all together, and
give some preference of ones among others, i.e enhancement > bug

```yml
order:
- release
- refactor
- enhancement
- bug
- style
- documentation
```

---

### PREVIEW
Expand Down
10 changes: 10 additions & 0 deletions src/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export interface Configuration {
title?: string;
// Notes decoration according to type
decoration?: Record<string, string>;
// Order of issue types in release notes
order?: string[];
// Webhooks lis
webhooks?: Record<string, Webhook>;
// Notification configuration
Expand Down Expand Up @@ -110,6 +112,14 @@ const defaultConfiguration: Configuration = {
style: '## :nailcare: ',
documentation: '## :book: ',
},
order: [
'release',
'refactor',
'enhancement',
'bug',
'style',
'documentation'
],
notification: {
style: {
h1: { 'font-size': '3rem', 'margin-top': '2rem' },
Expand Down
12 changes: 12 additions & 0 deletions src/generator/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ export abstract class Generator {
return pullRequestsList;
}

protected _sortPullRequestByType(pullRequest: PullRequest[]): PullRequest[] {
if (this._configuration.order) {
return this._configuration.order.reduce((acc: PullRequest[], currType: string) => {
const group = pullRequest.filter(issue => issue.labels.includes(currType) && !acc.includes(issue));

return acc.concat(group);
}, []);
}

return pullRequest;
}

protected async _labelPullRequests(pullRequests: PullRequest[]): Promise<void> {
const willPublish = !this._configuration.snapshot && (!this._interactive || (await confirmPullRequestLabeling()));

Expand Down
2 changes: 1 addition & 1 deletion src/generator/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class GithubGenerator extends Generator {

protected _parsePullRequests(pullRequests: PullRequest[]): string {
const oldFile = this._configuration.split ? '' : this._loadMarkdown();
const notes = pullRequests.map(this._composeText);
const notes = this._sortPullRequestByType(pullRequests).map(this._composeText);
const title = this._configuration.title?.length ? `# ${this._configuration.title}\n` : '';
const markdown = [title, ...notes, oldFile].join('\n');

Expand Down

0 comments on commit 9a1eae2

Please sign in to comment.