- introduce new flag to include open PRs into the changelog

- only fetch open with this flag
- expand pull request spec with
  - status, created at timestamp
- expand definition for placeholder patterns in the changelog
This commit is contained in:
Mike Penz
2022-04-08 11:00:39 +02:00
parent 7a59e9f4b4
commit 85af6a8181
10 changed files with 333 additions and 58 deletions
+33 -9
View File
@@ -11,6 +11,7 @@ export interface ReleaseNotesOptions {
repo: string // the repository
fromTag: string // the tag/ref to start from
toTag: string // the tag/ref up to
includeOpen: boolean // defines if we should also fetch open pull requests
failOnError: boolean // defines if we should fail the action in case of an error
commitMode: boolean // defines if we use the alternative commit based mode. note: this is only partially supported
configuration: Configuration // the configuration as defined in `configuration.ts`
@@ -80,7 +81,7 @@ export class ReleaseNotes {
private async getMergedPullRequests(
octokit: Octokit
): Promise<PullRequestInfo[]> {
const {owner, repo, configuration} = this.options
const {owner, repo, includeOpen, configuration} = this.options
const commits = await this.getCommitHistory(octokit)
if (commits.length === 0) {
@@ -133,6 +134,29 @@ export class ReleaseNotes {
return commmit.sha
})
// filter out pull requests not associated with this release
const mergedPullRequests = pullRequests.filter(pr => {
return releaseCommitHashes.includes(pr.mergeCommitSha)
})
let allPullRequests = mergedPullRequests
if (includeOpen) {
// retrieve all open pull requests
const openPullRequests = await pullRequestsApi.getOpen(
owner,
repo,
configuration.max_pull_requests ||
DefaultConfiguration.max_pull_requests
)
core.info(
`️ Retrieved ${pullRequests.length} open PRs for ${owner}/${repo}`
)
// all pull requests
allPullRequests = allPullRequests.concat(openPullRequests)
}
// retrieve base branches we allow
const baseBranches =
configuration.base_branches || DefaultConfiguration.base_branches
@@ -140,16 +164,14 @@ export class ReleaseNotes {
return new RegExp(baseBranch.replace('\\\\', '\\'), 'gu')
})
// return only the pull requests associated with this release
// and if the baseBranch is matching the configuration
return pullRequests.filter(pr => {
let keep = releaseCommitHashes.includes(pr.mergeCommitSha)
if (keep && baseBranches.length !== 0) {
keep = baseBranchPatterns.some(pattern => {
// return only prs if the baseBranch is matching the configuration
return allPullRequests.filter(pr => {
if (baseBranches.length !== 0) {
return baseBranchPatterns.some(pattern => {
return pr.baseBranch.match(pattern) !== null
})
}
return keep
return true
})
}
@@ -177,6 +199,7 @@ export class ReleaseNotes {
title: commit.summary,
htmlURL: '',
baseBranch: '',
createdAt: commit.date,
mergedAt: commit.date,
mergeCommitSha: commit.sha,
author: commit.author || '',
@@ -185,7 +208,8 @@ export class ReleaseNotes {
milestone: '',
body: commit.message || '',
assignees: [],
requestedReviewers: []
requestedReviewers: [],
status: 'merged'
}
})
}