-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate-jira-state.js
More file actions
42 lines (37 loc) · 1.21 KB
/
validate-jira-state.js
File metadata and controls
42 lines (37 loc) · 1.21 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
const fetch = require('node-fetch');
const isValidJiraState = async (pr, statusCategory, jiraUsername, jiraSecret, log) => {
const response = await fetch(`https://ovearup.atlassian.net/rest/api/3/issue/${pr}?fields=status`, {
method: 'GET',
headers: headers(jiraUsername, jiraSecret),
})
const status = await response.status;
const json = await response.json();
if(status === 200) {
const jiraStatusCategory = json.fields.status.statusCategory.name;
log(`${pr} has status category: ${jiraStatusCategory}`);
if(jiraStatusCategory === statusCategory) {
return {
result: true,
message: `${pr} has status category: ${jiraStatusCategory}`
}
} else {
return {
result: false,
message: `${pr} has status category ${jiraStatusCategory}, expected ${statusCategory}`
}
}
} else {
log(`Couldn't find Jira ticket: ${pr}`);
return {
result: false,
message: `Could not find Jira ticket ${pr}`
}
}
}
const headers = (jiraUsername, jiraSecret) => ({
'Content-Type': 'application/json',
'Authorization': `Basic ${Buffer.from(`${jiraUsername}:${jiraSecret}`).toString('base64')}`
})
module.exports = {
isValidJiraState
}