-
Notifications
You must be signed in to change notification settings - Fork 349
67 lines (62 loc) · 2.65 KB
/
Copy pathdependabot2jira.yml
File metadata and controls
67 lines (62 loc) · 2.65 KB
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
63
64
65
66
67
name: Dependabot Jira ticket
# This workflow is triggered to create a Jira ticket for every new dependabot PR
permissions: {}
on:
pull_request:
types: [opened]
jobs:
run-if-dependabot:
if: startsWith(github.actor, 'dependabot')
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Create a new Jira ticket
env:
JIRA_PROJECT_KEY: "DAOS"
PR_TITLE: ${{ github.event.pull_request.title }}
PR_BODY: ${{ github.event.pull_request.body }}
run: |
new_title=$(echo "$PR_TITLE" | sed 's/^Doc-only: true //')
jira_response=$(curl -u "${{ secrets.JIRA_EMAIL }}:${{ secrets.JIRA_API_TOKEN }}" \
-X POST \
-H "Content-Type: application/json" \
--data "$(jq -n --arg title "$new_title" \
--arg body "$PR_BODY" \
--arg project_key "$JIRA_PROJECT_KEY" \
'{
fields: {
project: { key: $project_key },
summary: $title,
description: {
type: "doc",
version: 1,
content: [
{
type: "paragraph",
content: [
{
type: "text",
text: $body
}
]
}
]
},
issuetype: { name: "Story" }
}
}')" ${{ secrets.JIRA_ISSUES_REST_API_V3_URL }}
)
jira_ticket_key=$(echo $jira_response | jq -r .key)
echo "PR_NEW_TITLE=$jira_ticket_key cq: $new_title" >> $GITHUB_ENV
- name: Update the PR title with a prefix based on the Jira ticket key
env:
PR_URL: "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}" # yamllint disable-line
run: |
curl -X PATCH -sS -o /dev/null \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
--data "$(jq -n --arg title "$PR_NEW_TITLE" \
'{
title: $title,
}' )" $PR_URL