- move around some parts of the code
This commit is contained in:
@@ -13,52 +13,43 @@ const octokit = new Octokit({
|
||||
it('Should have empty changelog (tags)', async () => {
|
||||
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs/configuration.json'))
|
||||
|
||||
const data = await pullData(
|
||||
octokit,
|
||||
{
|
||||
owner: 'mikepenz',
|
||||
repo: 'release-changelog-builder-action',
|
||||
fromTag: {name: 'v0.0.1'},
|
||||
toTag: {name: 'v0.0.2'},
|
||||
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: 'v0.0.1'},
|
||||
toTag: {name: 'v0.0.2'},
|
||||
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)
|
||||
expect(changeLog).toStrictEqual('- no changes')
|
||||
})
|
||||
|
||||
it('Should match generated changelog (tags)', async () => {
|
||||
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs/configuration.json'))
|
||||
const data = await pullData(
|
||||
octokit,
|
||||
{
|
||||
owner: 'mikepenz',
|
||||
repo: 'release-changelog-builder-action',
|
||||
fromTag: {name: 'v0.0.1'},
|
||||
toTag: {name: 'v0.0.3'},
|
||||
includeOpen: false,
|
||||
failOnError: false,
|
||||
fetchReviewers: false,
|
||||
fetchReleaseInformation: false,
|
||||
fetchReviews: false,
|
||||
commitMode: false,
|
||||
configuration
|
||||
},
|
||||
false,
|
||||
false
|
||||
)
|
||||
const options = {
|
||||
owner: 'mikepenz',
|
||||
repo: 'release-changelog-builder-action',
|
||||
fromTag: {name: 'v0.0.1'},
|
||||
toTag: {name: 'v0.0.3'},
|
||||
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, data!.options)
|
||||
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
|
||||
console.log(changeLog)
|
||||
expect(changeLog).toStrictEqual(`## 🧪 Tests
|
||||
|
||||
@@ -70,26 +61,23 @@ it('Should match generated changelog (tags)', async () => {
|
||||
|
||||
it('Should match generated changelog (refs)', async () => {
|
||||
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 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, data!.options)
|
||||
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
|
||||
console.log(changeLog)
|
||||
expect(changeLog).toStrictEqual(`## 🧪 Tests
|
||||
|
||||
@@ -109,26 +97,21 @@ nhoelzl
|
||||
|
||||
it('Should match generated changelog and replace all occurrences (refs)', async () => {
|
||||
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_replace_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)
|
||||
expect(changeLog).toStrictEqual(`## 🧪 Tests
|
||||
|
||||
@@ -150,78 +133,65 @@ nhoelzl
|
||||
|
||||
it('Should match ordered ASC', async () => {
|
||||
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_asc.json'))
|
||||
const data = await pullData(
|
||||
octokit,
|
||||
{
|
||||
owner: 'mikepenz',
|
||||
repo: 'release-changelog-builder-action',
|
||||
fromTag: {name: 'v0.3.0'},
|
||||
toTag: {name: 'v0.5.0'},
|
||||
includeOpen: false,
|
||||
failOnError: false,
|
||||
fetchReviewers: false,
|
||||
fetchReleaseInformation: false,
|
||||
fetchReviews: false,
|
||||
commitMode: false,
|
||||
configuration
|
||||
},
|
||||
false,
|
||||
false
|
||||
)
|
||||
const options = {
|
||||
owner: 'mikepenz',
|
||||
repo: 'release-changelog-builder-action',
|
||||
fromTag: {name: 'v0.3.0'},
|
||||
toTag: {name: 'v0.5.0'},
|
||||
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, data!.options)
|
||||
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
|
||||
console.log(changeLog)
|
||||
expect(changeLog).toStrictEqual(`## 🚀 Features\n\n22\n24\n25\n26\n28\n\n## 🐛 Fixes\n\n23\n\n`)
|
||||
})
|
||||
|
||||
it('Should match ordered DESC', async () => {
|
||||
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_desc.json'))
|
||||
const data = await pullData(
|
||||
octokit,
|
||||
{
|
||||
owner: 'mikepenz',
|
||||
repo: 'release-changelog-builder-action',
|
||||
fromTag: {name: 'v0.3.0'},
|
||||
toTag: {name: 'v0.5.0'},
|
||||
includeOpen: false,
|
||||
failOnError: false,
|
||||
fetchReviewers: false,
|
||||
fetchReleaseInformation: false,
|
||||
fetchReviews: false,
|
||||
commitMode: false,
|
||||
configuration
|
||||
},
|
||||
false,
|
||||
false
|
||||
)
|
||||
const options = {
|
||||
owner: 'mikepenz',
|
||||
repo: 'release-changelog-builder-action',
|
||||
fromTag: {name: 'v0.3.0'},
|
||||
toTag: {name: 'v0.5.0'},
|
||||
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, data!.options)
|
||||
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
|
||||
console.log(changeLog)
|
||||
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 () => {
|
||||
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_sort_title_asc.json'))
|
||||
const data = await pullData(
|
||||
octokit,
|
||||
{
|
||||
owner: 'mikepenz',
|
||||
repo: 'release-changelog-builder-action',
|
||||
fromTag: {name: 'v0.3.0'},
|
||||
toTag: {name: 'v0.5.0'},
|
||||
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: 'v0.3.0'},
|
||||
toTag: {name: 'v0.5.0'},
|
||||
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)
|
||||
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`
|
||||
@@ -230,26 +200,22 @@ it('Should match ordered by title ASC', async () => {
|
||||
|
||||
it('Should match ordered by title DESC', async () => {
|
||||
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_sort_title_desc.json'))
|
||||
const data = await pullData(
|
||||
octokit,
|
||||
{
|
||||
owner: 'mikepenz',
|
||||
repo: 'release-changelog-builder-action',
|
||||
fromTag: {name: 'v0.3.0'},
|
||||
toTag: {name: 'v0.5.0'},
|
||||
includeOpen: false,
|
||||
failOnError: false,
|
||||
fetchReviewers: false,
|
||||
fetchReleaseInformation: false,
|
||||
fetchReviews: false,
|
||||
commitMode: false,
|
||||
configuration
|
||||
},
|
||||
false,
|
||||
false
|
||||
)
|
||||
const options = {
|
||||
owner: 'mikepenz',
|
||||
repo: 'release-changelog-builder-action',
|
||||
fromTag: {name: 'v0.3.0'},
|
||||
toTag: {name: 'v0.5.0'},
|
||||
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, data!.options)
|
||||
const changeLog = buildChangelog(data!.diffInfo, data!.mergedPullRequests, options)
|
||||
console.log(changeLog)
|
||||
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`
|
||||
@@ -258,52 +224,42 @@ it('Should match ordered by title DESC', async () => {
|
||||
|
||||
it('Should ignore PRs not merged into develop branch', async () => {
|
||||
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_base_branches_develop.json'))
|
||||
const data = await pullData(
|
||||
octokit,
|
||||
{
|
||||
owner: 'mikepenz',
|
||||
repo: 'release-changelog-builder-action',
|
||||
fromTag: {name: 'v1.3.1'},
|
||||
toTag: {name: 'v1.4.0'},
|
||||
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: 'v1.3.1'},
|
||||
toTag: {name: 'v1.4.0'},
|
||||
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)
|
||||
expect(changeLog).toStrictEqual(`150\n\n`)
|
||||
})
|
||||
|
||||
it('Should ignore PRs not merged into main branch', async () => {
|
||||
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs_test/configuration_base_branches_main.json'))
|
||||
const data = await pullData(
|
||||
octokit,
|
||||
{
|
||||
owner: 'mikepenz',
|
||||
repo: 'release-changelog-builder-action',
|
||||
fromTag: {name: 'v1.3.1'},
|
||||
toTag: {name: 'v1.4.0'},
|
||||
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: 'v1.3.1'},
|
||||
toTag: {name: 'v1.4.0'},
|
||||
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)
|
||||
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 {Configuration} from './configuration'
|
||||
import {PullConfiguration} from './types'
|
||||
import {Octokit} from '@octokit/rest'
|
||||
import {TagInfo, Tags} from './tags'
|
||||
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
|
||||
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
|
||||
configuration: Configuration // the configuration as defined in `configuration.ts`
|
||||
configuration: PullConfiguration // the configuration as defined in `configuration.ts`
|
||||
}
|
||||
|
||||
export interface Data {
|
||||
diffInfo: DiffInfo
|
||||
mergedPullRequests: PullRequestInfo[]
|
||||
options: Options
|
||||
fromTag: TagInfo
|
||||
toTag: TagInfo
|
||||
}
|
||||
|
||||
export class PullRequestCollector {
|
||||
@@ -43,7 +44,7 @@ export class PullRequestCollector {
|
||||
private fetchReleaseInformation: boolean = false,
|
||||
private fetchReviews: boolean = false,
|
||||
private commitMode: boolean = false,
|
||||
private configuration: Configuration
|
||||
private configuration: PullConfiguration
|
||||
) {}
|
||||
|
||||
async build(): Promise<Data | null> {
|
||||
@@ -113,7 +114,7 @@ export class PullRequestCollector {
|
||||
|
||||
core.endGroup()
|
||||
|
||||
const options = {
|
||||
return await pullData(octokit, {
|
||||
owner: this.owner,
|
||||
repo: this.repo,
|
||||
fromTag: previousTag,
|
||||
@@ -125,9 +126,7 @@ export class PullRequestCollector {
|
||||
fetchReviews: this.fetchReviews,
|
||||
commitMode: this.commitMode,
|
||||
configuration: this.configuration
|
||||
}
|
||||
|
||||
return await pullData(octokit, options)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,6 +153,7 @@ export async function pullData(octokit: Octokit, options: Options): Promise<Data
|
||||
return {
|
||||
diffInfo,
|
||||
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 {Unpacked} from './utils'
|
||||
import moment from 'moment'
|
||||
import {Property, Sort} from './configuration'
|
||||
import {Property, Sort} from './types'
|
||||
import {Commits, DiffInfo, filterCommits} from './commits'
|
||||
import {Options} from './prCollector'
|
||||
|
||||
|
||||
@@ -1,42 +1,5 @@
|
||||
import * as core from '@actions/core'
|
||||
import {Extractor, Property, Regex, Rule, Transformer} from './configuration'
|
||||
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
|
||||
}
|
||||
import {Extractor, Property, Regex, RegexTransformer, Transformer} from './types'
|
||||
|
||||
export function validateTransformer(transformer?: Regex): RegexTransformer | null {
|
||||
if (transformer === undefined) {
|
||||
@@ -95,11 +58,3 @@ export function buildRegex(
|
||||
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 {Octokit, RestEndpointMethodTypes} from '@octokit/rest'
|
||||
import {SemVer} from 'semver'
|
||||
import {TagResolver} from './configuration'
|
||||
import {RegexTransformer, TagResolver} from './types'
|
||||
import {createCommandManager} from './gitHelper'
|
||||
import moment from 'moment'
|
||||
import {RegexTransformer, validateTransformer} from './regexUtils'
|
||||
import {validateTransformer} from './regexUtils'
|
||||
|
||||
export interface TagResult {
|
||||
from: TagInfo | null
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export interface Configuration {
|
||||
export interface PullConfiguration {
|
||||
max_tags_to_fetch: number
|
||||
max_pull_requests: 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
|
||||
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 {PullConfiguration} from 'github-pr-collector/lib/types'
|
||||
|
||||
export interface Configuration {
|
||||
export interface Configuration extends PullConfiguration {
|
||||
max_tags_to_fetch: number
|
||||
max_pull_requests: 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
|
||||
}
|
||||
|
||||
const resolvedOptions = prData.options
|
||||
const options: ReleaseNotesOptions = {
|
||||
owner: this.owner,
|
||||
repo: this.repo,
|
||||
fromTag: resolvedOptions.fromTag,
|
||||
toTag: resolvedOptions.toTag,
|
||||
fromTag: prData.fromTag,
|
||||
toTag: prData.toTag,
|
||||
includeOpen: this.includeOpen,
|
||||
failOnError: this.failOnError,
|
||||
fetchReviewers: this.fetchReviewers,
|
||||
|
||||
+3
-1
@@ -3,9 +3,11 @@ import {Category, Configuration, Placeholder, Property} from './configuration'
|
||||
import {createOrSet, haveCommonElementsArr, haveEveryElementsArr} from './utils'
|
||||
import {CommentInfo, EMPTY_COMMENT_INFO, PullRequestInfo, retrieveProperty, sortPullRequests} from 'github-pr-collector/lib/pullRequests'
|
||||
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 {ReleaseNotesOptions} from './releaseNotesBuilder'
|
||||
import {matchesRules} from './regexUtils'
|
||||
import {RegexTransformer} from 'github-pr-collector/lib/types'
|
||||
|
||||
const EMPTY_MAP = new Map<string, string>()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user