- add support to exclude merge commits in release notes generation

- move filterCommits into commits.ts
- recompile dist files with updated code
This commit is contained in:
Mike Penz
2021-02-26 10:47:08 +01:00
parent 3be50052a5
commit becbe17766
5 changed files with 73 additions and 59 deletions
+28
View File
@@ -93,3 +93,31 @@ export class Commits {
return commitsResult
}
}
/**
* Filters out all commits which match the exclude pattern
*/
export function filterCommits(
commits: CommitInfo[],
excludeMergeBranches: string[]
): CommitInfo[] {
const filteredCommits = []
for (const commit of commits) {
if (excludeMergeBranches) {
let matched = false
for (const excludeMergeBranch of excludeMergeBranches) {
if (commit.summary.includes(excludeMergeBranch)) {
matched = true
break
}
}
if (matched) {
continue
}
}
filteredCommits.push(commit)
}
return filteredCommits
}
-29
View File
@@ -1,7 +1,6 @@
import {Octokit, RestEndpointMethodTypes} from '@octokit/rest'
import moment from 'moment'
import {CommitInfo} from './commits'
import * as core from '@actions/core'
export interface PullRequestInfo {
@@ -129,34 +128,6 @@ export class PullRequests {
return sortPullRequests(mergedPRs, true)
}
/**
* Filters out all commits which match the exclude pattern
*/
filterCommits(
commits: CommitInfo[],
excludeMergeBranches: string[]
): CommitInfo[] {
const filteredCommits = []
for (const commit of commits) {
if (excludeMergeBranches) {
let matched = false
for (const excludeMergeBranch of excludeMergeBranches) {
if (commit.summary.includes(excludeMergeBranch)) {
matched = true
break
}
}
if (matched) {
continue
}
}
filteredCommits.push(commit)
}
return filteredCommits
}
}
export function sortPullRequests(
+12 -2
View File
@@ -1,5 +1,5 @@
import {Octokit} from '@octokit/rest'
import {Commits, CommitInfo} from './commits'
import {Commits, CommitInfo, filterCommits} from './commits'
import {PullRequestInfo, PullRequests} from './pullRequests'
import {buildChangelog} from './transform'
import * as core from '@actions/core'
@@ -113,7 +113,7 @@ export class ReleaseNotes {
`️ Retrieved ${pullRequests.length} merged PRs for ${owner}/${repo}`
)
const prCommits = pullRequestsApi.filterCommits(
const prCommits = filterCommits(
commits,
configuration.exclude_merge_branches ||
DefaultConfiguration.exclude_merge_branches
@@ -137,11 +137,21 @@ export class ReleaseNotes {
private async generateCommitPRs(
octokit: Octokit
): Promise<PullRequestInfo[]> {
const {owner, repo, configuration} = this.options
const commits = await this.getCommitHistory(octokit)
if (commits.length === 0) {
return []
}
const prCommits = filterCommits(
commits,
configuration.exclude_merge_branches ||
DefaultConfiguration.exclude_merge_branches
)
core.info(`️ Retrieved ${prCommits.length} commits for ${owner}/${repo}`)
return commits.map(function (commit) {
return {
number: 0,