Skip to content

Commit fd1343c

Browse files
author
Alexis Pierru
committed
Recompile main.js
1 parent e25aecb commit fd1343c

1 file changed

Lines changed: 39 additions & 26 deletions

File tree

main.js

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
99
});
1010
};
1111
var __generator = (this && this.__generator) || function (thisArg, body) {
12-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
1414
function verb(n) { return function (v) { return step([n, v]); }; }
1515
function step(op) {
1616
if (f) throw new TypeError("Generator is already executing.");
17-
while (_) try {
17+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
1818
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1919
if (y = 0, t) op = [op[0] & 2, t.value];
2020
switch (op[0]) {
@@ -35,7 +35,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
3535
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
3636
}
3737
};
38-
exports.__esModule = true;
38+
Object.defineProperty(exports, "__esModule", { value: true });
3939
var core = require("@actions/core");
4040
var fetch = require("node-fetch");
4141
var glob = require("glob");
@@ -44,15 +44,32 @@ var fs = require("fs");
4444
// Global constants
4545
var maxUploadFiles = 3; // no more than 3 files can be uploaded at a time
4646
var maxRetries = 3; // max number of uploads to retry
47+
function upload_step_init(dt_upload_api_key) {
48+
return __awaiter(this, void 0, void 0, function () {
49+
return __generator(this, function (_a) {
50+
switch (_a.label) {
51+
case 0: return [4 /*yield*/, fetch("https://api.securetheorem.com/uploadapi/v1/upload_init", {
52+
"headers": {
53+
"Accept": "application/json",
54+
"Authorization": "APIKey " + dt_upload_api_key,
55+
"Content-Type": "application/json",
56+
},
57+
"method": "POST",
58+
})];
59+
case 1: return [2 /*return*/, _a.sent()];
60+
}
61+
});
62+
});
63+
}
4764
function run() {
4865
return __awaiter(this, void 0, void 0, function () {
49-
var dt_upload_api_key, input_binary_path, username, password, comments, release_id, platform_variant, external_id, files, file_idx, output, _i, files_1, file_path, form, loop_idx, auth_response, auth_json, err_1, response, jsonformat, err_2, err_3;
66+
var dt_upload_api_key, input_binary_path, sourcemap_file_path, username, password, comments, release_id, platform_variant, external_id, files, file_idx, output, _i, files_1, file_path, form, loop_idx, auth_response, auth_json, err_1, response, jsonformat, err_2;
5067
return __generator(this, function (_a) {
5168
switch (_a.label) {
5269
case 0:
53-
_a.trys.push([0, 16, , 17]);
5470
dt_upload_api_key = core.getInput("DT_UPLOAD_API_KEY");
5571
input_binary_path = core.getInput("UPLOAD_BINARY_PATH");
72+
sourcemap_file_path = core.getInput("SOURCEMAP_FILE_PATH");
5673
username = core.getInput("USERNAME");
5774
password = core.getInput("PASSWORD");
5875
comments = core.getInput("COMMENTS");
@@ -90,7 +107,10 @@ function run() {
90107
console.log("Processing file " + file_path + " (" + file_idx + " of " + files.length + ").");
91108
form = new FormData();
92109
form.append("file", fs.createReadStream(file_path));
93-
// only append optional fields if explicitly set
110+
if (sourcemap_file_path) {
111+
form.append("sourcemap", fs.createReadStream(sourcemap_file_path));
112+
}
113+
// only append optional fields if explicitly set
94114
if (username) {
95115
form.append("username", username);
96116
console.log("DAST username set to: " + username);
@@ -119,14 +139,7 @@ function run() {
119139
_a.label = 2;
120140
case 2:
121141
if (!(loop_idx < maxRetries)) return [3 /*break*/, 14];
122-
return [4 /*yield*/, fetch("https://api.securetheorem.com/uploadapi/v1/upload_init", {
123-
method: "POST",
124-
headers: {
125-
Authorization: "APIKey " + dt_upload_api_key,
126-
Accept: "application/json",
127-
"Content-Type": "application/json"
128-
}
129-
})];
142+
return [4 /*yield*/, upload_step_init(dt_upload_api_key)];
130143
case 3:
131144
auth_response = _a.sent();
132145
auth_json = void 0;
@@ -150,8 +163,8 @@ function run() {
150163
// Send the scan request with file
151164
console.log("Starting upload...");
152165
return [4 /*yield*/, fetch(auth_json.upload_url, {
153-
method: "POST",
154-
body: form
166+
"method": "POST",
167+
"body": form,
155168
})];
156169
case 8:
157170
response = _a.sent();
@@ -170,10 +183,10 @@ function run() {
170183
return [3 /*break*/, 12];
171184
case 12:
172185
output.push(jsonformat);
173-
console.log("Response: HHTP/" + response.status);
186+
console.log("Response: HTTP/" + response.status);
174187
console.log(jsonformat);
175188
// Check the response
176-
// If we receive 409 (ownership conflict) or if this is the last try, bail out
189+
// If we receive 409 (ownership conflict) or if this is the last try, bail out
177190
if (response.status === 200) {
178191
return [3 /*break*/, 14];
179192
}
@@ -194,14 +207,14 @@ function run() {
194207
case 15:
195208
core.setOutput("responses", output);
196209
core.setOutput("response", output[0]); // keep the `response` output as the response of the first file upload to maintain compatibility
197-
return [3 /*break*/, 17];
198-
case 16:
199-
err_3 = _a.sent();
200-
core.setFailed(err_3.message);
201-
return [3 /*break*/, 17];
202-
case 17: return [2 /*return*/];
210+
return [2 /*return*/];
203211
}
204212
});
205213
});
206214
}
207-
run();
215+
try {
216+
run();
217+
}
218+
catch (err) {
219+
core.setFailed(err.message);
220+
}

0 commit comments

Comments
 (0)