- 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
+9 -9
View File
@@ -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
}
}
+1 -1
View File
@@ -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 -46
View File
@@ -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
}
+2 -2
View File
@@ -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
}