Skip to content

Commit fe3e59d

Browse files
authored
Run prettier on code (#123)
1 parent 46834bd commit fe3e59d

File tree

108 files changed

+2212
-1898
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+2212
-1898
lines changed

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lib/

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"printWidth": 150,
3+
"singleQuote": true,
4+
"tabWidth": 4
5+
}

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ We welcome pull requests from the community!
6060
* Before creating your first pull request, please join our contributors community by signing [JFrog's CLA](https://secure.echosign.com/public/hostedForm?formid=5IYKLZ2RXB543N).
6161
* Pull requests should be created on the *dev* branch.
6262
* Please make sure the code is covered by tests.
63+
* Please run `npm run format` for formatting the code before submitting the pull request.
6364
6465
# Release Notes
6566
See the release notes [here](https://www.jfrog.com/confluence/display/RTF/Azure+DevOps+and+TFS+Artifactory+Extension#AzureDevOpsandTFSArtifactoryExtension-ReleaseNotes).

artifactory-tasks-utils/package.json

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
2-
"name": "artifactory-tasks-utils",
3-
"version": "1.0.0",
4-
"author": "JFrog",
5-
"license": "Apache-2.0",
6-
"description": "Utilities for the JFrog Artifactory extension",
7-
"main": "utils.js",
8-
"dependencies": {
9-
"azure-pipelines-task-lib": "^2.7.1",
10-
"azure-pipelines-tool-lib": "^0.11.0",
11-
"fs-extra": "^7.0.0",
12-
"typed-rest-client": "1.0.9",
13-
"js-yaml": "^3.13.1"
14-
},
15-
"scripts": {
16-
"test": "echo \"Error: no test specified\" && exit 1"
17-
}
2+
"name": "artifactory-tasks-utils",
3+
"version": "1.0.0",
4+
"author": "JFrog",
5+
"license": "Apache-2.0",
6+
"description": "Utilities for the JFrog Artifactory extension",
7+
"main": "utils.js",
8+
"dependencies": {
9+
"azure-pipelines-task-lib": "^2.7.1",
10+
"azure-pipelines-tool-lib": "^0.11.0",
11+
"fs-extra": "^7.0.0",
12+
"typed-rest-client": "1.0.9",
13+
"js-yaml": "^3.13.1"
14+
},
15+
"scripts": {
16+
"test": "echo \"Error: no test specified\" && exit 1"
17+
}
1818
}

artifactory-tasks-utils/tools.js

+100-77
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,41 @@
22
const fs = require('fs-extra');
33
const tl = require('azure-pipelines-task-lib/task');
44
const path = require('path');
5-
const httpm = require("typed-rest-client/HttpClient");
5+
const httpm = require('typed-rest-client/HttpClient');
66
const uuidV4 = require('uuid/v4');
77

88
module.exports = {
99
downloadTool: downloadTool
1010
};
1111

12-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13-
return new (P || (P = Promise))(function (resolve, reject) {
14-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
15-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16-
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
17-
step((generator = generator.apply(thisArg, _arguments || [])).next());
18-
});
19-
};
12+
var __awaiter =
13+
(this && this.__awaiter) ||
14+
function(thisArg, _arguments, P, generator) {
15+
return new (P || (P = Promise))(function(resolve, reject) {
16+
function fulfilled(value) {
17+
try {
18+
step(generator.next(value));
19+
} catch (e) {
20+
reject(e);
21+
}
22+
}
23+
function rejected(value) {
24+
try {
25+
step(generator['throw'](value));
26+
} catch (e) {
27+
reject(e);
28+
}
29+
}
30+
function step(result) {
31+
result.done
32+
? resolve(result.value)
33+
: new P(function(resolve) {
34+
resolve(result.value);
35+
}).then(fulfilled, rejected);
36+
}
37+
step((generator = generator.apply(thisArg, _arguments || [])).next());
38+
});
39+
};
2040

