- fix lint errors

This commit is contained in:
Mike Penz
2020-10-16 19:37:04 +02:00
parent e5142357fc
commit 488b03cfa1
4 changed files with 54 additions and 26 deletions
+5 -5
View File
@@ -1,8 +1,8 @@
export interface Configuration { export interface Configuration {
max_tags_to_fetch: number, max_tags_to_fetch: number
max_pull_requests: number, max_pull_requests: number
max_back_track_time_days: number, max_back_track_time_days: number
exclude_merge_branches: string[], exclude_merge_branches: string[]
sort: string sort: string
template: string template: string
pr_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 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 empty_template: '- no changes', // the template to use if no pull requests are found
categories: [], // the categories to support for the ordering 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`
} }
+14 -8
View File
@@ -52,7 +52,7 @@ export class PullRequests {
owner: string, owner: string,
repo: string, repo: string,
fromDate: moment.Moment, fromDate: moment.Moment,
toDate: moment.Moment, // eslint-disable-line @typescript-eslint/no-unused-vars toDate: moment.Moment,
maxPullRequests: number maxPullRequests: number
): Promise<PullRequestInfo[]> { ): Promise<PullRequestInfo[]> {
const mergedPRs: PullRequestInfo[] = [] const mergedPRs: PullRequestInfo[] = []
@@ -84,11 +84,14 @@ export class PullRequests {
} }
const firstPR = prs[0] const firstPR = prs[0]
if (firstPR.merged_at && fromDate.isAfter(moment(firstPR.merged_at)) || mergedPRs.length >= maxPullRequests) { if (
if( mergedPRs.length >= maxPullRequests ) { (firstPR.merged_at && fromDate.isAfter(moment(firstPR.merged_at))) ||
mergedPRs.length >= maxPullRequests
) {
if (mergedPRs.length >= maxPullRequests) {
core.info(`Reached 'maxPullRequests' count ${maxPullRequests}`) core.info(`Reached 'maxPullRequests' count ${maxPullRequests}`)
} }
// 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)
} }
@@ -97,20 +100,23 @@ export class PullRequests {
return sortPullRequests(mergedPRs, true) return sortPullRequests(mergedPRs, true)
} }
filterCommits(commits: CommitInfo[], excludeMergeBranches: string[]): CommitInfo[] { filterCommits(
commits: CommitInfo[],
excludeMergeBranches: string[]
): CommitInfo[] {
const prRegex = /Merge pull request #(\d+)/ const prRegex = /Merge pull request #(\d+)/
const filteredCommits = [] const filteredCommits = []
for (const commit of commits) { for (const commit of commits) {
if(excludeMergeBranches) { if (excludeMergeBranches) {
let matched = false let matched = false
for (const excludeMergeBranch of excludeMergeBranches) { for (const excludeMergeBranch of excludeMergeBranches) {
if(commit.summary.includes(excludeMergeBranch)) { if (commit.summary.includes(excludeMergeBranch)) {
matched = true matched = true
break break
} }
} }
if(matched) { if (matched) {
continue continue
} }
} }
+29 -11
View File
@@ -28,7 +28,14 @@ export class ReleaseNotes {
core.debug(`fromTag undefined, trying to resolve via API`) core.debug(`fromTag undefined, trying to resolve via API`)
const tagsApi = new Tags(octokit) 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) { if (previousTag == null) {
core.error(`Unable to retrieve previous tag given ${toTag}`) core.error(`Unable to retrieve previous tag given ${toTag}`)
return configuration.empty_template return configuration.empty_template
@@ -72,9 +79,11 @@ export class ReleaseNotes {
let fromDate = firstCommit.date let fromDate = firstCommit.date
const toDate = lastCommit.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 maxDays = configuration.max_back_track_time_days
const maxFromDate = toDate.clone().subtract(maxDays, "days") ? configuration.max_back_track_time_days
if(maxFromDate.isAfter(fromDate)) { : 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`) core.info(`Adjusted 'fromDate' to go max ${maxDays} back`)
fromDate = maxFromDate fromDate = maxFromDate
} }
@@ -89,14 +98,25 @@ export class ReleaseNotes {
repo, repo,
fromDate, fromDate,
toDate, 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 filteredPullRequests = []
const pullRequestsByNumber: {[key: number]: PullRequestInfo} = {} const pullRequestsByNumber: {[key: number]: PullRequestInfo} = {}
@@ -127,9 +147,7 @@ export class ReleaseNotes {
core.warning(`${prRef} not found! Commit text: ${commit.summary}`) core.warning(`${prRef} not found! Commit text: ${commit.summary}`)
} }
} else { } else {
core.info( core.info(`${prRef} not in date range, excluding from changelog`)
`${prRef} not in date range, excluding from changelog`
)
} }
} }
+6 -2
View File
@@ -9,7 +9,11 @@ export interface TagInfo {
export class Tags { export class Tags {
constructor(private octokit: Octokit) {} constructor(private octokit: Octokit) {}
async getTags(owner: string, repo: string, maxTagsToFetch: number): Promise<TagInfo[]> { async getTags(
owner: string,
repo: string,
maxTagsToFetch: number
): Promise<TagInfo[]> {
const tagsInfo: TagInfo[] = [] const tagsInfo: TagInfo[] = []
const options = this.octokit.repos.listTags.endpoint.merge({ const options = this.octokit.repos.listTags.endpoint.merge({
owner, owner,
@@ -44,7 +48,7 @@ export class Tags {
async findPredecessorTag( async findPredecessorTag(
owner: string, owner: string,
repo: string, repo: string,
tag: string, tag: string,
maxTagsToFetch: number maxTagsToFetch: number
): Promise<TagInfo | null> { ): Promise<TagInfo | null> {
const tags = this.sortTags(await this.getTags(owner, repo, maxTagsToFetch)) const tags = this.sortTags(await this.getTags(owner, repo, maxTagsToFetch))