Add label filter operator

This commit is contained in:
Abdelhamid
2022-03-23 12:34:28 +02:00
parent db4444090e
commit 0ad701a62e

View File

@@ -37,18 +37,22 @@ export async function addToProject(): Promise<void> {
.split(',') .split(',')
.map(l => l.trim()) .map(l => l.trim())
.filter(l => l.length > 0) ?? [] .filter(l => l.length > 0) ?? []
const labelOperator = core.getInput('label-operator').trim().toLocaleLowerCase()
const octokit = github.getOctokit(ghToken) const octokit = github.getOctokit(ghToken)
const urlMatch = projectUrl.match(urlParse) const urlMatch = projectUrl.match(urlParse)
const issue = github.context.payload.issue ?? github.context.payload.pull_request const issue = github.context.payload.issue ?? github.context.payload.pull_request
const issueLabels: string[] = (issue?.labels ?? []).map((l: {name: string}) => l.name) const issueLabels: string[] = (issue?.labels ?? []).map((l: {name: string}) => l.name)
// Ensure the issue matches our `labeled` filter, if provided. // Ensure the issue matches our `labeled` filter based on the label-operator.
if (labeled.length > 0) { if (labelOperator === 'and') {
const hasLabel = issueLabels.some(l => labeled.includes(l)) if (!labeled.every(l => issueLabels.includes(l))) {
core.info(`Skipping issue ${issue?.number} because it doesn't match all the labels: ${labeled.join(', ')}`)
if (!hasLabel) { return
}
} else {
if (labeled.length > 0 && !issueLabels.some(l => labeled.includes(l))) {
core.info(`Skipping issue ${issue?.number} because it does not have one of the labels: ${labeled.join(', ')}`) core.info(`Skipping issue ${issue?.number} because it does not have one of the labels: ${labeled.join(', ')}`)
return return
} }
} }