2.2 KB58 lines
Blame
1name: Apply labels to PR
2on:
3 pull_request_target:
4 # required for pr-labeler to support PRs from forks
5 # ===================== ⛔ ☢️ 🚫 ⚠️ Warning ⚠️ 🚫 ☢️ ⛔ =======================
6 # Be very careful what you put in this GitHub Action workflow file to avoid
7 # malicious PRs from getting access to the Mermaid-js repo.
8 #
9 # Please read the following first before reviewing/merging:
10 # - https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target
11 # - https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
12 types: [opened, reopened, synchronize]
13
14permissions:
15 contents: read
16
17jobs:
18 pr-labeler:
19 runs-on: ubuntu-latest
20 permissions:
21 contents: read # read permission is required to read config file
22 pull-requests: write # write permission is required to label PRs
23 steps:
24 - name: Label PR
25 uses: release-drafter/release-drafter@b1476f6e6eb133afa41ed8589daba6dc69b4d3f5 # v6.1.0
26 with:
27 config-name: pr-labeler.yml
28 disable-autolabeler: false
29 disable-releaser: true
30 env:
31 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32
33 - name: Add "Sponsored by MermaidChart" label
34 uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
35 with:
36 github-token: ${{ secrets.GITHUB_TOKEN }}
37 script: |
38 const prNumber = context.payload.pull_request.number;
39 const { data: commits } = await github.rest.pulls.listCommits({
40 owner: context.repo.owner,
41 repo: context.repo.repo,
42 pull_number: prNumber,
43 });
44
45 const isSponsored = commits.every(
46 (c) => c.commit.author.email?.endsWith('@mermaidchart.com')
47 );
48
49 if (isSponsored) {
50 console.log('PR is sponsored. Adding label.');
51 await github.rest.issues.addLabels({
52 owner: context.repo.owner,
53 repo: context.repo.repo,
54 issue_number: prNumber,
55 labels: ['Sponsored by MermaidChart'],
56 });
57 }
58