generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
42 lines (37 loc) · 1.63 KB
/
label-pull-requests.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
name: Label pull request
# Label pull request based on Jira issue type
on:
pull_request:
types: opened
jobs:
label:
if: startsWith(github.event.pull_request.title, 'PI-')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check if PR is already labelled
id: labels
run: echo "count=$(gh pr view '${{ github.event.pull_request.number }}' --json 'labels' --jq '.labels | length')" | tee -a "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ github.token }}
- name: Get Jira issue type
if: ${{ steps.labels.outputs.count == '0' }}
id: jira
run: |
jira_issue_number=$(echo "$PR_TITLE" | sed -E 's/^(PI-[0-9]+).*/\1/')
jira_issue_type=$(curl -s -u "$JIRA_USERNAME:$JIRA_TOKEN" "https://dsdmoj.atlassian.net/rest/api/2/issue/$jira_issue_number" | jq -r '.fields.issuetype.name')
echo "issue-type=$jira_issue_type" | tee -a "$GITHUB_OUTPUT"
env:
PR_TITLE: ${{ github.event.pull_request.title }}
JIRA_USERNAME: ${{ secrets.JIRA_USERNAME }}
JIRA_TOKEN: ${{ secrets.JIRA_TOKEN }}
- name: Label as bug
if: ${{ steps.labels.outputs.count == '0' && steps.jira.outputs.issue-type == 'Bug' }}
run: gh pr edit '${{ github.event.pull_request.number }}' --add-label bug
env:
GH_TOKEN: ${{ github.token }}
- name: Label as enhancement
if: ${{ steps.labels.outputs.count == '0' && steps.jira.outputs.issue-type == 'Story' }}
run: gh pr edit '${{ github.event.pull_request.number }}' --add-label enhancement
env:
GH_TOKEN: ${{ github.token }}