forked from segmentio/action-destinations
-
Notifications
You must be signed in to change notification settings - Fork 0
62 lines (60 loc) · 2.32 KB
/
label-prs.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# This workflow labels PRs based on the files that were changed. It uses a custom script to this
# instead of actions/labeler as few of the tags are more than just file changes.
name: Label PRs
on:
pull_request_target:
types: [opened, synchronize, reopened]
jobs:
pr-labeler:
runs-on: ubuntu-20.04
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Compute Labels
id: compute-labels
uses: actions/github-script@v7
with:
# Required for the script to access team membership information.
# Scope: members:read and contentes:read permission on the organization.
github-token: ${{ secrets.GH_PAT_MEMBER_AND_PULL_REQUEST_READONLY }}
script: |
const script = require('./scripts/github-action/compute-labels.js')
await script({github, context, core})
# Separating apply labels to separate step to avoid using PAT token auth.
- name: Apply Labels
uses: actions/github-script@v7
env:
labelsToAdd: '${{ steps.compute-labels.outputs.add }}'
labelsToRemove: '${{ steps.compute-labels.outputs.remove }}'
with:
script: |
const { labelsToAdd, labelsToRemove, DRY_RUN } = process.env
if(Boolean(DRY_RUN)){
core.info(`Would have added labels: ${labelsToAdd}`)
core.info(`Would have removed labels: ${labelsToRemove}`)
return
}
if(labelsToAdd.length > 0) {
await github.rest.issues.addLabels({
issue_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: labelsToAdd.split(',')
});
}
if(labelsToRemove.length > 0) {
const requests = labelsToRemove.split(',').map(label => {
return github.rest.issues.removeLabel({
issue_number: context.payload.pull_request.number,
name: label,
owner: context.repo.owner,
repo: context.repo.repo
});
});
await Promise.all(requests);
}