-
Notifications
You must be signed in to change notification settings - Fork 90
118 lines (114 loc) · 4.83 KB
/
Copy pathissues-jira.yml
File metadata and controls
118 lines (114 loc) · 4.83 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: Create Jira Ticket for Github Issue
on:
issues:
types: [opened, reopened]
jobs:
issue-jira:
runs-on: ubuntu-latest
steps:
- name: Create Jira Issue
id: create_jira
uses: actions/github-script@v9
with:
script: |
const baseUrl = process.env.JIRA_BASE_URL;
const userEmail = process.env.JIRA_USER_EMAIL;
const jiraToken = process.env.JIRA_API_TOKEN;
const jiraProject = process.env.JIRA_PROJECT;
const jiraIssueType = process.env.JIRA_ISSUE_TYPE;
const jiraFields = JSON.parse(process.env.ISSUES_JIRA_FIELDS);
let requestBody = JSON.stringify({
fields: {
...jiraFields,
"project": {
"key": jiraProject
},
"issuetype": {
"name": jiraIssueType
},
"summary": "Github | Issue | ${{ github.event.repository.name }} | ${{ github.event.issue.title }}",
"description": {
"version": 1,
"type": "doc",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Github Issue",
"marks": [
{
"type": "strong"
}
]
},
{
"type": "text",
"text": ": "
},
{
"type": "text",
"text": "${{ github.event.issue.html_url }}",
"marks": [
{
"type": "link",
"attrs": {
"href": "${{ github.event.issue.html_url }}"
}
}
]
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Description",
"marks": [
{
"type": "strong"
}
]
},
{
"type": "text",
"text": ":"
}
]
},
{
"type": "codeBlock",
"content": [
{
"type": "text",
"text": `${{ github.event.issue.body }}`
}
]
}
]
}
}
});
const response = await fetch(`${baseUrl}/rest/api/3/issue`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Basic ${btoa(userEmail + ":" + jiraToken)}`
},
body: requestBody
});
if (!response.ok) {
throw new Error(`JIRA API error! Status: ${response.status}`);
}
const data = await response.json();
console.log('Jira Issue Created:', data.key);
env:
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
JIRA_PROJECT: ${{ secrets.JIRA_PROJECT }}
JIRA_ISSUE_TYPE: ${{ secrets.JIRA_ISSUE_TYPE }}
ISSUES_JIRA_FIELDS: "${{ secrets.ISSUES_JIRA_FIELDS }}"