mirror of
https://github.com/dorny/paths-filter.git
synced 2025-06-08 18:09:04 +00:00
Enable custom ref and base on PRs
This commit is contained in:
parent
8c7f485a57
commit
b0bc141e31
6 changed files with 156 additions and 15 deletions
|
@ -260,7 +260,7 @@ function fixStdOutNullTermination(): void {
|
|||
core.info('')
|
||||
}
|
||||
|
||||
const statusMap: {[char: string]: ChangeStatus} = {
|
||||
export const statusMap: {[char: string]: ChangeStatus} = {
|
||||
A: ChangeStatus.Added,
|
||||
C: ChangeStatus.Copied,
|
||||
D: ChangeStatus.Deleted,
|
||||
|
|
34
src/main.ts
34
src/main.ts
|
@ -18,6 +18,7 @@ async function run(): Promise<void> {
|
|||
process.chdir(workingDirectory)
|
||||
}
|
||||
|
||||
const customfiles = core.getInput('files', {required: false})
|
||||
const token = core.getInput('token', {required: false})
|
||||
const ref = core.getInput('ref', {required: false})
|
||||
const base = core.getInput('base', {required: false})
|
||||
|
@ -26,13 +27,16 @@ async function run(): Promise<void> {
|
|||
const listFiles = core.getInput('list-files', {required: false}).toLowerCase() || 'none'
|
||||
const initialFetchDepth = parseInt(core.getInput('initial-fetch-depth', {required: false})) || 10
|
||||
|
||||
const files = customfiles
|
||||
? parseFilesInput(customfiles.split(/\r?\n/))
|
||||
: await getChangedFiles(token, base, ref, initialFetchDepth)
|
||||
|
||||
if (!isExportFormat(listFiles)) {
|
||||
core.setFailed(`Input parameter 'list-files' is set to invalid value '${listFiles}'`)
|
||||
return
|
||||
}
|
||||
|
||||
const filter = new Filter(filtersYaml)
|
||||
const files = await getChangedFiles(token, base, ref, initialFetchDepth)
|
||||
core.info(`Detected ${files.length} changed files`)
|
||||
const results = filter.match(files)
|
||||
exportResults(results, listFiles)
|
||||
|
@ -41,6 +45,28 @@ async function run(): Promise<void> {
|
|||
}
|
||||
}
|
||||
|
||||
function parseFilesInput(customfiles: string[]): File[] {
|
||||
const files: File[] = []
|
||||
for (let i = 0; i + 1 < customfiles.length; i += 1) {
|
||||
var filearray = customfiles[i].split(/\s+/)
|
||||
if (filearray.length == 1) {
|
||||
var filestatus = 'U'
|
||||
var filename = filearray[0]
|
||||
} else if (filearray.length == 2) {
|
||||
var filestatus = filearray[0]
|
||||
var filename = filearray[1]
|
||||
} else {
|
||||
throw new Error(`Line '${i + 1}' in custom file: '${customfiles[i]}' is not parseable.`)
|
||||
}
|
||||
|
||||
files.push({
|
||||
status: git.statusMap[filestatus],
|
||||
filename: filename
|
||||
})
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
function isPathInput(text: string): boolean {
|
||||
return !(text.includes('\n') || text.includes(':'))
|
||||
}
|
||||
|
@ -68,12 +94,12 @@ async function getChangedFiles(token: string, base: string, ref: string, initial
|
|||
}
|
||||
|
||||
const prEvents = ['pull_request', 'pull_request_review', 'pull_request_review_comment', 'pull_request_target']
|
||||
if (prEvents.includes(github.context.eventName)) {
|
||||
if (prEvents.includes(github.context.eventName) && !ref && !base) {
|
||||
if (ref) {
|
||||
core.warning(`'ref' input parameter is ignored when 'base' is set to HEAD`)
|
||||
core.warning(`'ref' input parameter is ignored when 'base' is not also set on PR events.`)
|
||||
}
|
||||
if (base) {
|
||||
core.warning(`'base' input parameter is ignored when action is triggered by pull request event`)
|
||||
core.warning(`'base' input parameter is ignored when 'ref' is not also set on PR events.`)
|
||||
}
|
||||
const pr = github.context.payload.pull_request as Webhooks.WebhookPayloadPullRequestPullRequest
|
||||
if (token) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue