-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
92 lines (75 loc) · 2.17 KB
/
Copy pathindex.js
File metadata and controls
92 lines (75 loc) · 2.17 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
79
80
81
82
83
84
85
86
87
88
89
90
91
function escapeTeamCityString(message) {
if (message === null) {
return '';
}
return message
.replace(/\|/g, '||')
.replace(/'/g, '|\'')
.replace(/\n/g, '|n')
.replace(/\r/g, '|r')
.replace(/\u0085/g, '|x')
.replace(/\u2028/g, '|l')
.replace(/\u2029/g, '|p')
.replace(/\[/g, '|[')
.replace(/\]/g, '|]');
}
function prepareResults(results) {
if ((results === null) || !(results.length > 0)) {
return [];
}
return results.map(error => {
const errorDetails = Object.keys(error).reduce((msg, key) => {
if (['context', 'line', 'lineNumber'].indexOf(key) === -1) {
return msg;
}
msg += `\n${key}: ${error[key]}`;
return msg;
}
, '');
return {
name: `${error.name}: line ${error.lineNumber}`,
message: error.message,
detailed: `Message: ${error.message}\nDescription: ${error.description}${errorDetails}`
};
});
}
class TeamCityReporter {
constructor(errorReport, options) {
this.errorReport = errorReport;
if (options === null) {
options = {};
}
}
publish() {
this.print('progressStart \'Running CoffeeLint\'');
for (const filename in this.errorReport.paths) {
if ({}.hasOwnProperty.call(this.errorReport.paths, filename)) {
const results = this.errorReport.paths[filename];
this.reportPath(filename, results);
}
}
return this.print('progressFinish \'Running CoffeeLint\'');
}
reportPath(path, results) {
const errors = prepareResults(results);
const suite = `CoffeeLint: ${path}`;
this.print('testSuiteStarted',
{name: suite});
for (const error of [...errors]) {
this.print('testStarted', {name: error.name});
this.print('testFailed', error);
this.print('testFinished', {name: error.name});
}
return this.print('testSuiteFinished',
{name: suite});
}
print(message, attrs) {
let log = message;
if (typeof attrs === 'object') {
log = Object.keys(attrs).reduce((l, key) => l + ' ' + key + '=\'' + escapeTeamCityString(attrs[key]) + '\''
, log);
}
return console.log(`##teamcity[${log}]`);
}
}
module.exports = TeamCityReporter;