-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
49 lines (39 loc) · 1.29 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
const core = require('@actions/core');
const github = require('@actions/github');
let request = require('request-promise-native');
var bodyData = {
"audience": "api.atlassian.com",
"grant_type":"client_credentials",
"client_id": '',
"client_secret": ''
};
var options = {
method: 'POST',
url: 'https://api.atlassian.com/oauth/token',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: {}
};
async function getAccessToken() {
try {
const clientId = core.getInput('client-id');
const clientSecret = core.getInput('client-secret');
bodyData.client_id = clientId;
bodyData.client_secret = clientSecret;
bodyData = JSON.stringify(bodyData);
options.body = bodyData;
// const payload = JSON.stringify(github.context.payload, undefined, 2)
// console.log(`The event payload: ${payload}`);
const response = await request(options);
// console.log("response: ", response);
core.setOutput("access-token", JSON.parse(response).access_token);
} catch (error) {
core.setFailed(error.message);
}
}
(async function () {
await getAccessToken();
console.log("finished retrieving access token");
})();