@testomatio/reporter 2.0.1-beta.3 → 2.0.1-beta.5-timestamp
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/adapter/codecept.js +335 -293
- package/lib/adapter/cucumber/current.js +203 -195
- package/lib/adapter/cucumber/legacy.js +155 -130
- package/lib/adapter/cucumber.js +16 -5
- package/lib/adapter/cypress-plugin/index.js +105 -91
- package/lib/adapter/jasmine.js +53 -54
- package/lib/adapter/jest.js +99 -97
- package/lib/adapter/mocha.js +141 -112
- package/lib/adapter/playwright.js +231 -199
- package/lib/adapter/vitest.js +149 -150
- package/lib/adapter/webdriver.js +121 -144
- package/lib/bin/cli.js +211 -229
- package/lib/bin/reportXml.js +52 -51
- package/lib/bin/startTest.js +95 -83
- package/lib/bin/uploadArtifacts.js +61 -56
- package/lib/client.js +465 -424
- package/lib/config.js +23 -18
- package/lib/constants.js +44 -50
- package/lib/data-storage.js +188 -216
- package/lib/junit-adapter/adapter.js +20 -17
- package/lib/junit-adapter/csharp.js +14 -28
- package/lib/junit-adapter/index.js +25 -27
- package/lib/junit-adapter/java.js +53 -41
- package/lib/junit-adapter/javascript.js +27 -30
- package/lib/junit-adapter/python.js +37 -38
- package/lib/junit-adapter/ruby.js +8 -11
- package/lib/output.js +52 -44
- package/lib/pipe/bitbucket.js +230 -223
- package/lib/pipe/csv.js +126 -113
- package/lib/pipe/debug.js +99 -118
- package/lib/pipe/github.js +213 -218
- package/lib/pipe/gitlab.js +206 -183
- package/lib/pipe/html.js +321 -258
- package/lib/pipe/index.js +66 -94
- package/lib/pipe/testomatio.js +474 -429
- package/lib/reporter-functions.js +26 -28
- package/lib/reporter.js +29 -34
- package/lib/services/artifacts.js +51 -55
- package/lib/services/index.js +12 -14
- package/lib/services/key-values.js +53 -56
- package/lib/services/logger.js +245 -226
- package/lib/template/testomatio.hbs +1366 -1026
- package/lib/uploader.js +364 -295
- package/lib/utils/pipe_utils.js +85 -89
- package/lib/utils/utils.js +307 -398
- package/lib/xmlReader.js +532 -525
- package/package.json +21 -64
- package/lib/adapter/codecept.d.ts +0 -2
- package/lib/adapter/cucumber/current.d.ts +0 -14
- package/lib/adapter/cucumber/legacy.d.ts +0 -0
- package/lib/adapter/cucumber.d.ts +0 -2
- package/lib/adapter/cypress-plugin/index.d.ts +0 -2
- package/lib/adapter/jasmine.d.ts +0 -11
- package/lib/adapter/jest.d.ts +0 -13
- package/lib/adapter/mocha.d.ts +0 -2
- package/lib/adapter/nightwatch.d.ts +0 -4
- package/lib/adapter/nightwatch.js +0 -80
- package/lib/adapter/playwright.d.ts +0 -14
- package/lib/adapter/vitest.d.ts +0 -35
- package/lib/adapter/webdriver.d.ts +0 -24
- package/lib/bin/cli.d.ts +0 -2
- package/lib/bin/reportXml.d.ts +0 -2
- package/lib/bin/startTest.d.ts +0 -2
- package/lib/bin/uploadArtifacts.d.ts +0 -2
- package/lib/client.d.ts +0 -76
- package/lib/config.d.ts +0 -1
- package/lib/constants.d.ts +0 -25
- package/lib/data-storage.d.ts +0 -34
- package/lib/junit-adapter/adapter.d.ts +0 -9
- package/lib/junit-adapter/csharp.d.ts +0 -5
- package/lib/junit-adapter/index.d.ts +0 -3
- package/lib/junit-adapter/java.d.ts +0 -5
- package/lib/junit-adapter/javascript.d.ts +0 -4
- package/lib/junit-adapter/python.d.ts +0 -5
- package/lib/junit-adapter/ruby.d.ts +0 -4
- package/lib/output.d.ts +0 -11
- package/lib/package.json +0 -3
- package/lib/pipe/bitbucket.d.ts +0 -25
- package/lib/pipe/csv.d.ts +0 -47
- package/lib/pipe/debug.d.ts +0 -29
- package/lib/pipe/github.d.ts +0 -30
- package/lib/pipe/gitlab.d.ts +0 -25
- package/lib/pipe/html.d.ts +0 -35
- package/lib/pipe/index.d.ts +0 -1
- package/lib/pipe/testomatio.d.ts +0 -71
- package/lib/replay.d.ts +0 -31
- package/lib/replay.js +0 -237
- package/lib/reporter-functions.d.ts +0 -34
- package/lib/reporter.d.ts +0 -232
- package/lib/services/artifacts.d.ts +0 -33
- package/lib/services/index.d.ts +0 -9
- package/lib/services/key-values.d.ts +0 -27
- package/lib/services/logger.d.ts +0 -64
- package/lib/uploader.d.ts +0 -60
- package/lib/utils/pipe_utils.d.ts +0 -41
- package/lib/utils/utils.d.ts +0 -54
- package/lib/xmlReader.d.ts +0 -92
- package/src/adapter/codecept.js +0 -373
- package/src/adapter/cucumber/current.js +0 -228
- package/src/adapter/cucumber/legacy.js +0 -158
- package/src/adapter/cucumber.js +0 -4
- package/src/adapter/cypress-plugin/index.js +0 -110
- package/src/adapter/jasmine.js +0 -60
- package/src/adapter/jest.js +0 -107
- package/src/adapter/mocha.cjs +0 -2
- package/src/adapter/mocha.js +0 -156
- package/src/adapter/nightwatch.js +0 -88
- package/src/adapter/playwright.js +0 -254
- package/src/adapter/vitest.js +0 -183
- package/src/adapter/webdriver.js +0 -142
- package/src/bin/cli.js +0 -348
- package/src/bin/reportXml.js +0 -77
- package/src/bin/startTest.js +0 -124
- package/src/bin/uploadArtifacts.js +0 -91
- package/src/client.js +0 -508
- package/src/config.js +0 -30
- package/src/constants.js +0 -53
- package/src/data-storage.js +0 -204
- package/src/junit-adapter/adapter.js +0 -23
- package/src/junit-adapter/csharp.js +0 -28
- package/src/junit-adapter/index.js +0 -28
- package/src/junit-adapter/java.js +0 -58
- package/src/junit-adapter/javascript.js +0 -31
- package/src/junit-adapter/python.js +0 -42
- package/src/junit-adapter/ruby.js +0 -10
- package/src/output.js +0 -57
- package/src/pipe/bitbucket.js +0 -252
- package/src/pipe/csv.js +0 -140
- package/src/pipe/debug.js +0 -119
- package/src/pipe/github.js +0 -232
- package/src/pipe/gitlab.js +0 -247
- package/src/pipe/html.js +0 -373
- package/src/pipe/index.js +0 -71
- package/src/pipe/testomatio.js +0 -504
- package/src/replay.js +0 -245
- package/src/reporter-functions.js +0 -55
- package/src/reporter.cjs_decprecated +0 -21
- package/src/reporter.js +0 -33
- package/src/services/artifacts.js +0 -59
- package/src/services/index.js +0 -13
- package/src/services/key-values.js +0 -59
- package/src/services/logger.js +0 -315
- package/src/template/emptyData.svg +0 -23
- package/src/template/testomatio.hbs +0 -1081
- package/src/uploader.js +0 -376
- package/src/utils/pipe_utils.js +0 -119
- package/src/utils/utils.js +0 -416
- package/src/xmlReader.js +0 -614
package/lib/pipe/gitlab.js
CHANGED
|
@@ -1,204 +1,227 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const path_1 = __importDefault(require("path"));
|
|
12
|
-
const constants_js_1 = require("../constants.js");
|
|
13
|
-
const utils_js_1 = require("../utils/utils.js");
|
|
14
|
-
const pipe_utils_js_1 = require("../utils/pipe_utils.js");
|
|
15
|
-
const debug = (0, debug_1.default)('@testomatio/reporter:pipe:gitlab');
|
|
1
|
+
const debug = require('debug')('@testomatio/reporter:pipe:gitlab');
|
|
2
|
+
const { default: axios } = require('axios');
|
|
3
|
+
const chalk = require('chalk');
|
|
4
|
+
const humanizeDuration = require('humanize-duration');
|
|
5
|
+
const merge = require('lodash.merge');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const { APP_PREFIX, testomatLogoURL } = require('../constants');
|
|
8
|
+
const { ansiRegExp, isSameTest } = require('../utils/utils');
|
|
9
|
+
const { statusEmoji, fullName } = require('../utils/pipe_utils');
|
|
10
|
+
|
|
16
11
|
//! GITLAB_PAT environment variable is required for this functionality to work
|
|
17
12
|
//! and your pipeline trigger should be merge_request
|
|
13
|
+
|
|
18
14
|
/**
|
|
19
15
|
* @class GitLabPipe
|
|
20
|
-
* @typedef {import('../../types
|
|
21
|
-
* @typedef {import('../../types
|
|
16
|
+
* @typedef {import('../../types').Pipe} Pipe
|
|
17
|
+
* @typedef {import('../../types').TestData} TestData
|
|
22
18
|
*/
|
|
23
19
|
class GitLabPipe {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
this.client = new gaxios_1.Gaxios({
|
|
43
|
-
baseURL: 'https://gitlab.com/api/v4',
|
|
44
|
-
headers: {
|
|
45
|
-
'Content-Type': 'application/json',
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
debug('GitLab Pipe: Enabled');
|
|
20
|
+
constructor(params, store = {}) {
|
|
21
|
+
this.isEnabled = false;
|
|
22
|
+
this.ENV = process.env;
|
|
23
|
+
this.store = store;
|
|
24
|
+
this.tests = [];
|
|
25
|
+
// GitLab PAT looks like glpat-nKGdja3jsG4850sGksh7
|
|
26
|
+
this.token = params.GITLAB_PAT || process.env.GITLAB_PAT || this.ENV.GITLAB_PAT;
|
|
27
|
+
this.hiddenCommentData = `<!--- testomat.io report ${process.env.CI_JOB_NAME || ''} -->`;
|
|
28
|
+
|
|
29
|
+
debug(
|
|
30
|
+
chalk.yellow('GitLab Pipe:'),
|
|
31
|
+
this.token ? 'TOKEN passed' : '*no token*',
|
|
32
|
+
`Project id: ${this.ENV.CI_PROJECT_ID}, MR id: ${this.ENV.CI_MERGE_REQUEST_IID}`,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
if (!this.ENV.CI_PROJECT_ID || !this.ENV.CI_MERGE_REQUEST_IID) {
|
|
36
|
+
debug(`CI pipeline should be run in Merge Request to have ability to add the report comment.`);
|
|
37
|
+
return;
|
|
49
38
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
39
|
+
|
|
40
|
+
if (!this.token) {
|
|
41
|
+
debug(`Hint: GitLab CI variables are unavailable for unprotected branches by default.`);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
this.isEnabled = true;
|
|
46
|
+
|
|
47
|
+
debug('GitLab Pipe: Enabled');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// TODO: to using SET opts as argument => prepareRun(opts)
|
|
51
|
+
async prepareRun() {}
|
|
52
|
+
|
|
53
|
+
async createRun() {}
|
|
54
|
+
|
|
55
|
+
addTest(test) {
|
|
56
|
+
if (!this.isEnabled) return;
|
|
57
|
+
|
|
58
|
+
const index = this.tests.findIndex(t => isSameTest(t, test));
|
|
59
|
+
// update if they were already added
|
|
60
|
+
if (index >= 0) {
|
|
61
|
+
this.tests[index] = merge(this.tests[index], test);
|
|
62
|
+
return;
|
|
63
63
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
64
|
+
|
|
65
|
+
this.tests.push(test);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async finishRun(runParams) {
|
|
69
|
+
if (!this.isEnabled) return;
|
|
70
|
+
|
|
71
|
+
if (runParams.tests) runParams.tests.forEach(t => this.addTest(t));
|
|
72
|
+
|
|
73
|
+
// ... create a comment on GitLab
|
|
74
|
+
const passedCount = this.tests.filter(t => t.status === 'passed').length;
|
|
75
|
+
const failedCount = this.tests.filter(t => t.status === 'failed').length;
|
|
76
|
+
const skippedCount = this.tests.filter(t => t.status === 'skipped').length;
|
|
77
|
+
|
|
78
|
+
// constructing the table
|
|
79
|
+
let summary = `${this.hiddenCommentData}
|
|
75
80
|
|
|
76
|
-
| [](https://testomat.io) | ${statusEmoji(
|
|
82
|
+
runParams.status,
|
|
83
|
+
)} ${runParams.status.toUpperCase()} ${statusEmoji(runParams.status)} |
|
|
77
84
|
| --- | --- |
|
|
78
85
|
| Tests | ✔️ **${this.tests.length}** tests run |
|
|
79
|
-
| Summary | ${
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
86
|
+
| Summary | ${statusEmoji('failed')} **${failedCount}** failed; ${statusEmoji(
|
|
87
|
+
'passed',
|
|
88
|
+
)} **${passedCount}** passed; **${statusEmoji('skipped')}** ${skippedCount} skipped |
|
|
89
|
+
| Duration | 🕐 **${humanizeDuration(
|
|
90
|
+
parseInt(
|
|
91
|
+
this.tests.reduce((a, t) => a + (t.run_time || 0), 0),
|
|
92
|
+
10,
|
|
93
|
+
),
|
|
94
|
+
{
|
|
95
|
+
maxDecimalPoints: 0,
|
|
96
|
+
},
|
|
97
|
+
)}** |
|
|
83
98
|
`;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
text += '\n---\n';
|
|
115
|
-
return text;
|
|
116
|
-
});
|
|
117
|
-
let body = summary;
|
|
118
|
-
if (failures.length) {
|
|
119
|
-
body += `\n<details>\n<summary><h3>🟥 Failures (${failures.length})</h4></summary>\n\n${failures.join('\n')}\n`;
|
|
120
|
-
if (failures.length > 20) {
|
|
121
|
-
body += '\n> Notice\n> Only first 20 failures shown*';
|
|
122
|
-
}
|
|
123
|
-
body += '\n\n</details>';
|
|
124
|
-
}
|
|
125
|
-
if (this.tests.length > 0) {
|
|
126
|
-
body += '\n<details>\n<summary><h3>🐢 Slowest Tests</h3></summary>\n\n';
|
|
127
|
-
body += this.tests
|
|
128
|
-
.sort((a, b) => b?.run_time - a?.run_time)
|
|
129
|
-
.slice(0, 5)
|
|
130
|
-
.map(t => `* ${(0, pipe_utils_js_1.fullName)(t)} (${(0, humanize_duration_1.default)(parseFloat(t.run_time))})`)
|
|
131
|
-
.join('\n');
|
|
132
|
-
body += '\n</details>';
|
|
133
|
-
}
|
|
134
|
-
// eslint-disable-next-line max-len
|
|
135
|
-
const commentsRequestURL = `/projects/${this.ENV.CI_PROJECT_ID}/merge_requests/${this.ENV.CI_MERGE_REQUEST_IID}/notes`;
|
|
136
|
-
// delete previous report
|
|
137
|
-
await deletePreviousReport(this.client, commentsRequestURL, this.hiddenCommentData, this.token);
|
|
138
|
-
// add current report
|
|
139
|
-
debug(`Adding comment via url: ${commentsRequestURL}`);
|
|
140
|
-
try {
|
|
141
|
-
const addCommentResponse = await this.client.request({
|
|
142
|
-
method: 'POST',
|
|
143
|
-
url: commentsRequestURL,
|
|
144
|
-
params: { access_token: this.token },
|
|
145
|
-
data: { body }
|
|
99
|
+
|
|
100
|
+
if (this.ENV.CI_JOB_NAME && this.ENV.CI_JOB_ID) {
|
|
101
|
+
// eslint-disable-next-line max-len
|
|
102
|
+
summary += `| Job | 👷 [${this.ENV.CI_JOB_ID}](${this.ENV.CI_JOB_URL})<br>Name: **${this.ENV.CI_JOB_NAME}**<br>Stage: **${this.ENV.CI_JOB_STAGE}** | `;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const failures = this.tests
|
|
106
|
+
.filter(t => t.status === 'failed')
|
|
107
|
+
.slice(0, 20)
|
|
108
|
+
.map(t => {
|
|
109
|
+
let text = `#### ${statusEmoji('failed')} ${fullName(t)} `;
|
|
110
|
+
text += '\n\n';
|
|
111
|
+
if (t.message)
|
|
112
|
+
text += `> ${t.message
|
|
113
|
+
.replace(/[^\x20-\x7E]/g, '')
|
|
114
|
+
.replace(ansiRegExp(), '')
|
|
115
|
+
.trim()}\n`;
|
|
116
|
+
if (t.stack) text += `\`\`\`diff\n${t.stack.replace(ansiRegExp(), '').trim()}\n\`\`\`\n`;
|
|
117
|
+
|
|
118
|
+
if (t.artifacts && t.artifacts.length && !this.ENV.TESTOMATIO_PRIVATE_ARTIFACTS) {
|
|
119
|
+
t.artifacts
|
|
120
|
+
.filter(f => !!f)
|
|
121
|
+
.filter(f => f.endsWith('.png'))
|
|
122
|
+
.forEach(f => {
|
|
123
|
+
if (f.endsWith('.png')) {
|
|
124
|
+
text += `\n`;
|
|
125
|
+
return text;
|
|
126
|
+
}
|
|
127
|
+
text += `[📄 ${path.basename(f)}](${f})\n`;
|
|
128
|
+
return text;
|
|
146
129
|
});
|
|
147
|
-
const commentID = addCommentResponse.data.id;
|
|
148
|
-
// eslint-disable-next-line max-len
|
|
149
|
-
const commentURL = `${this.ENV.CI_PROJECT_URL}/-/merge_requests/${this.ENV.CI_MERGE_REQUEST_IID}#note_${commentID}`;
|
|
150
|
-
console.log(constants_js_1.APP_PREFIX, picocolors_1.default.yellow('GitLab'), `Report created: ${picocolors_1.default.magenta(commentURL)}`);
|
|
151
|
-
}
|
|
152
|
-
catch (err) {
|
|
153
|
-
console.error(constants_js_1.APP_PREFIX, picocolors_1.default.yellow('GitLab'), `Couldn't create GitLab report\n${err}.
|
|
154
|
-
Request url: ${commentsRequestURL}
|
|
155
|
-
Request data: ${body}`);
|
|
156
130
|
}
|
|
131
|
+
|
|
132
|
+
text += '\n---\n';
|
|
133
|
+
|
|
134
|
+
return text;
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
let body = summary;
|
|
138
|
+
|
|
139
|
+
if (failures.length) {
|
|
140
|
+
body += `\n<details>\n<summary><h3>🟥 Failures (${failures.length})</h4></summary>\n\n${failures.join('\n')}\n`;
|
|
141
|
+
if (failures.length > 20) {
|
|
142
|
+
body += '\n> Notice\n> Only first 20 failures shown*';
|
|
143
|
+
}
|
|
144
|
+
body += '\n\n</details>';
|
|
157
145
|
}
|
|
158
|
-
|
|
159
|
-
|
|
146
|
+
|
|
147
|
+
if (this.tests.length > 0) {
|
|
148
|
+
body += '\n<details>\n<summary><h3>🐢 Slowest Tests</h3></summary>\n\n';
|
|
149
|
+
body += this.tests
|
|
150
|
+
// eslint-disable-next-line no-unsafe-optional-chaining
|
|
151
|
+
.sort((a, b) => b?.run_time - a?.run_time)
|
|
152
|
+
.slice(0, 5)
|
|
153
|
+
.map(t => `* ${fullName(t)} (${humanizeDuration(parseFloat(t.run_time))})`)
|
|
154
|
+
.join('\n');
|
|
155
|
+
body += '\n</details>';
|
|
160
156
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
157
|
+
|
|
158
|
+
// eslint-disable-next-line max-len
|
|
159
|
+
const commentsRequestURL = `https://gitlab.com/api/v4/projects/${this.ENV.CI_PROJECT_ID}/merge_requests/${this.ENV.CI_MERGE_REQUEST_IID}/notes`;
|
|
160
|
+
|
|
161
|
+
// delete previous report
|
|
162
|
+
await deletePreviousReport(axios, commentsRequestURL, this.hiddenCommentData, this.token);
|
|
163
|
+
|
|
164
|
+
// add current report
|
|
165
|
+
debug(`Adding comment via url: ${commentsRequestURL}`);
|
|
166
|
+
|
|
168
167
|
try {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
catch (
|
|
177
|
-
|
|
168
|
+
const addCommentResponse = await axios.post(`${commentsRequestURL}?access_token=${this.token}`, { body });
|
|
169
|
+
|
|
170
|
+
const commentID = addCommentResponse.data.id;
|
|
171
|
+
// eslint-disable-next-line max-len
|
|
172
|
+
const commentURL = `${this.ENV.CI_PROJECT_URL}/-/merge_requests/${this.ENV.CI_MERGE_REQUEST_IID}#note_${commentID}`;
|
|
173
|
+
|
|
174
|
+
console.log(APP_PREFIX, chalk.yellow('GitLab'), `Report created: ${chalk.magenta(commentURL)}`);
|
|
175
|
+
} catch (err) {
|
|
176
|
+
console.error(
|
|
177
|
+
APP_PREFIX,
|
|
178
|
+
chalk.yellow('GitLab'),
|
|
179
|
+
`Couldn't create GitLab report\n${err}.
|
|
180
|
+
Request url: ${commentsRequestURL}
|
|
181
|
+
Request data: ${body}`,
|
|
182
|
+
);
|
|
178
183
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
toString() {
|
|
187
|
+
return 'GitLab Reporter';
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
updateRun() {}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async function deletePreviousReport(axiosInstance, commentsRequestURL, hiddenCommentData, token) {
|
|
194
|
+
if (process.env.GITLAB_KEEP_OUTDATED_REPORTS) return;
|
|
195
|
+
|
|
196
|
+
// get comments
|
|
197
|
+
let comments = [];
|
|
198
|
+
|
|
199
|
+
try {
|
|
200
|
+
const response = await axiosInstance.get(`${commentsRequestURL}?access_token=${token}`);
|
|
201
|
+
comments = response.data;
|
|
202
|
+
} catch (e) {
|
|
203
|
+
console.error('Error while attempt to retrieve comments on GitLab Merge Request:\n', e);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (!comments.length) return;
|
|
207
|
+
|
|
208
|
+
for (const comment of comments) {
|
|
209
|
+
// if comment was left by the same workflow
|
|
210
|
+
if (comment.body.includes(hiddenCommentData)) {
|
|
211
|
+
try {
|
|
212
|
+
// delete previous comment
|
|
213
|
+
const deleteCommentURL = `${commentsRequestURL}/${comment.id}?access_token=${token}`;
|
|
214
|
+
await axiosInstance.delete(deleteCommentURL);
|
|
215
|
+
} catch (e) {
|
|
216
|
+
console.warn(`Can't delete previously added comment with testomat.io report. Ignore.`);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// pass next env var if need to clear all previous reports;
|
|
220
|
+
// only the last one is removed by default
|
|
221
|
+
if (!process.env.GITLAB_REMOVE_ALL_OUTDATED_REPORTS) break;
|
|
222
|
+
// TODO: in case of many reports should implement pagination
|
|
202
223
|
}
|
|
224
|
+
}
|
|
203
225
|
}
|
|
226
|
+
|
|
204
227
|
module.exports = GitLabPipe;
|