mirror of
https://github.com/django/django.git
synced 2025-03-28 18:20:49 +00:00
The `pull_request` trigger runs in the context of the PR, and has limited access to information stored in the base repo django/django. As access is needed to the label "no ticket" in django/django, use the `pull_request_target` trigger.
54 lines
1.8 KiB
YAML
54 lines
1.8 KiB
YAML
name: Labels
|
|
|
|
on:
|
|
pull_request_target:
|
|
types: [ edited, opened, reopened, ready_for_review ]
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
permissions:
|
|
pull-requests: write
|
|
|
|
jobs:
|
|
no_ticket:
|
|
name: "Flag if no Trac ticket is found in the title"
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: "Check title and manage labels"
|
|
uses: actions/github-script@v7
|
|
with:
|
|
script: |
|
|
const title = context.payload.pull_request.title;
|
|
const regex = /#[0-9]+[ ,:]?/gm;
|
|
const label = "no ticket";
|
|
const hasMatch = regex.test(title);
|
|
const labels = context.payload.pull_request.labels.map(l => l.name);
|
|
const owner = context.repo.owner;
|
|
const repo = context.repo.repo;
|
|
const pr_number = context.payload.pull_request.number;
|
|
console.log(`=> Pull Request Title: ${title}`);
|
|
console.log(`=> Labels on PR: [${labels}]`);
|
|
if (hasMatch && labels.includes(label)) {
|
|
console.log(`==> Removing label "${label}" from PR #${pr_number}`);
|
|
await github.rest.issues.removeLabel({
|
|
owner,
|
|
repo,
|
|
issue_number: pr_number,
|
|
name: label
|
|
});
|
|
} else if (!hasMatch && !labels.includes(label)) {
|
|
console.log(`==> Adding label "${label}" to PR #${pr_number}`);
|
|
await github.rest.issues.addLabels({
|
|
owner,
|
|
repo,
|
|
issue_number: pr_number,
|
|
labels: [label]
|
|
});
|
|
} else {
|
|
console.log(`No action needed for PR #${pr_number}`);
|
|
}
|