Skip to content

Commit

Permalink
feat: add custom formats with header and title (#110)
Browse files Browse the repository at this point in the history
* feat: allow custom format and headers

* feat: add documentation
  • Loading branch information
adrianiy committed May 12, 2022
1 parent faa38a4 commit 84300fa
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ A **complete markdown** file will be created using your pull request description
- [labels](/src/configuration#labels)
- [ignoreTag](/src/configuration#ignore-tag)
- [title](/src/configuration#title)
- [header](/src/configuration#header)
- [format](/src/configuration#format)
- [decoration](/src/configuration#decoration)
- [order](/src/configuration#order)
- [preview](/src/configuration#preview)
Expand Down
25 changes: 25 additions & 0 deletions src/configuration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
- [labels](#labels)
- [ignoreTag](#ignore-tag)
- [title](#title)
- [header](#header)
- [format](#format)
- [decoration](#decoration)
- [order](#order)
- [preview](#preview)
Expand Down Expand Up @@ -43,6 +45,8 @@ We support `.yml` and `.json` formats with these options:
| [labels](#labels) | `[ 'release-note' ]` | Only PRs with these labels will be used in generation process |
| [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 |
| [header](#header) | `null` | Text to be used on header section over release notes. Useful for `mdx` files |
| [format](#format) | `.md` | File format used in save |
| [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 |
Expand Down Expand Up @@ -183,6 +187,27 @@ Title used in output markdown
title: RELEASE NOTES DEMO
```

### HEADER
##### Defualt value `null`

Header above markdown

```yml
hader: |
import { Meta } from 'third-party';
<Meta title="test"/>
```

### FORMAT
##### Default value `.md`

File format

```yml
format: '.stories.mdx'
```

### DECORATION
##### Default value [Decoration object](#decoration-object)

Expand Down
5 changes: 5 additions & 0 deletions src/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export interface Configuration {
name?: string;
// File sufix for splitted content
suffix?: string;
// File format
format?: string;
// Only PRs with this labels will be included in MD
labels?: Labels;
// PR query filter
Expand All @@ -70,6 +72,8 @@ export interface Configuration {
assets?: string[];
// Branch where output will be uploaded
branch?: string;
// Markdown header
header?: string;
// Markdown title
title?: string;
// Notes decoration according to type
Expand All @@ -86,6 +90,7 @@ const defaultConfiguration: Configuration = {
token: 'GITHUB_TOKEN',
out: '.',
name: 'RELEASE-NOTES',
format: '.md',
labels: {
include: ['release-note'],
ignore: ['in-release-note'],
Expand Down
4 changes: 2 additions & 2 deletions src/generator/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ export abstract class Generator {
}

protected _setFilePath(): void {
const { out, name, split, suffix } = this._configuration;
const { out, name, split, suffix, format } = this._configuration;
const outDir = split ? `${out}/release-notes` : out;
const fileName = split ? `${name}-${suffix}` : name;

if (!fs.existsSync(outDir!)) {
fs.mkdirSync(outDir!);
}

this._filePath = `${outDir}/${fileName}.md`;
this._filePath = `${outDir}/${fileName}${format}`;
}

protected async _getPullRequestList(): Promise<PullRequest[]> {
Expand Down
3 changes: 2 additions & 1 deletion src/generator/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ export class GithubGenerator extends Generator {
protected _parsePullRequests(pullRequests: PullRequest[]): string {
const oldFile = this._configuration.split ? '' : this._loadMarkdown();
const notes = this._sortPullRequestByType(pullRequests).map(this._composeText);
const header = this._configuration.header?.length ? `${this._configuration.header}\n` : '';
const title = this._configuration.title?.length ? `# ${this._configuration.title}\n` : '';
const markdown = [title, ...notes, oldFile].join('\n');
const markdown = [header, title, ...notes, oldFile].join('\n');

return markdown;
}
Expand Down

0 comments on commit 84300fa

Please sign in to comment.