aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/label-bug-fix.yml
blob: 4730d6194468caf77581870c8132990cfcf93305 (plain)
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
name: "Bug Fix label"
on:
    pull_request_target:
        types: [ opened, edited ]
jobs:
    assign-label:
        if: github.event.pull_request.state == 'open' # Condition to check if PR is open
        runs-on: ubuntu-latest
        permissions:
            issues: write
            pull-requests: write
            contents: read
        steps:
            -   name: label
                env:
                    TITLE: ${{ github.event.pull_request.title }}
                    LABEL: Bug Fix
                uses: actions/github-script@v7
                with:
                    github-token: ${{ secrets.GITHUB_TOKEN}}
                    script: |
                        if(process.env.TITLE.split(":")[0].toUpperCase().includes("FIX")){
                          github.rest.issues.addLabels({
                            issue_number: context.issue.number,
                            owner: context.repo.owner,
                            repo: context.repo.repo,
                            labels: [process.env.LABEL]
                          })
                        }else{
                          const {data} = await github.rest.issues.listLabelsOnIssue({
                            issue_number: context.issue.number,
                            owner: context.repo.owner,
                            repo: context.repo.repo,
                          })
                          const filtered = data.filter(label => label.name == process.env.LABEL)
                          if(filtered.length == 1){
                            github.rest.issues.removeLabel({
                              issue_number: context.issue.number,
                              owner: context.repo.owner,
                              repo: context.repo.repo,
                              name: process.env.LABEL
                            })
                          }
                        }