generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
47 lines (39 loc) · 1.05 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
const core = require('@actions/core');
const axios = require('axios');
const util = require('util');
async function run() {
try {
const userToken = core.getInput('user-token');
const projectSlug = core.getInput('project-slug');
const branch = core.getInput('branch');
const payload = core.getInput('payload');
const jsonObj = JSON.parse(payload)
var requestPayload = {
branch: branch,
parameters: jsonObj
};
let headers = {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
"Circle-Token": userToken,
}
};
let url = util.format(
'https://circleci.com/api/v2/project/gh/%s/pipeline',
projectSlug
);
axios.post(url, requestPayload, headers)
.then((res) => {
console.log("Response: ", res.status);
})
.catch((err) => {
console.log("HTTP Error: ", err);
core.setFailed(err.message);
})
} catch (error) {
console.log("Error: ", error);
core.setFailed(error.message);
}
}
run();