mirror of
https://github.com/actions/add-to-project.git
synced 2025-12-11 12:37:16 +00:00
Add label filter operator
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user