-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathbuild.js
More file actions
78 lines (72 loc) · 2.36 KB
/
build.js
File metadata and controls
78 lines (72 loc) · 2.36 KB
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
72
73
74
75
76
77
78
'use strict';
const axios = require('axios').default;
const config = require('./config'),
capabilityHelper = require("../helpers/capabilityHelper"),
Constants = require('../helpers/constants'),
utils = require('../helpers/utils'),
logger = require('../helpers/logger').winstonLogger;
const { setAxiosProxy } = require('./helper');
const createBuild = (bsConfig, zip) => {
return new Promise(function (resolve, reject) {
capabilityHelper.caps(bsConfig, zip).then(async function(data){
let options = {
url: config.buildUrl,
auth: {
user: bsConfig.auth.username,
password: bsConfig.auth.access_key
},
headers: {
'Content-Type': 'application/json',
"User-Agent": utils.getUserAgent(),
},
body: data
}
if (Constants.turboScaleObj.enabled) {
options.url = Constants.turboScaleObj.buildUrl;
}
const axiosConfig = {
auth: {
username: options.auth.user,
password: options.auth.password
},
headers: options.headers
}
setAxiosProxy(axiosConfig);
try {
const response = await axios.post(options.url, data, axiosConfig);
let build = null;
try {
build = response.data;
} catch (error) {
build = null;
}
if (response.status == 299) {
if (build) {
resolve(build.message);
} else {
logger.error(utils.formatRequest(response.statusText, response, response.data));
reject(Constants.userMessages.API_DEPRECATED);
}
} else if (response.status != 201) {
logger.error(utils.formatRequest(response.statusText, response, response.data));
if (build) {
reject(`${Constants.userMessages.BUILD_FAILED} Error: ${build.message}`);
} else {
reject(Constants.userMessages.BUILD_FAILED);
}
}
resolve(build);
} catch (error) {
if(error.response) {
logger.error(utils.formatRequest(error.response.statusText, error.response, error.response.data));
reject(`${Constants.userMessages.BUILD_FAILED} Error: ${error.response.data.message}`);
} else {
reject(error);
}
}
}).catch(function(err){
reject(err);
});
});
}
exports.createBuild = createBuild