Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce experimental support for CUSTOM PLACEHOLDERS #837

Merged
merged 4 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ Table of supported placeholders allowed to be used in the `template` and `empty_
| `${{UNCATEGORIZED_COUNT}}` | The count of PRs and changes which were not categorized. No label overlapping with category labels | |
| `${{OPEN_COUNT}}` | The count of open PRs. Will only be fetched if `includeOpen` is configured. | |
| `${{IGNORED_COUNT}}` | The count of PRs and changes which were specifically ignored from the changelog. | |
| `${{DAYS_SINCE}}` | Days between the 2 releases. Requires `fetchReleaseInformation` to be enabled. | * |
| `${{DAYS_SINCE}}` | Days between the 2 releases. Requires `fetchReleaseInformation` to be enabled. | x |

### Configuration Specification

Expand Down
2 changes: 0 additions & 2 deletions __tests__/tags.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {resolveConfiguration} from '../src/utils'
import {ReleaseNotesBuilder} from '../src/releaseNotesBuilder'
import { TagInfo, sortTags, filterTags } from '../src/tags';

jest.setTimeout(180000)
Expand Down
52 changes: 46 additions & 6 deletions __tests__/transform.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {buildChangelog} from '../src/transform'
import {PullRequestInfo} from '../src/pullRequests'
import moment from 'moment'
import { DefaultConfiguration, Configuration } from '../src/configuration';
import { Configuration, DefaultConfiguration } from '../src/configuration';
import { DefaultDiffInfo } from '../src/commits';

jest.setTimeout(180000)
Expand Down Expand Up @@ -41,7 +41,7 @@ mergedPullRequests.push(
repoName: 'test-repo',
labels: new Set<string>(),
milestone: '',
body: 'no magic body for this matter',
body: 'no magic body1 for this matter',
assignees: [],
requestedReviewers: [],
approvedReviewers: [],
Expand All @@ -59,7 +59,7 @@ mergedPullRequests.push(
repoName: 'test-repo',
labels: new Set<string>(),
milestone: '',
body: 'no magic body for this matter',
body: 'no magic body2 for this matter',
assignees: [],
requestedReviewers: [],
approvedReviewers: [],
Expand All @@ -77,7 +77,7 @@ mergedPullRequests.push(
repoName: 'test-repo',
labels: new Set<string>(),
milestone: '',
body: 'no magic body for this matter',
body: 'no magic body3 for this matter',
assignees: [],
requestedReviewers: [],
approvedReviewers: [],
Expand All @@ -95,7 +95,7 @@ mergedPullRequests.push(
repoName: 'test-repo',
labels: new Set<string>(),
milestone: '',
body: 'no magic body for this matter',
body: 'no magic body4 for this matter',
assignees: [],
requestedReviewers: [],
approvedReviewers: [],
Expand Down Expand Up @@ -582,4 +582,44 @@ it('Use exclude labels to not include a PR within a category.', async () => {
expect(resultChangelog).toStrictEqual(
`## 🚀 Features and 🐛 Issues\n\n- [ABC-1234] - this is a PR 3 title message\n - PR: #3\n\n## 🚀 Features and/or 🐛 Issues But No 🐛 Fixes\n\n- [ABC-1234] - this is a PR 1 title message\n - PR: #1\n\n`
)
})
})


it('Extract custom placeholder from PR body and replace in global template', async () => {
const customConfig = Object.assign({}, configuration)
customConfig.custom_placeholders = [
{
name: "C_PLACEHOLDER_1",
source: "BODY",
transformer: {
pattern: '.+ (b....).+',
target: '- $1'
}
},
{
name: "C_PLACEHOLER_2",
source: "BODY",
transformer: {
pattern: '.+ b(....).+',
target: '\n- $1'
}
}
]
customConfig.template = "${{CHANGELOG}}\n\n${{C_PLACEHOLER_2[2]}}\n\n${{C_PLACEHOLER_2[*]}}${{C_PLACEHOLDER_1[7]}}${{C_PLACEHOLER_2[1493]}}"
customConfig.pr_template = "${{BODY}} ----> ${{C_PLACEHOLDER_1}}"

const resultChangelog = buildChangelog(DefaultDiffInfo, mergedPullRequests, {
owner: 'mikepenz',
repo: 'test-repo',
fromTag: { name: '1.0.0' },
toTag: { name: '2.0.0' },
includeOpen: false,
failOnError: false,
fetchReviewers: false,
fetchReleaseInformation: false,
commitMode: false,
configuration: customConfig
})

expect(resultChangelog).toStrictEqual(`## 🚀 Features\n\nno magic body1 for this matter ----> - body1\nno magic body3 for this matter ----> - body3\n\n## 🐛 Fixes\n\nno magic body2 for this matter ----> - body2\nno magic body3 for this matter ----> - body3\n\n## 🧪 Others\n\nno magic body4 for this matter ----> - body4\n\n\n\n\n- ody3\n\n\n- ody1\n- ody2\n- ody3\n- ody4`)
})
189 changes: 131 additions & 58 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface Configuration {
transformers: Transformer[]
tag_resolver: TagResolver
base_branches: string[]
custom_placeholders?: Placeholder[]
}

export interface Category {
Expand Down Expand Up @@ -57,6 +58,12 @@ export interface TagResolver {
transformer?: Transformer // transforms the tag name using the regex, run after the filter
}

export interface Placeholder {
name: string // the name of the new placeholder
source: string // the src placeholder which will be used to apply the transformer on
transformer: Transformer // the transformer to use to transform the original placeholder into the custom placheolder
}

export const DefaultConfiguration: Configuration = {
max_tags_to_fetch: 200, // the amount of tags to fetch from the github API
max_pull_requests: 200, // the amount of pull requests to process
Expand Down Expand Up @@ -94,5 +101,6 @@ export const DefaultConfiguration: Configuration = {
filter: undefined, // filter out all tags not matching the regex
transformer: undefined // transforms the tag name using the regex, run after the filter
},
base_branches: [] // target branches for the merged PR ignoring PRs with different target branch, by default it will get all PRs
base_branches: [], // target branches for the merged PR ignoring PRs with different target branch, by default it will get all PRs
custom_placeholders: []
}
4 changes: 2 additions & 2 deletions src/releaseNotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Commits, filterCommits, DiffInfo, DefaultDiffInfo} from './commits'
import {Configuration, DefaultConfiguration} from './configuration'
import {PullRequestInfo, PullRequests} from './pullRequests'
import {Octokit} from '@octokit/rest'
import {buildChangelog, fillAdditionalPlaceholders} from './transform'
import {buildChangelog, replaceEmptyTemplate} from './transform'
import {failOrError} from './utils'
import {TagInfo} from './tags'

Expand Down Expand Up @@ -61,7 +61,7 @@ export class ReleaseNotes {

if (mergedPullRequests.length === 0) {
core.warning(`⚠️ No pull requests found`)
return fillAdditionalPlaceholders(
return replaceEmptyTemplate(
this.options.configuration.empty_template || DefaultConfiguration.empty_template,
this.options
)
Expand Down
Loading