2141
function _getAgentTemp() {
2242
tl.assertAgent('2.115.0');
@@ -32,74 +52,77 @@ function delay(ms) {
3252
}
3353

3454
function downloadTool(url, fileName, handlers) {
35-
return __awaiter(this, void 0, void 0, function* () {
36-
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
37-
try {
38-
let pkg = require(path.join(__dirname, 'package.json'));
39-
let userAgent = 'vsts-task-installer/' + pkg.version;
40-
let requestOptions = {
41-
// ignoreSslError: true,
42-
proxy: tl.getHttpProxyConfiguration(),
43-
cert: tl.getHttpCertConfiguration()
44-
};
45-
let http = new httpm.HttpClient(userAgent, handlers, requestOptions);
46-
tl.debug(fileName);
47-
fileName = fileName || uuidV4();
48-
// check if it's an absolute path already
49-
var destPath;
50-
if (path.isAbsolute(fileName)) {
51-
destPath = fileName;
52-
}
53-
else {
54-
destPath = path.join(_getAgentTemp(), fileName);
55-
}
56-
// make sure that the folder exists
57-
tl.mkdirP(path.dirname(destPath));
58-
console.log(tl.loc('TOOL_LIB_Downloading', url));
59-
tl.debug('destination ' + destPath);
60-
if (fs.existsSync(destPath)) {
61-
throw new Error("Destination file path already exists");
62-
}
63-
tl.debug('downloading');
64-
const statusCodesToRetry = [httpm.HttpCodes.BadGateway, httpm.HttpCodes.ServiceUnavailable, httpm.HttpCodes.GatewayTimeout];
65-
let retryCount = 1;
66-
const maxRetries = 3;
67-
let response = yield http.get(url);
68-
while (retryCount < maxRetries && statusCodesToRetry.indexOf(response.message.statusCode) > -1) {
69-
tl.debug(`Download attempt "${retryCount}" of "${maxRetries}" failed with status code "${response.message.statusCode}".`);
70-
retryCount += 1;
71-
yield delay(1000);
72-
tl.debug(`Downloading attempt "${retryCount}" of "${maxRetries}"`);
73-
response = yield http.get(url);
74-
}
75-
if (response.message.statusCode !== 200) {
76-
let err = new Error('Unexpected HTTP response: ' + response.message.statusCode);
77-
err['httpStatusCode'] = response.message.statusCode;
78-
tl.debug(`Failed to download "${fileName}" from "${url}". Code(${response.message.statusCode}) Message(${response.message.statusMessage})`);
79-
throw err;
80-
}
81-
tl.debug('creating stream');
82-
let file = fs.createWriteStream(destPath);
83-
file.on('open', (fd) => __awaiter(this, void 0, void 0, function* () {
84-
try {
85-
let stream = response.message.pipe(file);
86-
stream.on('close', () => {
87-
tl.debug('download complete');
88-
resolve(destPath);
89-
});
55+
return __awaiter(this, void 0, void 0, function*() {
56+
return new Promise((resolve, reject) =>
57+
__awaiter(this, void 0, void 0, function*() {
58+
try {
59+
let pkg = require(path.join(__dirname, 'package.json'));
60+
let userAgent = 'vsts-task-installer/' + pkg.version;
61+
let requestOptions = {
62+
// ignoreSslError: true,
63+
proxy: tl.getHttpProxyConfiguration(),
64+
cert: tl.getHttpCertConfiguration()
65+
};
66+
let http = new httpm.HttpClient(userAgent, handlers, requestOptions);
67+
tl.debug(fileName);
68+
fileName = fileName || uuidV4();
69+
// check if it's an absolute path already
70+
var destPath;
71+
if (path.isAbsolute(fileName)) {
72+
destPath = fileName;
73+
} else {
74+
destPath = path.join(_getAgentTemp(), fileName);
9075
}
91-
catch (err) {
92-
reject(err);
76+
// make sure that the folder exists
77+
tl.mkdirP(path.dirname(destPath));
78+
console.log(tl.loc('TOOL_LIB_Downloading', url));
79+
tl.debug('destination ' + destPath);
80+
if (fs.existsSync(destPath)) {
81+
throw new Error('Destination file path already exists');
9382
}
94-
}));
95-
file.on('error', (err) => {
96-
file.end();
97-
reject(err);
98-
});
99-
}
100-
catch (error) {
101-
reject(error);
102-
}
103-
}));
83+
tl.debug('downloading');
84+
const statusCodesToRetry = [httpm.HttpCodes.BadGateway, httpm.HttpCodes.ServiceUnavailable, httpm.HttpCodes.GatewayTimeout];
85+
let retryCount = 1;
86+
const maxRetries = 3;
87+
let response = yield http.get(url);
88+
while (retryCount < maxRetries && statusCodesToRetry.indexOf(response.message.statusCode) > -1) {
89+
tl.debug(`Download attempt "${retryCount}" of "${maxRetries}" failed with status code "${response.message.statusCode}".`);
90+
retryCount += 1;
91+
yield delay(1000);
92+
tl.debug(`Downloading attempt "${retryCount}" of "${maxRetries}"`);
93+
response = yield http.get(url);
94+
}
95+
if (response.message.statusCode !== 200) {
96+
let err = new Error('Unexpected HTTP response: ' + response.message.statusCode);
97+
err['httpStatusCode'] = response.message.statusCode;
98+
tl.debug(
99+
`Failed to download "${fileName}" from "${url}". Code(${response.message.statusCode}) Message(${response.message.statusMessage})`
100+
);
101+
throw err;
102+
}
103+
tl.debug('creating stream');
104+
let file = fs.createWriteStream(destPath);
105+
file.on('open', fd =>
106+
__awaiter(this, void 0, void 0, function*() {
107+
try {
108+
let stream = response.message.pipe(file);
109+
stream.on('close', () => {
110+
tl.debug('download complete');
111+
resolve(destPath);
112+
});
113+
} catch (err) {
114+
reject(err);
115+
}
116+
})
117+
);
118+
file.on('error', err => {
119+
file.end();
120+
reject(err);
121+
});
122+
} catch (error) {
123+
reject(error);
124+
}
125+
})
126+
);
104127
});
105-
}
128+
}

0 commit comments

Comments
 (0)