- move around some parts of the code
This commit is contained in:
@@ -13,9 +13,7 @@ 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',
|
owner: 'mikepenz',
|
||||||
repo: 'release-changelog-builder-action',
|
repo: 'release-changelog-builder-action',
|
||||||
fromTag: {name: 'v0.0.1'},
|
fromTag: {name: 'v0.0.1'},
|
||||||
@@ -27,21 +25,16 @@ it('Should have empty changelog (tags)', async () => {
|
|||||||
fetchReviews: false,
|
fetchReviews: false,
|
||||||
commitMode: false,
|
commitMode: false,
|
||||||
configuration
|
configuration
|
||||||
},
|
}
|
||||||
false,
|
const data = await pullData(octokit, options)
|
||||||
false
|
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
|
||||||
)
|
|
||||||
|
|
||||||
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',
|
owner: 'mikepenz',
|
||||||
repo: 'release-changelog-builder-action',
|
repo: 'release-changelog-builder-action',
|
||||||
fromTag: {name: 'v0.0.1'},
|
fromTag: {name: 'v0.0.1'},
|
||||||
@@ -53,12 +46,10 @@ it('Should match generated changelog (tags)', async () => {
|
|||||||
fetchReviews: false,
|
fetchReviews: false,
|
||||||
commitMode: false,
|
commitMode: false,
|
||||||
configuration
|
configuration
|
||||||
},
|
}
|
||||||
false,
|
const data = await pullData(octokit, options)
|
||||||
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,9 +61,8 @@ 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,
|
const options = {
|
||||||
{
|
|
||||||
owner: 'mikepenz',
|
owner: 'mikepenz',
|
||||||
repo: 'release-changelog-builder-action',
|
repo: 'release-changelog-builder-action',
|
||||||
fromTag: {name: '5ec7a2d86fe9f43fdd38d5e254a1117c8a51b4c3'},
|
fromTag: {name: '5ec7a2d86fe9f43fdd38d5e254a1117c8a51b4c3'},
|
||||||
@@ -84,12 +74,10 @@ it('Should match generated changelog (refs)', async () => {
|
|||||||
fetchReviews: false,
|
fetchReviews: false,
|
||||||
commitMode: false,
|
commitMode: false,
|
||||||
configuration
|
configuration
|
||||||
},
|
}
|
||||||
false,
|
const data = await pullData(octokit, options)
|
||||||
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
|
||||||
|
|
||||||
@@ -109,9 +97,7 @@ 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',
|
owner: 'mikepenz',
|
||||||
repo: 'release-changelog-builder-action',
|
repo: 'release-changelog-builder-action',
|
||||||
fromTag: {name: '5ec7a2d86fe9f43fdd38d5e254a1117c8a51b4c3'},
|
fromTag: {name: '5ec7a2d86fe9f43fdd38d5e254a1117c8a51b4c3'},
|
||||||
@@ -123,12 +109,9 @@ it('Should match generated changelog and replace all occurrences (refs)', async
|
|||||||
fetchReviews: false,
|
fetchReviews: false,
|
||||||
commitMode: false,
|
commitMode: false,
|
||||||
configuration
|
configuration
|
||||||
},
|
}
|
||||||
false,
|
const data = await pullData(octokit, options)
|
||||||
false
|
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
|
||||||
)
|
|
||||||
|
|
||||||
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, data!.options)
|
|
||||||
console.log(changeLog)
|
console.log(changeLog)
|
||||||
expect(changeLog).toStrictEqual(`## 🧪 Tests
|
expect(changeLog).toStrictEqual(`## 🧪 Tests
|
||||||
|
|
||||||
@@ -150,9 +133,7 @@ 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',
|
owner: 'mikepenz',
|
||||||
repo: 'release-changelog-builder-action',
|
repo: 'release-changelog-builder-action',
|
||||||
fromTag: {name: 'v0.3.0'},
|
fromTag: {name: 'v0.3.0'},
|
||||||
@@ -164,21 +145,17 @@ it('Should match ordered ASC', async () => {
|
|||||||
fetchReviews: false,
|
fetchReviews: false,
|
||||||
commitMode: false,
|
commitMode: false,
|
||||||
configuration
|
configuration
|
||||||
},
|
}
|
||||||
false,
|
const data = await pullData(octokit, options)
|
||||||
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',
|
owner: 'mikepenz',
|
||||||
repo: 'release-changelog-builder-action',
|
repo: 'release-changelog-builder-action',
|
||||||
fromTag: {name: 'v0.3.0'},
|
fromTag: {name: 'v0.3.0'},
|
||||||
@@ -190,21 +167,17 @@ it('Should match ordered DESC', async () => {
|
|||||||
fetchReviews: false,
|
fetchReviews: false,
|
||||||
commitMode: false,
|
commitMode: false,
|
||||||
configuration
|
configuration
|
||||||
},
|
}
|
||||||
false,
|
const data = await pullData(octokit, options)
|
||||||
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',
|
owner: 'mikepenz',
|
||||||
repo: 'release-changelog-builder-action',
|
repo: 'release-changelog-builder-action',
|
||||||
fromTag: {name: 'v0.3.0'},
|
fromTag: {name: 'v0.3.0'},
|
||||||
@@ -216,12 +189,9 @@ it('Should match ordered by title ASC', async () => {
|
|||||||
fetchReviews: false,
|
fetchReviews: false,
|
||||||
commitMode: false,
|
commitMode: false,
|
||||||
configuration
|
configuration
|
||||||
},
|
}
|
||||||
false,
|
const data = await pullData(octokit, options)
|
||||||
false
|
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
|
||||||
)
|
|
||||||
|
|
||||||
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,9 +200,7 @@ 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',
|
owner: 'mikepenz',
|
||||||
repo: 'release-changelog-builder-action',
|
repo: 'release-changelog-builder-action',
|
||||||
fromTag: {name: 'v0.3.0'},
|
fromTag: {name: 'v0.3.0'},
|
||||||
@@ -244,12 +212,10 @@ it('Should match ordered by title DESC', async () => {
|
|||||||
fetchReviews: false,
|
fetchReviews: false,
|
||||||
commitMode: false,
|
commitMode: false,
|
||||||
configuration
|
configuration
|
||||||
},
|
}
|
||||||
false,
|
const data = await pullData(octokit, options)
|
||||||
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,9 +224,7 @@ 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',
|
owner: 'mikepenz',
|
||||||
repo: 'release-changelog-builder-action',
|
repo: 'release-changelog-builder-action',
|
||||||
fromTag: {name: 'v1.3.1'},
|
fromTag: {name: 'v1.3.1'},
|
||||||
@@ -272,21 +236,16 @@ it('Should ignore PRs not merged into develop branch', async () => {
|
|||||||
fetchReviews: false,
|
fetchReviews: false,
|
||||||
commitMode: false,
|
commitMode: false,
|
||||||
configuration
|
configuration
|
||||||
},
|
}
|
||||||
false,
|
const data = await pullData(octokit, options)
|
||||||
false
|
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
|
||||||
)
|
|
||||||
|
|
||||||
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',
|
owner: 'mikepenz',
|
||||||
repo: 'release-changelog-builder-action',
|
repo: 'release-changelog-builder-action',
|
||||||
fromTag: {name: 'v1.3.1'},
|
fromTag: {name: 'v1.3.1'},
|
||||||
@@ -298,12 +257,9 @@ it('Should ignore PRs not merged into main branch', async () => {
|
|||||||
fetchReviews: false,
|
fetchReviews: false,
|
||||||
commitMode: false,
|
commitMode: false,
|
||||||
configuration
|
configuration
|
||||||
},
|
}
|
||||||
false,
|
const data = await pullData(octokit, options)
|
||||||
false
|
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
|
||||||
)
|
|
||||||
|
|
||||||
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`)
|
||||||
})
|
})
|
||||||
|
|||||||
+23966
-8619
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
@@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,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
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -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
@@ -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>()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user