-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
81 lines (71 loc) · 2.53 KB
/
index.js
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
const core = require('@actions/core');
const github = require('@actions/github');
const getTicketKeys = require('./getTicketKeys');
const getWabbiGatePass = require('./getWabbiGatePass');
const GATE_PASSED = 'The Wabbi Gate passed.';
const NO_GATE_STATUS = 'There is no Wabbi Gate status.';
const GATE_FAILED_PART1 = 'There are 1 or more policies associated with ticket(s), ';
const GATE_FAILED_PART2 = ', that have not yet been settled.';
const PASSED_STATUS = 'PASSED';
/**
* This GitHub action determines the ticket keys associated with the pull request.
* The action displays the Wabbi gate status for the associated ticket keys.
* The action fails if the Wabbi gate status is FAILED
* @param {Object} pullRequest GitHub pull request associated with action
*/
const processPullRequestEvent = async (pullRequest) => {
// Obtain pull request information
const commitsUrl = pullRequest._links.commits.href;
const pullRequestSource = pullRequest.head.ref;
const pullRequestTitle = pullRequest.title;
// Obtain wabbi configuration info
const wabbiHost = core.getInput('wabbiHost');
const wabbiProjectId = core.getInput('wabbiProjectId');
const issuePrefixes = core.getInput('issuePrefixes');
const wabbiGateId = core.getInput('wabbiGateId');
const wabbiGateToken = core.getInput('wabbiGateToken');
// Obtain github access info
const githubToken = core.getInput('githubToken');
try {
// Get Jira ticket keys associated with the pull request
let ticketKeys = await getTicketKeys(issuePrefixes,
pullRequestTitle,
pullRequestSource,
commitsUrl,
githubToken);
// Display extracted ticket keys within action console
if (ticketKeys.length) {
console.log(`The ticket keys are ${ticketKeys}`);
}
else {
console.log('No ticket keys found');
}
// Obtain the Wabbi Gate status associated with ticket keys
let gateStatus = await getWabbiGatePass(wabbiHost,
wabbiGateToken,
wabbiProjectId,
wabbiGateId,
ticketKeys);
// Define Wabbi gate status and action pass / fail
if (gateStatus === PASSED_STATUS) {
core.setOutput('status', GATE_PASSED);
}
else if (gateStatus === undefined || gateStatus === null) {
core.setOutput('status', NO_GATE_STATUS);
}
else {
let gateFailed = `${GATE_FAILED_PART1}${ticketKeys.join(', ')}${GATE_FAILED_PART2}`;
core.setOutput('status', gateFailed);
core.setFailed(gateFailed);
}
}
catch (error) {
core.setFailed(error.message);
}
};
// Driver function to handle async calls
Promise.resolve(
processPullRequestEvent(
github.context.payload.pull_request
)
);