-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
71 lines (65 loc) · 3.4 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
'use strict';
const core = require('@actions/core');
const { createOrUpdateDiscoveredApi } = require('./discovery-client');
// most @actions toolkit packages have async methods
async function run() {
try {
let isFolder = false;
const githubServer = new URL(process.env['GITHUB_SERVER_URL']).hostname;
const repoLocation = process.env['GITHUB_REPOSITORY'];
const workspacePath = process.env['GITHUB_WORKSPACE'];
const apihost = core.getInput('api_host');
const apikey = core.getInput('api_key');
const porg = core.getInput('provider_org');
const datasourceCheck = core.getInput('resync_check');
const apisLocation = core.getInput('api_files') || core.getInput('api_folders');
const filesChanged = core.getInput('git_diff');
const platformApiPrefix = core.getInput('platform_api_prefix') ? core.getInput('platform_api_prefix') : 'platform-api';
const nodeTlsRejectUnauthorized = (core.getInput('insecure_skip_tls_verify').toLowerCase() === 'true');
if (core.getInput('api_files')) {
isFolder = false;
} else if (core.getInput('api_folders')) {
isFolder = true;
}
if (filesChanged.trim() && apisLocation) {
let checkChanges = false;
let filesArray = filesChanged.split(' ');
let apisLocationArray = apisLocation.split(',');
if (isFolder) {
for (let name of apisLocationArray) {
checkChanges = filesArray.find(file => file.includes(name.trim())) || checkChanges;
}
} else {
for (let name of apisLocationArray) {
checkChanges = filesArray.includes(name.trim()) || checkChanges;
}
}
if (checkChanges) {
await execution(apihost, platformApiPrefix, porg, isFolder, apisLocation, datasourceCheck, workspacePath, apikey, githubServer, repoLocation, nodeTlsRejectUnauthorized);
} else {
core.setOutput('action-result', 'No files changed from the previous commit to send to Discovery Service');
}
} else {
await execution(apihost, platformApiPrefix, porg, isFolder, apisLocation, datasourceCheck, workspacePath, apikey, githubServer, repoLocation, nodeTlsRejectUnauthorized);
}
} catch (error) {
core.setFailed(error.message);
}
}
async function execution(apihost, platformApiPrefix, porg, isFolder, apisLocation, datasourceCheck, workspacePath, apikey, githubServer, repoLocation, nodeTlsRejectUnauthorized) {
try {
core.info(`apihost ${apihost}`);
core.info(`porg ${porg}`);
isFolder && core.info(`apifolders ${apisLocation}`) || core.info(`apifiles ${apisLocation}`);
core.info(`datasourceCheck ${datasourceCheck}`);
var resp = await createOrUpdateDiscoveredApi(workspacePath, apihost, platformApiPrefix, apikey, porg, apisLocation, githubServer + '/' + repoLocation, datasourceCheck, isFolder, nodeTlsRejectUnauthorized);
core.info(`response: status: ${resp.status}, message: ${resp.message[0]}`);
core.setOutput('action-result', `response: status: ${resp.status}, message: ${resp.message[0]}`);
if (![ 200, 201, 304 ].includes(resp.status)) {
core.setFailed(resp.message[0]);
}
} catch (error) {
core.setFailed(error.message);
}
}
run();