forked from baratrion/sleuth-action
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
40 lines (32 loc) · 1.16 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
const core = require('@actions/core');
const httpm = require('@actions/http-client');
async function main() {
try {
const organizationSlug = core.getInput('organization-slug');
const deploymentSlug = core.getInput('deployment-slug');
const environment = core.getInput('environment');
const email = core.getInput('email');
const apiKey = core.getInput('api-key');
const sha = core.getInput('sha');
const requestUrl = `https://app.sleuth.io/api/1/deployments/${organizationSlug}/${deploymentSlug}/register_deploy`;
core.info(`Sleuth API URL ${requestUrl}`);
const data = {
api_key: apiKey,
sha,
environment,
email,
};
Object.entries(data).forEach(([name, value]) => {
core.info(`> Sleuth API request payload ${name}: ${value}`);
});
const http = new httpm.HttpClient();
const response = await http.postJson(requestUrl, data);
core.setOutput('status', response.statusCode);
if (response.statusCode !== httpm.HttpCodes.OK) {
throw new httpm.HttpClientError('Failed to ping Sleuth', response.statusCode);
}
} catch (error) {
core.setFailed(error.message);
}
}
main();