Skip to content

Commit d1f6100

Browse files
authored
Merge pull request #1623 from hydephp/create-workflow-to-label-pull-requests
Internal: Update pull request labeling workflow
2 parents 93d9e5b + 4a9e81c commit d1f6100

File tree

1 file changed

+42
-20
lines changed

1 file changed

+42
-20
lines changed

.github/workflows/label-pull-requests.yml

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,49 @@ name: 🏷 Label Pull Requests
22

33
on:
44
pull_request:
5-
types: [opened, edited, reopened]
5+
types: [opened, edited, reopened, closed]
66

77
jobs:
88

9-
label-pull-requests:
10-
runs-on: ubuntu-latest
11-
permissions:
12-
contents: read
13-
pull-requests: write
9+
label-pull-requests:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
pull-requests: write
1414

15-
steps:
16-
# If PR title starts with "Internal: " then add the "Internal" label
17-
- name: Label Internal Pull Requests
18-
if: "startsWith(github.event.pull_request.title, 'Internal: ')"
19-
uses: actions/github-script@v7
20-
with:
21-
github-token: ${{ secrets.GITHUB_TOKEN }}
22-
script: |
23-
github.rest.issues.addLabels({
24-
issue_number: context.issue.number,
25-
owner: context.repo.owner,
26-
repo: context.repo.repo,
27-
labels: ['Internal']
28-
})
15+
steps:
16+
# If PR title starts with "Internal: " then add the "Internal" label
17+
- name: Label Internal Pull Requests
18+
if: "startsWith(github.event.pull_request.title, 'Internal: ')"
19+
uses: actions/github-script@v7
20+
with:
21+
github-token: ${{ secrets.GITHUB_TOKEN }}
22+
script: |
23+
github.rest.issues.addLabels({
24+
issue_number: context.issue.number,
25+
owner: context.repo.owner,
26+
repo: context.repo.repo,
27+
labels: ['Internal']
28+
})
29+
30+
# Remove "run-visual-tests" label if the pull request is closed
31+
- name: Remove run-visual-tests Label
32+
if: github.event_name == 'pull_request' && github.event.action == 'closed'
33+
uses: actions/github-script@v7
34+
with:
35+
github-token: ${{ secrets.GITHUB_TOKEN }}
36+
script: |
37+
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
38+
issue_number: context.issue.number,
39+
owner: context.repo.owner,
40+
repo: context.repo.repo
41+
});
42+
const visualTestsLabel = labels.find(label => label.name === 'run-visual-tests');
43+
if (visualTestsLabel) {
44+
await github.rest.issues.removeLabel({
45+
issue_number: context.issue.number,
46+
name: 'run-visual-tests',
47+
owner: context.repo.owner,
48+
repo: context.repo.repo
49+
});
50+
}

0 commit comments

Comments
 (0)