- improve test case to depend on self
- fix various eslint error reports
This commit is contained in:
+6
-13
@@ -28,25 +28,18 @@ it('Should be true', async () => {
|
|||||||
const configuration = readConfiguration('configuration.json')
|
const configuration = readConfiguration('configuration.json')
|
||||||
const releaseNotes = new ReleaseNotes({
|
const releaseNotes = new ReleaseNotes({
|
||||||
owner: 'mikepenz',
|
owner: 'mikepenz',
|
||||||
repo: 'MaterialDrawer',
|
repo: 'release-changelog-builder-action',
|
||||||
fromTag: null,
|
fromTag: null,
|
||||||
toTag: 'v8.1.6',
|
toTag: '0.0.3',
|
||||||
configuration: configuration
|
configuration: configuration
|
||||||
})
|
})
|
||||||
|
|
||||||
const changeLog = await releaseNotes.pull()
|
const changeLog = await releaseNotes.pull()
|
||||||
console.log(changeLog)
|
console.log(changeLog)
|
||||||
expect(changeLog).toStrictEqual(`
|
expect(changeLog).toStrictEqual(`## 🧪 Tests
|
||||||
|
|
||||||
<details>
|
- [CI] Specify Test Case
|
||||||
<summary>Uncategorized</summary>
|
- PR: #10
|
||||||
|
|
||||||
- Improve GitHub Actions
|
`)
|
||||||
- PR: #2655
|
|
||||||
- Update dependencies
|
|
||||||
- PR: #2656
|
|
||||||
- [RELEASE] v8.1.6
|
|
||||||
- PR: #2657
|
|
||||||
|
|
||||||
</details>`)
|
|
||||||
})
|
})
|
||||||
|
|||||||
+44
-35
@@ -58,6 +58,7 @@ class Commits {
|
|||||||
// This is because the GitHub API limits the number of commits returned in a single response.
|
// This is because the GitHub API limits the number of commits returned in a single response.
|
||||||
let commits = [];
|
let commits = [];
|
||||||
let compareHead = head;
|
let compareHead = head;
|
||||||
|
// eslint-disable-next-line no-constant-condition
|
||||||
while (true) {
|
while (true) {
|
||||||
const compareResult = yield this.octokit.repos.compareCommits({
|
const compareResult = yield this.octokit.repos.compareCommits({
|
||||||
owner,
|
owner,
|
||||||
@@ -467,7 +468,8 @@ class PullRequests {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
getBetweenDates(owner, repo, fromDate, toDate) {
|
getBetweenDates(owner, repo, fromDate, toDate // eslint-disable-line @typescript-eslint/no-unused-vars
|
||||||
|
) {
|
||||||
var e_1, _a;
|
var e_1, _a;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const mergedPRs = [];
|
const mergedPRs = [];
|
||||||
@@ -482,16 +484,7 @@ class PullRequests {
|
|||||||
for (var _b = __asyncValues(this.octokit.paginate.iterator(options)), _c; _c = yield _b.next(), !_c.done;) {
|
for (var _b = __asyncValues(this.octokit.paginate.iterator(options)), _c; _c = yield _b.next(), !_c.done;) {
|
||||||
const response = _c.value;
|
const response = _c.value;
|
||||||
const prs = response.data;
|
const prs = response.data;
|
||||||
const firstPR = prs[0];
|
for (const pr of prs.filter(p => !!p.merged_at)) {
|
||||||
if (firstPR.merged_at && fromDate.isAfter(moment_1.default(firstPR.merged_at))) {
|
|
||||||
// bail out early to not keep iterating on PRs super old
|
|
||||||
return sortPullRequests(mergedPRs, true);
|
|
||||||
}
|
|
||||||
prs
|
|
||||||
.filter(pr => !!pr.merged_at &&
|
|
||||||
fromDate.isBefore(moment_1.default(pr.merged_at)) &&
|
|
||||||
toDate.isSameOrAfter(moment_1.default(pr.merged_at)))
|
|
||||||
.forEach(pr => {
|
|
||||||
mergedPRs.push({
|
mergedPRs.push({
|
||||||
number: pr.number,
|
number: pr.number,
|
||||||
title: pr.title,
|
title: pr.title,
|
||||||
@@ -504,7 +497,12 @@ class PullRequests {
|
|||||||
}),
|
}),
|
||||||
body: pr.body
|
body: pr.body
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
const firstPR = prs[0];
|
||||||
|
if (firstPR.merged_at && fromDate.isAfter(moment_1.default(firstPR.merged_at))) {
|
||||||
|
// bail out early to not keep iterating on PRs super old
|
||||||
|
return sortPullRequests(mergedPRs, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
||||||
@@ -753,12 +751,12 @@ class Tags {
|
|||||||
for (var _b = __asyncValues(this.octokit.paginate.iterator(options)), _c; _c = yield _b.next(), !_c.done;) {
|
for (var _b = __asyncValues(this.octokit.paginate.iterator(options)), _c; _c = yield _b.next(), !_c.done;) {
|
||||||
const response = _c.value;
|
const response = _c.value;
|
||||||
const tags = response.data;
|
const tags = response.data;
|
||||||
tags.forEach(tag => {
|
for (const tag of tags) {
|
||||||
tagsInfo.push({
|
tagsInfo.push({
|
||||||
name: tag.name,
|
name: tag.name,
|
||||||
commit: tag.commit.sha
|
commit: tag.commit.sha
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
// for performance only fetch newest 200 tags!!
|
// for performance only fetch newest 200 tags!!
|
||||||
if (tagsInfo.length >= max) {
|
if (tagsInfo.length >= max) {
|
||||||
break;
|
break;
|
||||||
@@ -861,52 +859,60 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|||||||
exports.buildChangelog = void 0;
|
exports.buildChangelog = void 0;
|
||||||
const pullRequests_1 = __webpack_require__(4217);
|
const pullRequests_1 = __webpack_require__(4217);
|
||||||
const core = __importStar(__webpack_require__(2186));
|
const core = __importStar(__webpack_require__(2186));
|
||||||
|
const configuration_1 = __webpack_require__(5527);
|
||||||
function buildChangelog(prs, config) {
|
function buildChangelog(prs, config) {
|
||||||
// sort to target order
|
// sort to target order
|
||||||
prs = pullRequests_1.sortPullRequests(prs, config.sort.toUpperCase() === 'ASC');
|
prs = pullRequests_1.sortPullRequests(prs, (config.sort ? config.sort : configuration_1.DefaultConfiguration.sort).toUpperCase() ===
|
||||||
|
'ASC');
|
||||||
const validatedTransformers = validateTransfomers(config.transformers);
|
const validatedTransformers = validateTransfomers(config.transformers);
|
||||||
const transformedMap = new Map();
|
const transformedMap = new Map();
|
||||||
// convert PRs to their text representation
|
// convert PRs to their text representation
|
||||||
prs.forEach(pr => {
|
for (const pr of prs) {
|
||||||
transformedMap.set(pr, transform(fillTemplate(pr, config.pr_template), validatedTransformers));
|
transformedMap.set(pr, transform(fillTemplate(pr, config.pr_template
|
||||||
});
|
? config.pr_template
|
||||||
|
: configuration_1.DefaultConfiguration.pr_template), validatedTransformers));
|
||||||
|
}
|
||||||
// bring PRs into the order of categories
|
// bring PRs into the order of categories
|
||||||
const categorized = new Map();
|
const categorized = new Map();
|
||||||
config.categories.forEach(category => {
|
if (config.categories) {
|
||||||
categorized.set(category, []);
|
for (const category of config.categories) {
|
||||||
});
|
categorized.set(category, []);
|
||||||
|
}
|
||||||
|
}
|
||||||
const uncategorized = [];
|
const uncategorized = [];
|
||||||
// bring elements in order
|
// bring elements in order
|
||||||
transformedMap.forEach((body, pr) => {
|
for (const [pr, body] of transformedMap) {
|
||||||
let matched = false;
|
let matched = false;
|
||||||
categorized.forEach((pullRequests, category) => {
|
for (const [category, pullRequests] of categorized) {
|
||||||
if (haveCommonElements(category.labels, pr.labels)) {
|
if (haveCommonElements(category.labels, pr.labels)) {
|
||||||
pullRequests.push(body);
|
pullRequests.push(body);
|
||||||
matched = true;
|
matched = true;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
if (!matched) {
|
if (!matched) {
|
||||||
uncategorized.push(body);
|
uncategorized.push(body);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
// construct final changelog
|
// construct final changelog
|
||||||
let changelog = '';
|
let changelog = '';
|
||||||
categorized.forEach((pullRequests, category) => {
|
for (const [category, pullRequests] of categorized) {
|
||||||
if (pullRequests.length > 0) {
|
if (pullRequests.length > 0) {
|
||||||
changelog = `${changelog + category.title}\n\n`;
|
changelog = `${changelog + category.title}\n\n`;
|
||||||
pullRequests.forEach(pr => {
|
for (const pr of pullRequests) {
|
||||||
changelog = `${changelog + pr}\n`;
|
changelog = `${changelog + pr}\n`;
|
||||||
});
|
}
|
||||||
// add space between
|
// add space between
|
||||||
changelog = `${changelog}\n`;
|
changelog = `${changelog}\n`;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
let changelogUncategorized = '';
|
let changelogUncategorized = '';
|
||||||
uncategorized.forEach(pr => {
|
for (const pr of uncategorized) {
|
||||||
changelogUncategorized = `${changelogUncategorized + pr}\n`;
|
changelogUncategorized = `${changelogUncategorized + pr}\n`;
|
||||||
});
|
}
|
||||||
// fill template
|
// fill template
|
||||||
let transformedChangelog = config.template;
|
let transformedChangelog = config.template
|
||||||
|
? config.template
|
||||||
|
: configuration_1.DefaultConfiguration.template;
|
||||||
transformedChangelog = transformedChangelog.replace('${{CHANGELOG}}', changelog);
|
transformedChangelog = transformedChangelog.replace('${{CHANGELOG}}', changelog);
|
||||||
transformedChangelog = transformedChangelog.replace('${{UNCATEGORIZED}}', changelogUncategorized);
|
transformedChangelog = transformedChangelog.replace('${{UNCATEGORIZED}}', changelogUncategorized);
|
||||||
return transformedChangelog;
|
return transformedChangelog;
|
||||||
@@ -930,12 +936,15 @@ function transform(filled, transformers) {
|
|||||||
return filled;
|
return filled;
|
||||||
}
|
}
|
||||||
let transformed = filled;
|
let transformed = filled;
|
||||||
transformers.forEach(({ pattern, target }) => {
|
for (const { target, pattern } of transformers) {
|
||||||
transformed = transformed.replace(pattern, target);
|
transformed = transformed.replace(pattern, target);
|
||||||
});
|
}
|
||||||
return transformed;
|
return transformed;
|
||||||
}
|
}
|
||||||
function validateTransfomers(transformers) {
|
function validateTransfomers(specifiedTransformers) {
|
||||||
|
const transformers = specifiedTransformers
|
||||||
|
? specifiedTransformers
|
||||||
|
: configuration_1.DefaultConfiguration.transformers;
|
||||||
return transformers
|
return transformers
|
||||||
.map(transformer => {
|
.map(transformer => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
@@ -39,6 +39,7 @@ export class Commits {
|
|||||||
// This is because the GitHub API limits the number of commits returned in a single response.
|
// This is because the GitHub API limits the number of commits returned in a single response.
|
||||||
let commits: RestEndpointMethodTypes['repos']['compareCommits']['response']['data']['commits'] = []
|
let commits: RestEndpointMethodTypes['repos']['compareCommits']['response']['data']['commits'] = []
|
||||||
let compareHead = head
|
let compareHead = head
|
||||||
|
// eslint-disable-next-line no-constant-condition
|
||||||
while (true) {
|
while (true) {
|
||||||
const compareResult = await this.octokit.repos.compareCommits({
|
const compareResult = await this.octokit.repos.compareCommits({
|
||||||
owner,
|
owner,
|
||||||
|
|||||||
+16
-23
@@ -52,7 +52,7 @@ export class PullRequests {
|
|||||||
owner: string,
|
owner: string,
|
||||||
repo: string,
|
repo: string,
|
||||||
fromDate: moment.Moment,
|
fromDate: moment.Moment,
|
||||||
toDate: moment.Moment
|
toDate: moment.Moment // eslint-disable-line @typescript-eslint/no-unused-vars
|
||||||
): Promise<PullRequestInfo[]> {
|
): Promise<PullRequestInfo[]> {
|
||||||
const mergedPRs: PullRequestInfo[] = []
|
const mergedPRs: PullRequestInfo[] = []
|
||||||
const options = this.octokit.pulls.list.endpoint.merge({
|
const options = this.octokit.pulls.list.endpoint.merge({
|
||||||
@@ -67,33 +67,26 @@ export class PullRequests {
|
|||||||
type PullsListData = RestEndpointMethodTypes['pulls']['list']['response']['data']
|
type PullsListData = RestEndpointMethodTypes['pulls']['list']['response']['data']
|
||||||
const prs: PullsListData = response.data as PullsListData
|
const prs: PullsListData = response.data as PullsListData
|
||||||
|
|
||||||
|
for (const pr of prs.filter(p => !!p.merged_at)) {
|
||||||
|
mergedPRs.push({
|
||||||
|
number: pr.number,
|
||||||
|
title: pr.title,
|
||||||
|
htmlURL: pr.html_url,
|
||||||
|
mergedAt: moment(pr.merged_at),
|
||||||
|
author: pr.user.login,
|
||||||
|
repoName: pr.base.repo.full_name,
|
||||||
|
labels: pr.labels.map(function (label) {
|
||||||
|
return label.name
|
||||||
|
}),
|
||||||
|
body: pr.body
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const firstPR = prs[0]
|
const firstPR = prs[0]
|
||||||
if (firstPR.merged_at && fromDate.isAfter(moment(firstPR.merged_at))) {
|
if (firstPR.merged_at && fromDate.isAfter(moment(firstPR.merged_at))) {
|
||||||
// bail out early to not keep iterating on PRs super old
|
// bail out early to not keep iterating on PRs super old
|
||||||
return sortPullRequests(mergedPRs, true)
|
return sortPullRequests(mergedPRs, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
prs
|
|
||||||
.filter(
|
|
||||||
pr =>
|
|
||||||
!!pr.merged_at &&
|
|
||||||
fromDate.isBefore(moment(pr.merged_at)) &&
|
|
||||||
toDate.isSameOrAfter(moment(pr.merged_at))
|
|
||||||
)
|
|
||||||
.forEach(pr => {
|
|
||||||
mergedPRs.push({
|
|
||||||
number: pr.number,
|
|
||||||
title: pr.title,
|
|
||||||
htmlURL: pr.html_url,
|
|
||||||
mergedAt: moment(pr.merged_at),
|
|
||||||
author: pr.user.login,
|
|
||||||
repoName: pr.base.repo.full_name,
|
|
||||||
labels: pr.labels.map(function (label) {
|
|
||||||
return label.name
|
|
||||||
}),
|
|
||||||
body: pr.body
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return sortPullRequests(mergedPRs, true)
|
return sortPullRequests(mergedPRs, true)
|
||||||
|
|||||||
+3
-1
@@ -43,7 +43,9 @@ export class ReleaseNotes {
|
|||||||
const mergedPullRequests = await this.getMergedPullRequests(octokit)
|
const mergedPullRequests = await this.getMergedPullRequests(octokit)
|
||||||
|
|
||||||
if (mergedPullRequests.length === 0) {
|
if (mergedPullRequests.length === 0) {
|
||||||
core.warning(`No pull requests found for between ${this.options.fromTag}...${toTag}`)
|
core.warning(
|
||||||
|
`No pull requests found for between ${this.options.fromTag}...${toTag}`
|
||||||
|
)
|
||||||
return configuration.empty_template
|
return configuration.empty_template
|
||||||
? configuration.empty_template
|
? configuration.empty_template
|
||||||
: DefaultConfiguration.empty_template
|
: DefaultConfiguration.empty_template
|
||||||
|
|||||||
+2
-2
@@ -23,12 +23,12 @@ export class Tags {
|
|||||||
type TagsListData = RestEndpointMethodTypes['repos']['listTags']['response']['data']
|
type TagsListData = RestEndpointMethodTypes['repos']['listTags']['response']['data']
|
||||||
const tags: TagsListData = response.data as TagsListData
|
const tags: TagsListData = response.data as TagsListData
|
||||||
|
|
||||||
tags.forEach(tag => {
|
for (const tag of tags) {
|
||||||
tagsInfo.push({
|
tagsInfo.push({
|
||||||
name: tag.name,
|
name: tag.name,
|
||||||
commit: tag.commit.sha
|
commit: tag.commit.sha
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
|
|
||||||
// for performance only fetch newest 200 tags!!
|
// for performance only fetch newest 200 tags!!
|
||||||
if (tagsInfo.length >= max) {
|
if (tagsInfo.length >= max) {
|
||||||
|
|||||||
+48
-21
@@ -1,69 +1,90 @@
|
|||||||
import {PullRequestInfo, sortPullRequests} from './pullRequests'
|
import {PullRequestInfo, sortPullRequests} from './pullRequests'
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import {Category, Configuration, Transformer} from './configuration'
|
import {
|
||||||
|
Category,
|
||||||
|
Configuration,
|
||||||
|
Transformer,
|
||||||
|
DefaultConfiguration
|
||||||
|
} from './configuration'
|
||||||
|
|
||||||
export function buildChangelog(
|
export function buildChangelog(
|
||||||
prs: PullRequestInfo[],
|
prs: PullRequestInfo[],
|
||||||
config: Configuration
|
config: Configuration
|
||||||
): string {
|
): string {
|
||||||
// sort to target order
|
// sort to target order
|
||||||
prs = sortPullRequests(prs, config.sort.toUpperCase() === 'ASC')
|
prs = sortPullRequests(
|
||||||
|
prs,
|
||||||
|
(config.sort ? config.sort : DefaultConfiguration.sort).toUpperCase() ===
|
||||||
|
'ASC'
|
||||||
|
)
|
||||||
|
|
||||||
const validatedTransformers = validateTransfomers(config.transformers)
|
const validatedTransformers = validateTransfomers(config.transformers)
|
||||||
const transformedMap = new Map<PullRequestInfo, string>()
|
const transformedMap = new Map<PullRequestInfo, string>()
|
||||||
// convert PRs to their text representation
|
// convert PRs to their text representation
|
||||||
prs.forEach(pr => {
|
for (const pr of prs) {
|
||||||
transformedMap.set(
|
transformedMap.set(
|
||||||
pr,
|
pr,
|
||||||
transform(fillTemplate(pr, config.pr_template), validatedTransformers)
|
transform(
|
||||||
|
fillTemplate(
|
||||||
|
pr,
|
||||||
|
config.pr_template
|
||||||
|
? config.pr_template
|
||||||
|
: DefaultConfiguration.pr_template
|
||||||
|
),
|
||||||
|
validatedTransformers
|
||||||
|
)
|
||||||
)
|
)
|
||||||
})
|
}
|
||||||
|
|
||||||
// bring PRs into the order of categories
|
// bring PRs into the order of categories
|
||||||
const categorized = new Map<Category, string[]>()
|
const categorized = new Map<Category, string[]>()
|
||||||
config.categories.forEach(category => {
|
if (config.categories) {
|
||||||
categorized.set(category, [])
|
for (const category of config.categories) {
|
||||||
})
|
categorized.set(category, [])
|
||||||
|
}
|
||||||
|
}
|
||||||
const uncategorized: string[] = []
|
const uncategorized: string[] = []
|
||||||
|
|
||||||
// bring elements in order
|
// bring elements in order
|
||||||
transformedMap.forEach((body, pr) => {
|
for (const [pr, body] of transformedMap) {
|
||||||
let matched = false
|
let matched = false
|
||||||
|
|
||||||
categorized.forEach((pullRequests, category) => {
|
for (const [category, pullRequests] of categorized) {
|
||||||
if (haveCommonElements(category.labels, pr.labels)) {
|
if (haveCommonElements(category.labels, pr.labels)) {
|
||||||
pullRequests.push(body)
|
pullRequests.push(body)
|
||||||
matched = true
|
matched = true
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
if (!matched) {
|
if (!matched) {
|
||||||
uncategorized.push(body)
|
uncategorized.push(body)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
// construct final changelog
|
// construct final changelog
|
||||||
let changelog = ''
|
let changelog = ''
|
||||||
categorized.forEach((pullRequests, category) => {
|
for (const [category, pullRequests] of categorized) {
|
||||||
if (pullRequests.length > 0) {
|
if (pullRequests.length > 0) {
|
||||||
changelog = `${changelog + category.title}\n\n`
|
changelog = `${changelog + category.title}\n\n`
|
||||||
|
|
||||||
pullRequests.forEach(pr => {
|
for (const pr of pullRequests) {
|
||||||
changelog = `${changelog + pr}\n`
|
changelog = `${changelog + pr}\n`
|
||||||
})
|
}
|
||||||
|
|
||||||
// add space between
|
// add space between
|
||||||
changelog = `${changelog}\n`
|
changelog = `${changelog}\n`
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
let changelogUncategorized = ''
|
let changelogUncategorized = ''
|
||||||
uncategorized.forEach(pr => {
|
for (const pr of uncategorized) {
|
||||||
changelogUncategorized = `${changelogUncategorized + pr}\n`
|
changelogUncategorized = `${changelogUncategorized + pr}\n`
|
||||||
})
|
}
|
||||||
|
|
||||||
// fill template
|
// fill template
|
||||||
let transformedChangelog = config.template
|
let transformedChangelog = config.template
|
||||||
|
? config.template
|
||||||
|
: DefaultConfiguration.template
|
||||||
transformedChangelog = transformedChangelog.replace(
|
transformedChangelog = transformedChangelog.replace(
|
||||||
'${{CHANGELOG}}',
|
'${{CHANGELOG}}',
|
||||||
changelog
|
changelog
|
||||||
@@ -95,13 +116,19 @@ function transform(filled: string, transformers: RegexTransformer[]): string {
|
|||||||
return filled
|
return filled
|
||||||
}
|
}
|
||||||
let transformed = filled
|
let transformed = filled
|
||||||
transformers.forEach(({pattern, target}) => {
|
for (const {target, pattern} of transformers) {
|
||||||
transformed = transformed.replace(pattern!!, target)
|
transformed = transformed.replace(pattern!!, target)
|
||||||
})
|
}
|
||||||
return transformed
|
return transformed
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateTransfomers(transformers: Transformer[]): RegexTransformer[] {
|
function validateTransfomers(
|
||||||
|
specifiedTransformers: Transformer[]
|
||||||
|
): RegexTransformer[] {
|
||||||
|
const transformers = specifiedTransformers
|
||||||
|
? specifiedTransformers
|
||||||
|
: DefaultConfiguration.transformers
|
||||||
|
|
||||||
return transformers
|
return transformers
|
||||||
.map(transformer => {
|
.map(transformer => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user