Merge pull request #26 from mikepenz/feature/introduce_additional_placeholders

Introduce additional placeholders [milestone, labels, assignees, reviewers]
This commit is contained in:
Mike Penz
2020-10-17 18:21:07 +02:00
committed by GitHub
8 changed files with 59 additions and 40 deletions
+4
View File
@@ -144,7 +144,11 @@ Table of supported placeholders allowed to be used in the `template` configurati
| `${{URL}}` | Url linking to the pull request on GitHub |
| `${{MERGED_AT}}` | The ISO time, the pull request was merged at |
| `${{AUTHOR}}` | Author creating and opening the pull request |
| `${{LABELS}}` | The labels associated with this pull request, joined by `,` |
| `${{MILESTONE}}` | Milestone this PR was part of, as assigned on GitHub |
| `${{BODY}}` | Description/Body of the pull request as specified on GitHub |
| `${{ASSIGNEES}}` | Login names of assigned GitHub users, joined by `,` |
| `${{REVIEWERS}}` | GitHub Login names of specified reviewers, joined by `,` |
### Template placeholders
+11 -3
View File
@@ -88,7 +88,7 @@ it('Should match generated changelog (unspecified fromTag)', async () => {
it('Should match generated changelog (refs)', async () => {
jest.setTimeout(180000)
const configuration = readConfiguration('configuration.json')!!
const configuration = readConfiguration('configs/configuration_all_placeholders.json')!!
const releaseNotes = new ReleaseNotes({
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
@@ -102,8 +102,16 @@ it('Should match generated changelog (refs)', async () => {
console.log(changeLog)
expect(changeLog).toStrictEqual(`## 🧪 Tests
- [CI] Specify Test Case
- PR: #10
[CI] Specify Test Case
10
https://github.com/mikepenz/release-changelog-builder-action/pull/10
2020-10-16T13:59:36.000Z
mikepenz
test
1.0.0
- specify test case
mikepenz, nhoelzl
nhoelzl
`)
})
@@ -0,0 +1,3 @@
{
"pr_template": "${{TITLE}}\n${{NUMBER}}\n${{URL}}\n${{MERGED_AT}}\n${{AUTHOR}}\n${{LABELS}}\n${{MILESTONE}}\n${{BODY}}\n${{ASSIGNEES}}\n${{REVIEWERS}}"
}
-24
View File
@@ -1,24 +0,0 @@
{
"categories": [
{
"title": "## 🚀 Features",
"labels": ["feature"]
},
{
"title": "## 🦄 Internal Features",
"labels": ["internal"]
},
{
"title": "## 🐛 Fixes",
"labels": ["fix"]
},
{
"title": "## 🧪 Tests",
"labels": ["test"]
}
],
"sort": "ASC",
"template": "${{CHANGELOG}}",
"pr_template": "- ${{TITLE}}\n - PR: #${{NUMBER}}",
"empty_template": "- no changes"
}
Generated Vendored
+4 -4
View File
@@ -948,6 +948,7 @@ const pullRequests_1 = __webpack_require__(4217);
const core = __importStar(__webpack_require__(2186));
const configuration_1 = __webpack_require__(5527);
function buildChangelog(prs, config) {
var _a;
// sort to target order
prs = pullRequests_1.sortPullRequests(prs, (config.sort ? config.sort : configuration_1.DefaultConfiguration.sort).toUpperCase() ===
'ASC');
@@ -961,11 +962,10 @@ function buildChangelog(prs, config) {
}
// bring PRs into the order of categories
const categorized = new Map();
if (config.categories) {
for (const category of config.categories) {
const categories = (_a = config.categories) !== null && _a !== void 0 ? _a : configuration_1.DefaultConfiguration.categories;
for (const category of categories) {
categorized.set(category, []);
}
}
const uncategorized = [];
// bring elements in order
for (const [pr, body] of transformedMap) {
@@ -1019,7 +1019,7 @@ function fillTemplate(pr, template) {
transformed = transformed.replace('${{LABELS}}', (_b = (_a = pr.labels) === null || _a === void 0 ? void 0 : _a.join(', ')) !== null && _b !== void 0 ? _b : '');
transformed = transformed.replace('${{MILESTONE}}', (_c = pr.milestone) !== null && _c !== void 0 ? _c : '');
transformed = transformed.replace('${{BODY}}', pr.body);
transformed = transformed.replace('${{ASIGNEES}}', (_e = (_d = pr.assignees) === null || _d === void 0 ? void 0 : _d.join(', ')) !== null && _e !== void 0 ? _e : '');
transformed = transformed.replace('${{ASSIGNEES}}', (_e = (_d = pr.assignees) === null || _d === void 0 ? void 0 : _d.join(', ')) !== null && _e !== void 0 ? _e : '');
transformed = transformed.replace('${{REVIEWERS}}', (_g = (_f = pr.requestedReviewers) === null || _f === void 0 ? void 0 : _f.join(', ')) !== null && _g !== void 0 ? _g : '');
return transformed;
}
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+22 -3
View File
@@ -12,7 +12,10 @@ export interface PullRequestInfo {
author: string
repoName: string
labels: string[]
milestone: string
body: string
assignees: string[]
requestedReviewers: string[]
}
export class PullRequests {
@@ -40,7 +43,16 @@ export class PullRequests {
labels: pr.data.labels.map(function (label) {
return label.name
}),
body: pr.data.body
milestone: pr.data.milestone?.title,
body: pr.data.body,
assignees: pr.data.assignees?.map(function (asignee) {
return asignee.login
}),
requestedReviewers: pr.data.requested_reviewers?.map(function (
reviewer
) {
return reviewer.login
})
}
} catch (e) {
core.warning(`Cannot find PR ${owner}/${repo}#${prNumber} - ${e.message}`)
@@ -76,10 +88,17 @@ export class PullRequests {
mergedAt: moment(pr.merged_at),
author: pr.user.login,
repoName: pr.base.repo.full_name,
labels: pr.labels.map(function (label) {
labels: pr.labels?.map(function (label) {
return label.name
}),
body: pr.body
milestone: pr.milestone?.title,
body: pr.body,
assignees: pr.assignees?.map(function (asignee) {
return asignee.login
}),
requestedReviewers: pr.requested_reviewers?.map(function (reviewer) {
return reviewer.login
})
})
}
+12 -3
View File
@@ -38,11 +38,10 @@ export function buildChangelog(
// bring PRs into the order of categories
const categorized = new Map<Category, string[]>()
if (config.categories) {
for (const category of config.categories) {
const categories = config.categories ?? DefaultConfiguration.categories
for (const category of categories) {
categorized.set(category, [])
}
}
const uncategorized: string[] = []
// bring elements in order
@@ -107,7 +106,17 @@ function fillTemplate(pr: PullRequestInfo, template: string): string {
transformed = transformed.replace('${{URL}}', pr.htmlURL)
transformed = transformed.replace('${{MERGED_AT}}', pr.mergedAt.toISOString())
transformed = transformed.replace('${{AUTHOR}}', pr.author)
transformed = transformed.replace('${{LABELS}}', pr.labels?.join(', ') ?? '')
transformed = transformed.replace('${{MILESTONE}}', pr.milestone ?? '')
transformed = transformed.replace('${{BODY}}', pr.body)
transformed = transformed.replace(
'${{ASSIGNEES}}',
pr.assignees?.join(', ') ?? ''
)
transformed = transformed.replace(
'${{REVIEWERS}}',
pr.requestedReviewers?.join(', ') ?? ''
)
return transformed
}