-
Notifications
You must be signed in to change notification settings - Fork 167
75 lines (68 loc) · 3.81 KB
/
create_pylon_issue.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
63
64
65
66
67
68
69
70
71
72
73
74
75
name: Create Pylon Issue
on:
issues:
types: [opened]
pull_request:
types: [opened]
jobs:
create_pylon_issue:
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v2
- name: Install jq
run: sudo apt-get install -y jq
- name: Create Pylon Issue for GitHub Issue
if: github.event_name == 'issues'
run: |
response=$(curl --request POST \
--url https://api.usepylon.com/issues \
--header 'Authorization: ${{ secrets.PYLON_API_KEY }}' \
--header 'Content-Type: application/json' \
--data '{
"account_id": "${{ secrets.PYLON_ACCOUNT_ID }}",
"requester_id": "${{ secrets.PYLON_REQUESTER_ID }}",
"priority": "medium",
"title": "${{ github.event.issue.title }}",
"body_html": "<html lang=en><head><title>GitHub Issue Details</title></head><body><h1>GitHub Issue Details</h1><p><strong>Repository:</strong> ${{ github.repository }}</p><p><strong>Type:</strong> Github Issue</p><p><strong>URL:</strong> <a href=${{ github.event.issue.html_url }}>${{ github.event.issue.html_url }}</a></p></body></html>"
}')
ticket_id=$(echo $response | jq -r '.data.id')
echo "ticket_id=$ticket_id" >> $GITHUB_ENV
- name: Add Pylon ticket ID to issue body
if: success()
run: |
issue_body=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}" | jq -r '.body')
new_body="$issue_body<!-- pylon-ticket-id: ${{ env.ticket_id }} -->"
json_body=$(jq -R -s --arg body "$new_body" '{"body": $body}' <<< "$new_body")
curl -X PATCH -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d "$json_body" \
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}"
- name: Create Pylon Issue for Pull Request
if: github.event_name == 'pull_request'
run: |
response=$(curl --request POST \
--url https://api.usepylon.com/issues \
--header 'Authorization: ${{ secrets.PYLON_API_KEY }}' \
--header 'Content-Type: application/json' \
--data '{
"account_id": "${{ secrets.PYLON_ACCOUNT_ID }}",
"requester_id": "${{ secrets.PYLON_REQUESTER_ID }}",
"priority": "high",
"title": "${{ github.event.pull_request.title }}",
"body_html": "<html lang=en><head><title>GitHub Pull Request Details</title></head><body><h1>GitHub Pull Request Details</h1><p><strong>Repository:</strong> ${{ github.repository }}</p><p><strong>Type:</strong> Pull Request</p><p><strong>URL:</strong> <a href=${{ github.event.pull_request.html_url }}>${{ github.event.pull_request.html_url }}</a></p></body></html>"
}')
ticket_id=$(echo $response | jq -r '.data.id')
echo "ticket_id=$ticket_id" >> $GITHUB_ENV
- name: Add Pylon ticket ID to PR body
if: success()
run: |
pr_body=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}" | jq -r '.body')
new_body="$pr_body<!-- pylon-ticket-id: ${{ env.ticket_id }} -->"
json_body=$(jq -R -s --arg body "$new_body" '{"body": $body}' <<< "$new_body")
curl -X PATCH -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d "$json_body" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}"