diff --git a/src/configuration.ts b/src/configuration.ts index 63db05f..4411a4c 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -1,8 +1,8 @@ export interface Configuration { - max_tags_to_fetch: number, - max_pull_requests: number, - max_back_track_time_days: number, - exclude_merge_branches: string[], + max_tags_to_fetch: number + max_pull_requests: number + max_back_track_time_days: number + exclude_merge_branches: string[] sort: string template: string pr_template: string @@ -31,5 +31,5 @@ export const DefaultConfiguration: Configuration = { pr_template: '- ${{TITLE}}\n - PR: #${{NUMBER}}', // the per PR template to pick empty_template: '- no changes', // the template to use if no pull requests are found categories: [], // the categories to support for the ordering - transformers: [] // transformers to apply on the PR description according to the `pr_template` + transformers: [] // transformers to apply on the PR description according to the `pr_template` } diff --git a/src/pullRequests.ts b/src/pullRequests.ts index fadb0f0..51f34f6 100755 --- a/src/pullRequests.ts +++ b/src/pullRequests.ts @@ -52,7 +52,7 @@ export class PullRequests { owner: string, repo: string, fromDate: moment.Moment, - toDate: moment.Moment, // eslint-disable-line @typescript-eslint/no-unused-vars + toDate: moment.Moment, maxPullRequests: number ): Promise { const mergedPRs: PullRequestInfo[] = [] @@ -84,11 +84,14 @@ export class PullRequests { } const firstPR = prs[0] - if (firstPR.merged_at && fromDate.isAfter(moment(firstPR.merged_at)) || mergedPRs.length >= maxPullRequests) { - if( mergedPRs.length >= maxPullRequests ) { + if ( + (firstPR.merged_at && fromDate.isAfter(moment(firstPR.merged_at))) || + mergedPRs.length >= maxPullRequests + ) { + if (mergedPRs.length >= maxPullRequests) { core.info(`Reached 'maxPullRequests' count ${maxPullRequests}`) } - + // bail out early to not keep iterating on PRs super old return sortPullRequests(mergedPRs, true) } @@ -97,20 +100,23 @@ export class PullRequests { return sortPullRequests(mergedPRs, true) } - filterCommits(commits: CommitInfo[], excludeMergeBranches: string[]): CommitInfo[] { + filterCommits( + commits: CommitInfo[], + excludeMergeBranches: string[] + ): CommitInfo[] { const prRegex = /Merge pull request #(\d+)/ const filteredCommits = [] for (const commit of commits) { - if(excludeMergeBranches) { + if (excludeMergeBranches) { let matched = false for (const excludeMergeBranch of excludeMergeBranches) { - if(commit.summary.includes(excludeMergeBranch)) { + if (commit.summary.includes(excludeMergeBranch)) { matched = true break } } - if(matched) { + if (matched) { continue } } diff --git a/src/releaseNotes.ts b/src/releaseNotes.ts index 9dc29e3..3e376ce 100755 --- a/src/releaseNotes.ts +++ b/src/releaseNotes.ts @@ -28,7 +28,14 @@ export class ReleaseNotes { core.debug(`fromTag undefined, trying to resolve via API`) const tagsApi = new Tags(octokit) - const previousTag = await tagsApi.findPredecessorTag(owner, repo, toTag, configuration.max_tags_to_fetch ? configuration.max_tags_to_fetch : DefaultConfiguration.max_tags_to_fetch) + const previousTag = await tagsApi.findPredecessorTag( + owner, + repo, + toTag, + configuration.max_tags_to_fetch + ? configuration.max_tags_to_fetch + : DefaultConfiguration.max_tags_to_fetch + ) if (previousTag == null) { core.error(`Unable to retrieve previous tag given ${toTag}`) return configuration.empty_template @@ -72,9 +79,11 @@ export class ReleaseNotes { let fromDate = firstCommit.date const toDate = lastCommit.date - const maxDays = configuration.max_back_track_time_days ? configuration.max_back_track_time_days : DefaultConfiguration.max_back_track_time_days - const maxFromDate = toDate.clone().subtract(maxDays, "days") - if(maxFromDate.isAfter(fromDate)) { + const maxDays = configuration.max_back_track_time_days + ? configuration.max_back_track_time_days + : DefaultConfiguration.max_back_track_time_days + const maxFromDate = toDate.clone().subtract(maxDays, 'days') + if (maxFromDate.isAfter(fromDate)) { core.info(`Adjusted 'fromDate' to go max ${maxDays} back`) fromDate = maxFromDate } @@ -89,14 +98,25 @@ export class ReleaseNotes { repo, fromDate, toDate, - configuration.max_pull_requests ? configuration.max_pull_requests : DefaultConfiguration.max_pull_requests + configuration.max_pull_requests + ? configuration.max_pull_requests + : DefaultConfiguration.max_pull_requests ) - core.info(`Retrieved ${pullRequests.length} merged PRs for ${owner}/${repo}`) + core.info( + `Retrieved ${pullRequests.length} merged PRs for ${owner}/${repo}` + ) - const prCommits = pullRequestsApi.filterCommits(commits, configuration.exclude_merge_branches ? configuration.exclude_merge_branches : DefaultConfiguration.exclude_merge_branches) + const prCommits = pullRequestsApi.filterCommits( + commits, + configuration.exclude_merge_branches + ? configuration.exclude_merge_branches + : DefaultConfiguration.exclude_merge_branches + ) - core.info(`Retrieved ${prCommits.length} PR merge commits for ${owner}/${repo}`) + core.info( + `Retrieved ${prCommits.length} PR merge commits for ${owner}/${repo}` + ) const filteredPullRequests = [] const pullRequestsByNumber: {[key: number]: PullRequestInfo} = {} @@ -127,9 +147,7 @@ export class ReleaseNotes { core.warning(`${prRef} not found! Commit text: ${commit.summary}`) } } else { - core.info( - `${prRef} not in date range, excluding from changelog` - ) + core.info(`${prRef} not in date range, excluding from changelog`) } } diff --git a/src/tags.ts b/src/tags.ts index 6ea970c..8ea4573 100755 --- a/src/tags.ts +++ b/src/tags.ts @@ -9,7 +9,11 @@ export interface TagInfo { export class Tags { constructor(private octokit: Octokit) {} - async getTags(owner: string, repo: string, maxTagsToFetch: number): Promise { + async getTags( + owner: string, + repo: string, + maxTagsToFetch: number + ): Promise { const tagsInfo: TagInfo[] = [] const options = this.octokit.repos.listTags.endpoint.merge({ owner, @@ -44,7 +48,7 @@ export class Tags { async findPredecessorTag( owner: string, repo: string, - tag: string, + tag: string, maxTagsToFetch: number ): Promise { const tags = this.sortTags(await this.getTags(owner, repo, maxTagsToFetch))