- move around some parts of the code

This commit is contained in:
Mike Penz
2023-06-04 09:59:53 +00:00
committed by GitHub
parent 9785335233
commit 91da901770
12 changed files with 24188 additions and 8879 deletions
+151 -195
View File
@@ -13,52 +13,43 @@ const octokit = new Octokit({
it('Should have empty changelog (tags)', async () => { it('Should have empty changelog (tags)', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs/configuration.json')) const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs/configuration.json'))
const data = await pullData( const options = {
octokit, owner: 'mikepenz',
{ repo: 'release-changelog-builder-action',
owner: 'mikepenz', fromTag: {name: 'v0.0.1'},
repo: 'release-changelog-builder-action', toTag: {name: 'v0.0.2'},
fromTag: {name: 'v0.0.1'}, includeOpen: false,
toTag: {name: 'v0.0.2'}, failOnError: false,
includeOpen: false, fetchReviewers: false,
failOnError: false, fetchReleaseInformation: false,
fetchReviewers: false, fetchReviews: false,
fetchReleaseInformation: false, commitMode: false,
fetchReviews: false, configuration
commitMode: false, }
configuration const data = await pullData(octokit, options)
}, const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
false,
false
)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
console.log(changeLog) console.log(changeLog)
expect(changeLog).toStrictEqual('- no changes') expect(changeLog).toStrictEqual('- no changes')
}) })
it('Should match generated changelog (tags)', async () => { it('Should match generated changelog (tags)', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs/configuration.json')) const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs/configuration.json'))
const data = await pullData( const options = {
octokit, owner: 'mikepenz',
{ repo: 'release-changelog-builder-action',
owner: 'mikepenz', fromTag: {name: 'v0.0.1'},
repo: 'release-changelog-builder-action', toTag: {name: 'v0.0.3'},
fromTag: {name: 'v0.0.1'}, includeOpen: false,
toTag: {name: 'v0.0.3'}, failOnError: false,
includeOpen: false, fetchReviewers: false,
failOnError: false, fetchReleaseInformation: false,
fetchReviewers: false, fetchReviews: false,
fetchReleaseInformation: false, commitMode: false,
fetchReviews: false, configuration
commitMode: false, }
configuration const data = await pullData(octokit, options)
},
false,
false
)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options) const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
console.log(changeLog) console.log(changeLog)
expect(changeLog).toStrictEqual(`## 🧪 Tests expect(changeLog).toStrictEqual(`## 🧪 Tests
@@ -70,26 +61,23 @@ it('Should match generated changelog (tags)', async () => {
it('Should match generated changelog (refs)', async () => { it('Should match generated changelog (refs)', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_all_placeholders.json')) const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_all_placeholders.json'))
const data = await pullData(
octokit,
{
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: '5ec7a2d86fe9f43fdd38d5e254a1117c8a51b4c3'},
toTag: {name: 'fa3788c8c4b3373ef8424ce3eb008a5cd07cc5aa'},
includeOpen: false,
failOnError: false,
fetchReviewers: false,
fetchReleaseInformation: false,
fetchReviews: false,
commitMode: false,
configuration
},
false,
false
)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options) const options = {
owner: 'mikepenz',
repo: 'release-changelog-builder-action',
fromTag: {name: '5ec7a2d86fe9f43fdd38d5e254a1117c8a51b4c3'},
toTag: {name: 'fa3788c8c4b3373ef8424ce3eb008a5cd07cc5aa'},
includeOpen: false,
failOnError: false,
fetchReviewers: false,
fetchReleaseInformation: false,
fetchReviews: false,
commitMode: false,
configuration
}
const data = await pullData(octokit, options)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
console.log(changeLog) console.log(changeLog)
expect(changeLog).toStrictEqual(`## 🧪 Tests expect(changeLog).toStrictEqual(`## 🧪 Tests
@@ -109,26 +97,21 @@ nhoelzl
it('Should match generated changelog and replace all occurrences (refs)', async () => { it('Should match generated changelog and replace all occurrences (refs)', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_replace_all_placeholders.json')) const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_replace_all_placeholders.json'))
const data = await pullData( const options = {
octokit, owner: 'mikepenz',
{ repo: 'release-changelog-builder-action',
owner: 'mikepenz', fromTag: {name: '5ec7a2d86fe9f43fdd38d5e254a1117c8a51b4c3'},
repo: 'release-changelog-builder-action', toTag: {name: 'fa3788c8c4b3373ef8424ce3eb008a5cd07cc5aa'},
fromTag: {name: '5ec7a2d86fe9f43fdd38d5e254a1117c8a51b4c3'}, includeOpen: false,
toTag: {name: 'fa3788c8c4b3373ef8424ce3eb008a5cd07cc5aa'}, failOnError: false,
includeOpen: false, fetchReviewers: false,
failOnError: false, fetchReleaseInformation: false,
fetchReviewers: false, fetchReviews: false,
fetchReleaseInformation: false, commitMode: false,
fetchReviews: false, configuration
commitMode: false, }
configuration const data = await pullData(octokit, options)
}, const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
false,
false
)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
console.log(changeLog) console.log(changeLog)
expect(changeLog).toStrictEqual(`## 🧪 Tests expect(changeLog).toStrictEqual(`## 🧪 Tests
@@ -150,78 +133,65 @@ nhoelzl
it('Should match ordered ASC', async () => { it('Should match ordered ASC', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_asc.json')) const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_asc.json'))
const data = await pullData( const options = {
octokit, owner: 'mikepenz',
{ repo: 'release-changelog-builder-action',
owner: 'mikepenz', fromTag: {name: 'v0.3.0'},
repo: 'release-changelog-builder-action', toTag: {name: 'v0.5.0'},
fromTag: {name: 'v0.3.0'}, includeOpen: false,
toTag: {name: 'v0.5.0'}, failOnError: false,
includeOpen: false, fetchReviewers: false,
failOnError: false, fetchReleaseInformation: false,
fetchReviewers: false, fetchReviews: false,
fetchReleaseInformation: false, commitMode: false,
fetchReviews: false, configuration
commitMode: false, }
configuration const data = await pullData(octokit, options)
},
false,
false
)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options) const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
console.log(changeLog) console.log(changeLog)
expect(changeLog).toStrictEqual(`## 🚀 Features\n\n22\n24\n25\n26\n28\n\n## 🐛 Fixes\n\n23\n\n`) expect(changeLog).toStrictEqual(`## 🚀 Features\n\n22\n24\n25\n26\n28\n\n## 🐛 Fixes\n\n23\n\n`)
}) })
it('Should match ordered DESC', async () => { it('Should match ordered DESC', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_desc.json')) const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_desc.json'))
const data = await pullData( const options = {
octokit, owner: 'mikepenz',
{ repo: 'release-changelog-builder-action',
owner: 'mikepenz', fromTag: {name: 'v0.3.0'},
repo: 'release-changelog-builder-action', toTag: {name: 'v0.5.0'},
fromTag: {name: 'v0.3.0'}, includeOpen: false,
toTag: {name: 'v0.5.0'}, failOnError: false,
includeOpen: false, fetchReviewers: false,
failOnError: false, fetchReleaseInformation: false,
fetchReviewers: false, fetchReviews: false,
fetchReleaseInformation: false, commitMode: false,
fetchReviews: false, configuration
commitMode: false, }
configuration const data = await pullData(octokit, options)
},
false,
false
)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options) const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
console.log(changeLog) console.log(changeLog)
expect(changeLog).toStrictEqual(`## 🚀 Features\n\n28\n26\n25\n24\n22\n\n## 🐛 Fixes\n\n23\n\n`) expect(changeLog).toStrictEqual(`## 🚀 Features\n\n28\n26\n25\n24\n22\n\n## 🐛 Fixes\n\n23\n\n`)
}) })
it('Should match ordered by title ASC', async () => { it('Should match ordered by title ASC', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_sort_title_asc.json')) const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_sort_title_asc.json'))
const data = await pullData( const options = {
octokit, owner: 'mikepenz',
{ repo: 'release-changelog-builder-action',
owner: 'mikepenz', fromTag: {name: 'v0.3.0'},
repo: 'release-changelog-builder-action', toTag: {name: 'v0.5.0'},
fromTag: {name: 'v0.3.0'}, includeOpen: false,
toTag: {name: 'v0.5.0'}, failOnError: false,
includeOpen: false, fetchReviewers: false,
failOnError: false, fetchReleaseInformation: false,
fetchReviewers: false, fetchReviews: false,
fetchReleaseInformation: false, commitMode: false,
fetchReviews: false, configuration
commitMode: false, }
configuration const data = await pullData(octokit, options)
}, const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
false,
false
)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
console.log(changeLog) console.log(changeLog)
expect(changeLog).toStrictEqual( expect(changeLog).toStrictEqual(
`## 🚀 Features\n\nEnhanced action logs\nImprove README\nImproved configuration failure handling\nImproved defaults if no configuration is provided\nIntroduce additional placeholders [milestone, labels, assignees, reviewers]\n\n## 🐛 Fixes\n\nImproved handling for non existing tags\n\n` `## 🚀 Features\n\nEnhanced action logs\nImprove README\nImproved configuration failure handling\nImproved defaults if no configuration is provided\nIntroduce additional placeholders [milestone, labels, assignees, reviewers]\n\n## 🐛 Fixes\n\nImproved handling for non existing tags\n\n`
@@ -230,26 +200,22 @@ it('Should match ordered by title ASC', async () => {
it('Should match ordered by title DESC', async () => { it('Should match ordered by title DESC', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_sort_title_desc.json')) const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_sort_title_desc.json'))
const data = await pullData( const options = {
octokit, owner: 'mikepenz',
{ repo: 'release-changelog-builder-action',
owner: 'mikepenz', fromTag: {name: 'v0.3.0'},
repo: 'release-changelog-builder-action', toTag: {name: 'v0.5.0'},
fromTag: {name: 'v0.3.0'}, includeOpen: false,
toTag: {name: 'v0.5.0'}, failOnError: false,
includeOpen: false, fetchReviewers: false,
failOnError: false, fetchReleaseInformation: false,
fetchReviewers: false, fetchReviews: false,
fetchReleaseInformation: false, commitMode: false,
fetchReviews: false, configuration
commitMode: false, }
configuration const data = await pullData(octokit, options)
},
false,
false
)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options) const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
console.log(changeLog) console.log(changeLog)
expect(changeLog).toStrictEqual( expect(changeLog).toStrictEqual(
`## 🚀 Features\n\nIntroduce additional placeholders [milestone, labels, assignees, reviewers]\nImproved defaults if no configuration is provided\nImproved configuration failure handling\nImprove README\nEnhanced action logs\n\n## 🐛 Fixes\n\nImproved handling for non existing tags\n\n` `## 🚀 Features\n\nIntroduce additional placeholders [milestone, labels, assignees, reviewers]\nImproved defaults if no configuration is provided\nImproved configuration failure handling\nImprove README\nEnhanced action logs\n\n## 🐛 Fixes\n\nImproved handling for non existing tags\n\n`
@@ -258,52 +224,42 @@ it('Should match ordered by title DESC', async () => {
it('Should ignore PRs not merged into develop branch', async () => { it('Should ignore PRs not merged into develop branch', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_base_branches_develop.json')) const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_base_branches_develop.json'))
const data = await pullData( const options = {
octokit, owner: 'mikepenz',
{ repo: 'release-changelog-builder-action',
owner: 'mikepenz', fromTag: {name: 'v1.3.1'},
repo: 'release-changelog-builder-action', toTag: {name: 'v1.4.0'},
fromTag: {name: 'v1.3.1'}, includeOpen: false,
toTag: {name: 'v1.4.0'}, failOnError: false,
includeOpen: false, fetchReviewers: false,
failOnError: false, fetchReleaseInformation: false,
fetchReviewers: false, fetchReviews: false,
fetchReleaseInformation: false, commitMode: false,
fetchReviews: false, configuration
commitMode: false, }
configuration const data = await pullData(octokit, options)
}, const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
false,
false
)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
console.log(changeLog) console.log(changeLog)
expect(changeLog).toStrictEqual(`150\n\n`) expect(changeLog).toStrictEqual(`150\n\n`)
}) })
it('Should ignore PRs not merged into main branch', async () => { it('Should ignore PRs not merged into main branch', async () => {
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_base_branches_main.json')) const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_base_branches_main.json'))
const data = await pullData( const options = {
octokit, owner: 'mikepenz',
{ repo: 'release-changelog-builder-action',
owner: 'mikepenz', fromTag: {name: 'v1.3.1'},
repo: 'release-changelog-builder-action', toTag: {name: 'v1.4.0'},
fromTag: {name: 'v1.3.1'}, includeOpen: false,
toTag: {name: 'v1.4.0'}, failOnError: false,
includeOpen: false, fetchReviewers: false,
failOnError: false, fetchReleaseInformation: false,
fetchReviewers: false, fetchReviews: false,
fetchReleaseInformation: false, commitMode: false,
fetchReviews: false, configuration
commitMode: false, }
configuration const data = await pullData(octokit, options)
}, const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
false,
false
)
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
console.log(changeLog) console.log(changeLog)
expect(changeLog).toStrictEqual(`153\n\n`) expect(changeLog).toStrictEqual(`153\n\n`)
}) })
Generated Vendored
+23966 -8619
View File
File diff suppressed because one or more lines are too long
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+9 -9
View File
@@ -1,5 +1,5 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import {Configuration} from './configuration' import {PullConfiguration} from './types'
import {Octokit} from '@octokit/rest' import {Octokit} from '@octokit/rest'
import {TagInfo, Tags} from './tags' import {TagInfo, Tags} from './tags'
import {failOrError} from './utils' import {failOrError} from './utils'
@@ -18,13 +18,14 @@ export interface Options {
fetchReleaseInformation: boolean // defines if the action should fetch the release information for the from and to tag - e.g. the creation date for the associated release fetchReleaseInformation: boolean // defines if the action should fetch the release information for the from and to tag - e.g. the creation date for the associated release
fetchReviews: boolean // defines if the action should fetch the reviews for the PR. fetchReviews: boolean // defines if the action should fetch the reviews for the PR.
commitMode: boolean // defines if we use the alternative commit based mode. note: this is only partially supported 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` configuration: PullConfiguration // the configuration as defined in `configuration.ts`
} }
export interface Data { export interface Data {
diffInfo: DiffInfo diffInfo: DiffInfo
mergedPullRequests: PullRequestInfo[] mergedPullRequests: PullRequestInfo[]
options: Options fromTag: TagInfo
toTag: TagInfo
} }
export class PullRequestCollector { export class PullRequestCollector {
@@ -43,7 +44,7 @@ export class PullRequestCollector {
private fetchReleaseInformation: boolean = false, private fetchReleaseInformation: boolean = false,
private fetchReviews: boolean = false, private fetchReviews: boolean = false,
private commitMode: boolean = false, private commitMode: boolean = false,
private configuration: Configuration private configuration: PullConfiguration
) {} ) {}
async build(): Promise<Data | null> { async build(): Promise<Data | null> {
@@ -113,7 +114,7 @@ export class PullRequestCollector {
core.endGroup() core.endGroup()
const options = { return await pullData(octokit, {
owner: this.owner, owner: this.owner,
repo: this.repo, repo: this.repo,
fromTag: previousTag, fromTag: previousTag,
@@ -125,9 +126,7 @@ export class PullRequestCollector {
fetchReviews: this.fetchReviews, fetchReviews: this.fetchReviews,
commitMode: this.commitMode, commitMode: this.commitMode,
configuration: this.configuration configuration: this.configuration
} })
return await pullData(octokit, options)
} }
} }
@@ -154,6 +153,7 @@ export async function pullData(octokit: Octokit, options: Options): Promise<Data
return { return {
diffInfo, diffInfo,
mergedPullRequests, mergedPullRequests,
options fromTag: options.fromTag,
toTag: options.toTag
} }
} }
+1 -1
View File
@@ -2,7 +2,7 @@ import * as core from '@actions/core'
import {Octokit, RestEndpointMethodTypes} from '@octokit/rest' import {Octokit, RestEndpointMethodTypes} from '@octokit/rest'
import {Unpacked} from './utils' import {Unpacked} from './utils'
import moment from 'moment' import moment from 'moment'
import {Property, Sort} from './configuration' import {Property, Sort} from './types'
import {Commits, DiffInfo, filterCommits} from './commits' import {Commits, DiffInfo, filterCommits} from './commits'
import {Options} from './prCollector' import {Options} from './prCollector'
+1 -46
View File
@@ -1,42 +1,5 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import {Extractor, Property, Regex, Rule, Transformer} from './configuration' import {Extractor, Property, Regex, RegexTransformer, Transformer} from './types'
import {PullRequestInfo, retrieveProperty} from './pullRequests'
/**
* Checks if any of the rules match the given PR
*/
export function matchesRules(rules: Rule[], pr: PullRequestInfo, exhaustive: Boolean): boolean {
const transformers: RegexTransformer[] = rules.map(rule => validateTransformer(rule)).filter(t => t !== null) as RegexTransformer[]
if (exhaustive) {
return transformers.every(transformer => {
return matches(pr, transformer, 'rule')
})
} else {
return transformers.some(transformer => {
return matches(pr, transformer, 'rule')
})
}
}
/**
* Checks if the configured property results in a positive `test` with the regex.
*/
function matches(pr: PullRequestInfo, extractor: RegexTransformer, extractor_usecase: string): boolean {
if (extractor.pattern == null) {
return false
}
if (extractor.onProperty !== undefined && extractor.onProperty.length === 1) {
const prop = extractor.onProperty[0]
const value = retrieveProperty(pr, prop, extractor_usecase)
const matched = extractor.pattern.test(value)
if (core.isDebug()) {
core.debug(` Pattern ${extractor.pattern} resulted in ${matched} for ${value} on PR ${pr.number} (usecase: ${extractor_usecase})`)
}
return matched
}
return false
}
export function validateTransformer(transformer?: Regex): RegexTransformer | null { export function validateTransformer(transformer?: Regex): RegexTransformer | null {
if (transformer === undefined) { if (transformer === undefined) {
@@ -95,11 +58,3 @@ export function buildRegex(
return null return null
} }
} }
export interface RegexTransformer {
pattern: RegExp | null
target: string
onProperty?: Property[]
method?: 'replace' | 'match'
onEmpty?: string
}
+2 -2
View File
@@ -3,10 +3,10 @@ import * as github from '@actions/github'
import * as semver from 'semver' import * as semver from 'semver'
import {Octokit, RestEndpointMethodTypes} from '@octokit/rest' import {Octokit, RestEndpointMethodTypes} from '@octokit/rest'
import {SemVer} from 'semver' import {SemVer} from 'semver'
import {TagResolver} from './configuration' import {RegexTransformer, TagResolver} from './types'
import {createCommandManager} from './gitHelper' import {createCommandManager} from './gitHelper'
import moment from 'moment' import moment from 'moment'
import {RegexTransformer, validateTransformer} from './regexUtils' import {validateTransformer} from './regexUtils'
export interface TagResult { export interface TagResult {
from: TagInfo | null from: TagInfo | null
@@ -1,4 +1,4 @@
export interface Configuration { export interface PullConfiguration {
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
@@ -53,3 +53,11 @@ export interface Extractor extends Transformer {
method?: 'replace' | 'match' | undefined // the method to use to extract the value, `match` will not use the `target` property method?: 'replace' | 'match' | undefined // the method to use to extract the value, `match` will not use the `target` property
on_empty?: string | undefined // in case the regex results in an empty string, this value is gonna be used instead (only for label_extractor currently) on_empty?: string | undefined // in case the regex results in an empty string, this value is gonna be used instead (only for label_extractor currently)
} }
export interface RegexTransformer {
pattern: RegExp | null
target: string
onProperty?: Property[]
method?: 'replace' | 'match'
onEmpty?: string
}
+2 -1
View File
@@ -1,6 +1,7 @@
import {Extractor, Regex, Rule, Sort, Transformer} from 'github-pr-collector/lib/configuration' import {Extractor, Regex, Rule, Sort, Transformer} from 'github-pr-collector/lib/configuration'
import {PullConfiguration} from 'github-pr-collector/lib/types'
export interface Configuration { export interface Configuration extends PullConfiguration {
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
+41
View File
@@ -0,0 +1,41 @@
import * as core from '@actions/core'
import {Rule} from 'github-pr-collector/lib/configuration'
import {PullRequestInfo, retrieveProperty} from 'github-pr-collector/lib/pullRequests'
import {validateTransformer} from 'github-pr-collector/lib/regexUtils'
import {RegexTransformer} from 'github-pr-collector/lib/types'
/**
* Checks if any of the rules match the given PR
*/
export function matchesRules(rules: Rule[], pr: PullRequestInfo, exhaustive: Boolean): boolean {
const transformers: RegexTransformer[] = rules.map(rule => validateTransformer(rule)).filter(t => t !== null) as RegexTransformer[]
if (exhaustive) {
return transformers.every(transformer => {
return matches(pr, transformer, 'rule')
})
} else {
return transformers.some(transformer => {
return matches(pr, transformer, 'rule')
})
}
}
/**
* Checks if the configured property results in a positive `test` with the regex.
*/
function matches(pr: PullRequestInfo, extractor: RegexTransformer, extractor_usecase: string): boolean {
if (extractor.pattern == null) {
return false
}
if (extractor.onProperty !== undefined && extractor.onProperty.length === 1) {
const prop = extractor.onProperty[0]
const value = retrieveProperty(pr, prop, extractor_usecase)
const matched = extractor.pattern.test(value)
if (core.isDebug()) {
core.debug(` Pattern ${extractor.pattern} resulted in ${matched} for ${value} on PR ${pr.number} (usecase: ${extractor_usecase})`)
}
return matched
}
return false
}
+2 -3
View File
@@ -90,12 +90,11 @@ export class ReleaseNotesBuilder {
return null return null
} }
const resolvedOptions = prData.options
const options: ReleaseNotesOptions = { const options: ReleaseNotesOptions = {
owner: this.owner, owner: this.owner,
repo: this.repo, repo: this.repo,
fromTag: resolvedOptions.fromTag, fromTag: prData.fromTag,
toTag: resolvedOptions.toTag, toTag: prData.toTag,
includeOpen: this.includeOpen, includeOpen: this.includeOpen,
failOnError: this.failOnError, failOnError: this.failOnError,
fetchReviewers: this.fetchReviewers, fetchReviewers: this.fetchReviewers,
+3 -1
View File
@@ -3,9 +3,11 @@ import {Category, Configuration, Placeholder, Property} from './configuration'
import {createOrSet, haveCommonElementsArr, haveEveryElementsArr} from './utils' import {createOrSet, haveCommonElementsArr, haveEveryElementsArr} from './utils'
import {CommentInfo, EMPTY_COMMENT_INFO, PullRequestInfo, retrieveProperty, sortPullRequests} from 'github-pr-collector/lib/pullRequests' import {CommentInfo, EMPTY_COMMENT_INFO, PullRequestInfo, retrieveProperty, sortPullRequests} from 'github-pr-collector/lib/pullRequests'
import {DiffInfo} from 'github-pr-collector/lib/commits' import {DiffInfo} from 'github-pr-collector/lib/commits'
import {RegexTransformer, matchesRules, validateTransformer} from 'github-pr-collector/lib/regexUtils' import {validateTransformer} from 'github-pr-collector/lib/regexUtils'
import {Transformer} from 'github-pr-collector/lib/configuration' import {Transformer} from 'github-pr-collector/lib/configuration'
import {ReleaseNotesOptions} from './releaseNotesBuilder' import {ReleaseNotesOptions} from './releaseNotesBuilder'
import {matchesRules} from './regexUtils'
import {RegexTransformer} from 'github-pr-collector/lib/types'
const EMPTY_MAP = new Map<string, string>() const EMPTY_MAP = new Map<string, string>()