-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (59 loc) · 2.65 KB
/
github_zendesk_issue_labelled.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
name: Create Zendesk ticket
on:
workflow_call:
inputs:
ZENDESK_TENANT_NAME:
description: 'The zendesk tenant name, can be found in the URL, for example https://my-subdomain.zendesk.com/'
required: true
type: string
ISSUE_LABEL:
description: 'The required label to trigger this workflow'
required: true
type: string
secrets:
ZENDESK_AUTH_TOKEN:
description: 'The zendesk basic auth token for authentification. See https://support.zendesk.com/hc/en-us/articles/115000510267-How-can-I-authenticate-API-requests-#heading2'
required: true
jobs:
create-ticket:
name: Create Zendesk ticket
if: github.event.label.name == inputs.ISSUE_LABEL
runs-on: ubuntu-latest
steps:
- env:
TENANT_NAME: ${{ inputs.ZENDESK_TENANT_NAME }}
ZENDESK_AUTH_TOKEN: ${{ secrets.ZENDESK_AUTH_TOKEN }}
ISSUE_TITLE: ${{ github.event.issue.title }}
ISSUE_BODY: ${{ github.event.issue.body }}
ISSUE_USER: ${{ github.event.issue.user.login }}
ISSUE_URL: ${{ github.event.issue.html_url }}
run: |
## look up ticket in zendesk
echo "Looking up ticket by issue: $ISSUE_URL"
tickets=$(curl --silent "https://$TENANT_NAME.zendesk.com/api/v2/search.json?query=external_id:$ISSUE_URL" -H "Authorization: Basic $ZENDESK_AUTH_TOKEN" -H "Content-Type: application/json")
ticket_number=$(echo $tickets | jq '.results[0].id')
echo "Found ticket number: " $ticket_number
if [[ "$ticket_number" == "null" ]];
then
## create ticket if the lookup failed
title=$(jq -n --arg title "$ISSUE_TITLE" '{title: $title}' | jq .title)
title=${title:1:-1}
echo "$title"
body=$(jq -n --arg body "$ISSUE_BODY" '{body: $body}' | jq .body)
body=${body:1:-1}
echo "$body"
curl --silent -X POST https://$TENANT_NAME.zendesk.com/api/v2/tickets -H "Authorization: Basic $ZENDESK_AUTH_TOKEN" -H "Content-Type: application/json" --data-binary @- <<DATA
{
"ticket": {
"subject": "Github_Issue: $title",
"comment": { "body": "[GITHUB_ISSUE_COMMENT]\n\n${body}\n\nGITHUB ISSUE URL: $ISSUE_URL" },
"external_id": "$ISSUE_URL",
"requester": { "locale_id": 1, "name": "$ISSUE_USER from Github", "email": "[email protected]" },
"status": "open"
}
}
DATA
echo "Zendesk ticket created"
else
echo "Ticket exists, no need to create"
fi