From 31b028f1ccd466db358734f9373b8f78db88f7bf Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 15 Jun 2024 21:08:31 +0200 Subject: [PATCH 1/2] fix spellings --- __tests__/demo/demo.test.ts | 12 ++++++------ src/configuration.ts | 8 ++++---- src/main.ts | 4 ++-- src/pr-collector/pullRequests.ts | 2 +- src/pr-collector/regexUtils.ts | 2 +- src/repositories/GithubRepository.ts | 2 +- src/transform.ts | 4 ++-- src/utils.ts | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/__tests__/demo/demo.test.ts b/__tests__/demo/demo.test.ts index c7f17405..be4c1df7 100644 --- a/__tests__/demo/demo.test.ts +++ b/__tests__/demo/demo.test.ts @@ -10,7 +10,7 @@ const token = process.env.GITHUB_TOKEN || '' const githubRepository = new GithubRepository(token, undefined, '.') it('Test custom changelog builder', async () => { // define the configuration file to use. - // By default it retireves a configuration from a json file + // By default, it retrieves a configuration from a json file // You can also quickly modify in code. const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs/configuration.json')) @@ -24,17 +24,17 @@ it('Test custom changelog builder', async () => { 'mikepenz', // The owner of the repo to test 'release-changelog-builder-action-playground', // The repository name '1.5.0', // `fromTag` The from tag name or the SHA1 of the from commit - '2.0.0', // `toTag` The to tag name or the SHA1 of the to commit + '4.2.2', // `toTag` The to tag name or the SHA1 of the to commit false, // `includeOpen` Define if you want to include open PRs into the changelog false, // `failOnError` Define if the action should fail on errors - false, // `ignorePrePrelease` used if no `fromTag` is defined to resolve the prior tag + false, // `ignorePrePrerelease` used if no `fromTag` is defined to resolve the prior tag false, // `fetchViaCommits` enable to fetch via commits - false, // `fetchReviewers` Enables fetching of reviewers for building the changlog (does additional API requests) + false, // `fetchReviewers` Enables fetching of reviewers for building the changelog (does additional API requests) false, // `fetchReleaseInformation` Enable to fetch release information (does additional API requests) false, // `fetchReviews` Enable to fetch reviews of the PRs (does additional API requests) 'PR', // `mode` Set the mode to use [PR, COMMIT, HYBRID]. PR -> builds changelog using PRs, COMMIT -> using commits, HYBRID -> Uses both - false, // `exportCache` Exports the fethced information to the cahce. Not relevant for this test - false, // `exportOnly` Enables to only export the fetched information however not build a changleog + false, // `exportCache` Exports the fetched information to the cache. Not relevant for this test + false, // `exportOnly` Enables to only export the fetched information however not build a changelog null, // `cache` Path to the cache. Not relevant for this test. configuration // The configuration to use for building the changelog ) diff --git a/src/configuration.ts b/src/configuration.ts index b869ed27..ff2e1c62 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -32,7 +32,7 @@ export interface Category { empty_content?: string // if the category has no matching PRs, this content will be used. If not set, the category will be skipped in the changelog. categories?: Category[] // allows for nested categories, items matched for a child category won't show up in the parent consume?: boolean // defines if the matched PR will be consumed by this category. Consumed PRs won't show up in any category *after* - entries?: string[] // array of single changelog entries, used to construc the changelog. (this is filled during the build) + entries?: string[] // array of single changelog entries, used to construct the changelog. (this is filled during the build) } /** @@ -60,7 +60,7 @@ export interface TagResolver { 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: Regex // the transformer to use to transform the original placeholder into the custom placheolder + transformer: Regex // the transformer to use to transform the original placeholder into the custom placeheolder } export const DefaultConfiguration: Configuration = { @@ -94,13 +94,13 @@ export const DefaultConfiguration: Configuration = { labels: [] } ], // the categories to support for the ordering - ignore_labels: ['ignore'], // list of lables being ignored from the changelog + ignore_labels: ['ignore'], // list of labels being ignored from the changelog label_extractor: [], // extracts additional labels from the commit message given a regex duplicate_filter: undefined, // extract an identifier from a PR used to detect duplicates, will keep the last match (depends on `sort`) transformers: [], // transformers to apply on the PR description according to the `pr_template` tag_resolver: { // defines the logic on how to resolve the previous tag, only relevant if `fromTag` is not specified - method: 'semver', // defines which method to use, by default it will use `semver` (dropping all non matching tags). Alternative `sort` is also available. + method: 'semver', // defines which method to use, by default it will use `semver` (dropping all non-matching tags). Alternative `sort` is also available. filter: undefined, // filter out all tags not matching the regex transformer: undefined // transforms the tag name using the regex, run after the filter }, diff --git a/src/main.ts b/src/main.ts index 38a81e2f..59d37a27 100644 --- a/src/main.ts +++ b/src/main.ts @@ -37,14 +37,14 @@ async function run(): Promise { if (configurationJson) { configJson = parseConfiguration(configurationJson) if (configJson) { - core.info(`ℹ️ Retreived configuration via 'configurationJson'.`) + core.info(`ℹ️ Retrieved configuration via 'configurationJson'.`) } } // read in the configuration from the file if possible const configurationFile: string = core.getInput('configuration') const configFile = resolveConfiguration(repositoryPath, configurationFile) if (configFile) { - core.info(`ℹ️ Retreived configuration via 'configuration' (via file).`) + core.info(`ℹ️ Retrieved configuration via 'configuration' (via file).`) } if (!configJson && !configFile) { diff --git a/src/pr-collector/pullRequests.ts b/src/pr-collector/pullRequests.ts index 2bb42103..5a177550 100644 --- a/src/pr-collector/pullRequests.ts +++ b/src/pr-collector/pullRequests.ts @@ -205,7 +205,7 @@ export class PullRequests { if (reviews && (reviews?.length || 0) > 0) { core.info(`ℹ️ Retrieved ${reviews.length || 0} review(s) for PR ${owner}/${repo}/#${pr.number}`) - // backwards compatiblity + // backwards compatibility pr.approvedReviewers = reviews.filter(r => r.state === 'APPROVED').map(r => r.author) } else { core.debug(`No reviewer(s) for PR ${owner}/${repo}/#${pr.number}`) diff --git a/src/pr-collector/regexUtils.ts b/src/pr-collector/regexUtils.ts index f7609c53..030cdc38 100644 --- a/src/pr-collector/regexUtils.ts +++ b/src/pr-collector/regexUtils.ts @@ -98,7 +98,7 @@ export function transformStringToValue(value: string, extractor: RegexTransforme function transformRegexr(regex: RegExp, source: string, target: string): Set | null { /** - * Util funtion extracted from regexr and is licensed under: + * Util function extracted from regexr and is licensed under: * * RegExr: Learn, Build, & Test RegEx * Copyright (C) 2017 gskinner.com, inc. diff --git a/src/repositories/GithubRepository.ts b/src/repositories/GithubRepository.ts index 506d18a2..654ca9a6 100644 --- a/src/repositories/GithubRepository.ts +++ b/src/repositories/GithubRepository.ts @@ -273,7 +273,7 @@ export class GithubRepository extends BaseRepository { labels: this.attachSpecialLabels(status, pr.labels?.map(lbl => lbl.name?.toLocaleLowerCase('en') || '') || []), milestone: pr.milestone?.title || '', body: pr.body || '', - assignees: pr.assignees?.map(asignee => asignee?.login || '') || [], + assignees: pr.assignees?.map(assignee => assignee?.login || '') || [], requestedReviewers: pr.requested_reviewers?.map(reviewer => reviewer?.login || '') || [], approvedReviewers: [], reviews: undefined, diff --git a/src/transform.ts b/src/transform.ts index a61aca3b..a1f8b0c7 100644 --- a/src/transform.ts +++ b/src/transform.ts @@ -89,7 +89,7 @@ export function buildChangelog(diffInfo: DiffInfo, origPrs: PullRequestInfo[], o const deduplicatedMap = new Map() const unmatched: PullRequestInfo[] = [] for (const pr of prs) { - const extracted = extractValues(pr, extractor, 'dupliate_filter') + const extracted = extractValues(pr, extractor, 'duplicate_filter') if (extracted !== null && extracted.length > 0) { deduplicatedMap.set(extracted[0], pr) } else { @@ -513,7 +513,7 @@ function handlePlaceholder( if (transformer?.pattern) { const extractedValue = transformStringToOptionalValue(value, transformer) // note: `.replace` will return the full string again if there was no match - // note: This is mostly backwards compatiblity + // note: This is mostly backwards compatibility if (extractedValue && ((transformer.method && transformer.method !== 'replace') || extractedValue !== value)) { if (placeholderPrMap) { createOrSet(placeholderPrMap, placeholder.name, extractedValue) diff --git a/src/utils.ts b/src/utils.ts index 043be09c..56b8de38 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -179,7 +179,7 @@ function readConfiguration(filename: string): Configuration | undefined { */ export function parseConfiguration(config: string): Configuration | undefined { try { - // for compatiblity with the `yml` file we require to use `#{{}}` instead of `${{}}` - replace it here. + // for compatibility with the `yml` file we require to use `#{{}}` instead of `${{}}` - replace it here. const configurationJSON: Configuration = JSON.parse(config.replace(/\${{/g, '#{{')) return configurationJSON } catch (error) { From 7f3d41d711f08d736ce9f5af43b36afa6845b2e0 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 15 Jun 2024 22:29:13 +0200 Subject: [PATCH 2/2] add contributors idea --- __tests__/transform.test.ts | 36 ++++++++++++++++++---------- __tests__/utils.ts | 3 ++- src/pr-collector/commits.ts | 3 ++- src/pr-collector/pullRequests.ts | 28 +++++++++++++++++++++- src/repositories/GithubRepository.ts | 3 ++- src/transform.ts | 10 ++++++++ 6 files changed, 67 insertions(+), 16 deletions(-) diff --git a/__tests__/transform.test.ts b/__tests__/transform.test.ts index e86d6b50..b69c5241 100644 --- a/__tests__/transform.test.ts +++ b/__tests__/transform.test.ts @@ -49,7 +49,8 @@ mergedPullRequests.push( assignees: [], requestedReviewers: [], approvedReviewers: [], - status: 'merged' + status: 'merged', + committers: [] }, { number: 2, @@ -67,7 +68,8 @@ mergedPullRequests.push( assignees: [], requestedReviewers: [], approvedReviewers: [], - status: 'merged' + status: 'merged', + committers: [] }, { number: 3, @@ -85,7 +87,8 @@ mergedPullRequests.push( assignees: [], requestedReviewers: [], approvedReviewers: [], - status: 'merged' + status: 'merged', + committers: [] }, { number: 4, @@ -103,7 +106,8 @@ mergedPullRequests.push( assignees: [], requestedReviewers: [], approvedReviewers: [], - status: 'merged' + status: 'merged', + committers: [] } ) @@ -123,7 +127,8 @@ const pullRequestWithLabelInBody: PullRequestInfo = { assignees: [], requestedReviewers: [], approvedReviewers: [], - status: 'merged' + status: 'merged', + committers: [] } const openPullRequest: PullRequestInfo = { @@ -142,7 +147,8 @@ const openPullRequest: PullRequestInfo = { assignees: [], requestedReviewers: [], approvedReviewers: [], - status: 'open' + status: 'open', + committers: [] } it('Extract label from title, combined regex', async () => { @@ -256,7 +262,8 @@ pullRequestsWithLabels.push( assignees: [], requestedReviewers: [], approvedReviewers: [], - status: 'merged' + status: 'merged', + committers: [] }, { number: 2, @@ -274,7 +281,8 @@ pullRequestsWithLabels.push( assignees: [], requestedReviewers: [], approvedReviewers: [], - status: 'merged' + status: 'merged', + committers: [] }, { number: 3, @@ -292,7 +300,8 @@ pullRequestsWithLabels.push( assignees: [], requestedReviewers: [], approvedReviewers: [], - status: 'merged' + status: 'merged', + committers: [] }, { number: 4, @@ -310,7 +319,8 @@ pullRequestsWithLabels.push( assignees: [], requestedReviewers: [], approvedReviewers: [], - status: 'merged' + status: 'merged', + committers: [] } ) @@ -332,7 +342,8 @@ openPullRequestsWithLabels.push( assignees: [], requestedReviewers: [], approvedReviewers: [], - status: 'open' + status: 'open', + committers: [] }, { number: 7, @@ -350,7 +361,8 @@ openPullRequestsWithLabels.push( assignees: [], requestedReviewers: [], approvedReviewers: [], - status: 'open' + status: 'open', + committers: [] } ) diff --git a/__tests__/utils.ts b/__tests__/utils.ts index 18a314d8..db07804e 100644 --- a/__tests__/utils.ts +++ b/__tests__/utils.ts @@ -39,6 +39,7 @@ export const buildPullRequeset = (number: number, title: string, labels: string[ assignees: [], requestedReviewers: [], approvedReviewers: [], - status: 'merged' + status: 'merged', + committers: [] } } diff --git a/src/pr-collector/commits.ts b/src/pr-collector/commits.ts index 143a3420..6491aab8 100644 --- a/src/pr-collector/commits.ts +++ b/src/pr-collector/commits.ts @@ -124,7 +124,8 @@ export function convertCommitsToPrs(options: Options, diffInfo: DiffInfo): [Diff assignees: [], requestedReviewers: [], approvedReviewers: [], - status: 'merged' + status: 'merged', + committers: [] } }) return [diffInfo, prs] diff --git a/src/pr-collector/pullRequests.ts b/src/pr-collector/pullRequests.ts index 5a177550..c9c741c9 100644 --- a/src/pr-collector/pullRequests.ts +++ b/src/pr-collector/pullRequests.ts @@ -25,6 +25,7 @@ export interface PullRequestInfo { approvedReviewers: string[] reviews?: CommentInfo[] status: 'open' | 'merged' + committers: string[] } export interface CommentInfo { @@ -52,7 +53,8 @@ export const EMPTY_PULL_REQUEST_INFO: PullRequestInfo = { assignees: [], requestedReviewers: [], approvedReviewers: [], - status: 'open' + status: 'open', + committers: [] } export const EMPTY_COMMENT_INFO: CommentInfo = { @@ -123,7 +125,22 @@ export class PullRequests { const prCommits = filterCommits(commits, configuration.exclude_merge_branches) core.info(`ℹ️ Retrieved ${prCommits.length} release commits for ${owner}/${repo}`) + + + const prCommittersMap = new Map(); + const uniqueAuthors = new Set(); + + // Iterate over each entry in prCommittersMap + for (const [commitSha, authors] of prCommittersMap.entries()) { + // Iterate over each author in the array and add to the set + authors.forEach(author => { + uniqueAuthors.add(author); + }); + } + // Convert Set to array (if needed) + const uniqueAuthorsList = Array.from(uniqueAuthors); + // create array of commits for this release const releaseCommitHashes = prCommits.map(commit => { return commit.sha @@ -174,6 +191,15 @@ export class PullRequests { pullRequests = allPullRequests } + // Update each pull request with its committers + pullRequests.forEach(pr => { + if (prCommittersMap.has(pr.number)) { + pr.committers = prCommittersMap.get(pr.number); + } else { + pr.committers = []; + } + }); + // retrieve base branches we allow const baseBranches = configuration.base_branches const baseBranchPatterns = baseBranches.map(baseBranch => { diff --git a/src/repositories/GithubRepository.ts b/src/repositories/GithubRepository.ts index 654ca9a6..19b678f5 100644 --- a/src/repositories/GithubRepository.ts +++ b/src/repositories/GithubRepository.ts @@ -277,7 +277,8 @@ export class GithubRepository extends BaseRepository { requestedReviewers: pr.requested_reviewers?.map(reviewer => reviewer?.login || '') || [], approvedReviewers: [], reviews: undefined, - status + status, + committers: [] }) private mapComment = (comment: Unpacked): CommentInfo => ({ diff --git a/src/transform.ts b/src/transform.ts index a1f8b0c7..c770dcab 100644 --- a/src/transform.ts +++ b/src/transform.ts @@ -275,6 +275,15 @@ export function buildChangelog(diffInfo: DiffInfo, origPrs: PullRequestInfo[], o } core.info(`✒️ Wrote ${ignoredPrs.length} ignored pull requests down`) + // create contributors list + let contributors: string[] = [] + for (const pr of prs) { + contributors = contributors.concat(pr.committers) + } + const contributorsString = contributors.join(', ') + + core.setOutput('contributors', contributorsString) + // fill template const placeholderMap = new Map() placeholderMap.set('CHANGELOG', changelog) @@ -286,6 +295,7 @@ export function buildChangelog(diffInfo: DiffInfo, origPrs: PullRequestInfo[], o placeholderMap.set('UNCATEGORIZED_COUNT', uncategorizedPrs.length.toString()) placeholderMap.set('OPEN_COUNT', openPrs.length.toString()) placeholderMap.set('IGNORED_COUNT', ignoredPrs.length.toString()) + placeholderMap.set('CONTRIBUTORS', contributors) // code change placeholders placeholderMap.set('CHANGED_FILES', diffInfo.changedFiles.toString()) placeholderMap.set('ADDITIONS', diffInfo.additions.toString())