- fix lint errors
This commit is contained in:
@@ -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`
|
||||
}
|
||||
|
||||
+14
-8
@@ -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<PullRequestInfo[]> {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
+29
-11
@@ -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`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -9,7 +9,11 @@ export interface TagInfo {
|
||||
export class Tags {
|
||||
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 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<TagInfo | null> {
|
||||
const tags = this.sortTags(await this.getTags(owner, repo, maxTagsToFetch))
|
||||
|
||||
Reference in New Issue
Block a user