2021-10-01 13:09:20 +03:00
---
# vi: ts=2 sw=2 et:
2021-10-01 13:10:22 +03:00
# SPDX-License-Identifier: LGPL-2.1-or-later
2021-10-01 13:09:20 +03:00
#
2020-12-12 09:30:26 +03:00
name : "Pull Request Labeler"
2021-10-01 13:09:20 +03:00
2020-12-12 09:30:26 +03:00
on :
2022-12-09 14:10:09 +03:00
pull_request_target :
2023-01-10 15:16:33 +03:00
types : [ opened, synchronize, reopened, ready_for_review, closed]
2024-01-02 14:38:09 +03:00
paths-ignore :
- '.github/labeler.yml'
- '.github/workflows/labeler.yml'
# Allow testing changes made to the labeler configuration
pull_request :
paths :
- '.github/labeler.yml'
- '.github/workflows/labeler.yml'
2022-12-09 14:10:09 +03:00
issue_comment :
types : [ created]
2020-12-12 09:30:26 +03:00
2021-11-13 17:40:20 +03:00
permissions :
contents : read
2020-12-12 09:30:26 +03:00
jobs :
triage :
2022-12-09 14:10:09 +03:00
if : github.repository == 'systemd/systemd'
2024-06-07 11:55:53 +03:00
runs-on : ubuntu-24.04
2021-11-14 12:41:42 +03:00
permissions :
pull-requests : write
2023-02-08 15:02:49 +03:00
2020-12-12 09:30:26 +03:00
steps :
2024-01-02 14:38:09 +03:00
- name : Repository checkout
2024-11-01 12:01:41 +03:00
uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
2024-01-02 14:38:09 +03:00
if : github.event_name == 'pull_request'
2023-02-08 15:02:49 +03:00
- name : Label PR based on policy in labeler.yml
2024-01-01 12:40:40 +03:00
uses : actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9
2024-07-04 21:55:53 +03:00
if : startsWith(github.event_name, 'pull_request') && github.base_ref == 'main' && github.event.action != 'closed'
2020-12-12 09:30:26 +03:00
with :
repo-token : "${{ secrets.GITHUB_TOKEN }}"
configuration-path : .github/labeler.yml
2024-01-02 14:18:52 +03:00
sync-labels : false
2022-12-08 18:25:03 +03:00
2023-02-08 15:02:49 +03:00
- name : Set or remove labels based on systemd development workflow
2023-12-01 12:03:48 +03:00
uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
2024-01-02 14:38:09 +03:00
if : startsWith(github.event_name, 'pull_request') && github.event.action != 'closed' && !github.event.pull_request.draft
2022-12-08 18:25:03 +03:00
with :
script : |
2022-12-09 14:10:09 +03:00
response = await github.rest.issues.listLabelsOnIssue({
2022-12-08 18:25:03 +03:00
issue_number : context.issue.number,
owner : context.repo.owner,
repo : context.repo.repo,
2022-12-09 14:10:09 +03:00
});
2024-05-07 16:53:35 +03:00
original = new Set(response.data.map(l => l.name));
labels = new Set(original);
good_to_merge = new Set([
2022-12-09 14:10:09 +03:00
"good-to-merge/waiting-for-ci 👍" ,
"good-to-merge/after-next-release" ,
"good-to-merge/with-minor-suggestions" ,
"good-to-merge/waiting-for-reporter-feedback 👍" ,
2024-05-07 16:53:35 +03:00
] );
2022-12-09 14:10:09 +03:00
2024-05-07 16:53:35 +03:00
if (Array.from(labels).filter(l => good_to_merge.has(l)).length == 0) {
labels.add("please-review");
2022-12-09 14:10:09 +03:00
}
2022-12-08 18:25:03 +03:00
for (const label of ["reviewed/needs-rework 🔨",
"ci-fails/needs-rework 🔥" ,
2022-12-09 14:10:09 +03:00
"ci-failure-appears-unrelated" ,
"needs-rebase" ] ) {
2024-05-07 16:53:35 +03:00
labels.delete(label);
}
if (labels.size != original.size || Array.from(labels).some(l => !original.has(l))) {
await github.rest.issues.setLabels({
issue_number : context.issue.number,
owner : context.repo.owner,
repo : context.repo.repo,
labels : Array.from(labels),
});
2022-12-08 18:25:03 +03:00
}
2023-02-08 15:02:49 +03:00
- name : Add please-review label on command in issue comment
2023-12-01 12:03:48 +03:00
uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
2022-12-08 18:25:03 +03:00
if : github.event_name == 'issue_comment' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/please-review')
with :
script : |
2022-12-09 14:10:09 +03:00
await github.rest.issues.addLabels({
2022-12-08 18:25:03 +03:00
issue_number : context.issue.number,
owner : context.repo.owner,
repo : context.repo.repo,
labels : [ "please-review" ]
})
2023-01-10 15:16:33 +03:00
2023-02-08 15:02:49 +03:00
- name : Remove specific labels when PR is closed or merged
2023-12-01 12:03:48 +03:00
uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
2024-01-02 14:38:09 +03:00
if : startsWith(github.event_name, 'pull_request') && github.event.action == 'closed'
2023-01-10 15:16:33 +03:00
with :
script : |
2024-05-07 16:53:35 +03:00
response = await github.rest.issues.listLabelsOnIssue({
issue_number : context.issue.number,
owner : context.repo.owner,
repo : context.repo.repo,
});
original = new Set(response.data.map(l => l.name));
labels = new Set(original);
2023-01-10 15:16:33 +03:00
for (const label of ["please-review",
"reviewed/needs-rework 🔨" ,
"ci-fails/needs-rework 🔥" ,
"needs-rebase" ,
"good-to-merge/waiting-for-ci 👍" ,
"good-to-merge/after-next-release" ,
"good-to-merge/with-minor-suggestions" ,
"good-to-merge/waiting-for-reporter-feedback 👍" ,
"needs-discussion 🤔" ,
"needs-reporter-feedback ❓" ,
2023-02-11 09:38:28 +03:00
"dont-merge 💣" ,
2023-02-07 17:39:37 +03:00
"squash-on-merge" ,
2023-02-11 09:35:07 +03:00
"quick-review 🏃♂️" ] ) {
2024-05-07 16:53:35 +03:00
labels.delete(label);
}
if (labels.size != original.size || Array.from(labels).some(l => !original.has(l))) {
await github.rest.issues.setLabels({
issue_number : context.issue.number,
owner : context.repo.owner,
repo : context.repo.repo,
labels : Array.from(labels),
});
2023-01-10 15:16:33 +03:00
}