@testomatio/reporter 2.0.1-beta.4 → 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/github.js
CHANGED
|
@@ -1,236 +1,231 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
const debug_1 = __importDefault(require("debug"));
|
|
40
|
-
const path_1 = __importDefault(require("path"));
|
|
41
|
-
const picocolors_1 = __importDefault(require("picocolors"));
|
|
42
|
-
const humanize_duration_1 = __importDefault(require("humanize-duration"));
|
|
43
|
-
const lodash_merge_1 = __importDefault(require("lodash.merge"));
|
|
44
|
-
const constants_js_1 = require("../constants.js");
|
|
45
|
-
const utils_js_1 = require("../utils/utils.js");
|
|
46
|
-
const pipe_utils_js_1 = require("../utils/pipe_utils.js");
|
|
47
|
-
const debug = (0, debug_1.default)('@testomatio/reporter:pipe:github');
|
|
1
|
+
const debug = require('debug')('@testomatio/reporter:pipe:github');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const chalk = require('chalk');
|
|
4
|
+
const humanizeDuration = require('humanize-duration');
|
|
5
|
+
const merge = require('lodash.merge');
|
|
6
|
+
const { Octokit } = require('@octokit/rest');
|
|
7
|
+
const { APP_PREFIX, testomatLogoURL } = require('../constants');
|
|
8
|
+
const { ansiRegExp, isSameTest } = require('../utils/utils');
|
|
9
|
+
const { statusEmoji, fullName } = require('../utils/pipe_utils');
|
|
10
|
+
|
|
48
11
|
/**
|
|
49
|
-
* @typedef {import('../../types
|
|
50
|
-
* @typedef {import('../../types
|
|
12
|
+
* @typedef {import('../../types').Pipe} Pipe
|
|
13
|
+
* @typedef {import('../../types').TestData} TestData
|
|
51
14
|
* @class GitHubPipe
|
|
52
15
|
* @implements {Pipe}
|
|
53
16
|
*/
|
|
54
17
|
class GitHubPipe {
|
|
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
|
-
|
|
18
|
+
constructor(params, store = {}) {
|
|
19
|
+
this.isEnabled = false;
|
|
20
|
+
this.store = store;
|
|
21
|
+
this.tests = [];
|
|
22
|
+
this.token = params.GH_PAT || process.env.GH_PAT;
|
|
23
|
+
this.ref = process.env.GITHUB_REF;
|
|
24
|
+
this.repo = process.env.GITHUB_REPOSITORY;
|
|
25
|
+
this.jobKey = `${process.env.GITHUB_WORKFLOW || ''} / ${process.env.GITHUB_JOB || ''}`;
|
|
26
|
+
this.hiddenCommentData = `<!--- testomat.io report ${this.jobKey} -->`;
|
|
27
|
+
|
|
28
|
+
debug('GitHub Pipe: ', this.token ? 'TOKEN' : '*no token*', 'Ref:', this.ref, 'Repo:', this.repo);
|
|
29
|
+
|
|
30
|
+
if (!this.token || !this.ref || !this.repo) return;
|
|
31
|
+
this.isEnabled = true;
|
|
32
|
+
const matchedIssue = this.ref.match(/refs\/pull\/(\d+)\/merge/);
|
|
33
|
+
if (!matchedIssue) return;
|
|
34
|
+
this.issue = parseInt(matchedIssue[1], 10);
|
|
35
|
+
|
|
36
|
+
this.start = new Date();
|
|
37
|
+
|
|
38
|
+
debug('GitHub Pipe: Enabled');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// TODO: to using SET opts as argument => prepareRun(opts)
|
|
42
|
+
async prepareRun() {}
|
|
43
|
+
|
|
44
|
+
async createRun() {}
|
|
45
|
+
|
|
46
|
+
addTest(test) {
|
|
47
|
+
if (!this.isEnabled) return;
|
|
48
|
+
debug('Adding test:', test);
|
|
49
|
+
|
|
50
|
+
const index = this.tests.findIndex(t => isSameTest(t, test));
|
|
51
|
+
// update if they were already added
|
|
52
|
+
if (index >= 0) {
|
|
53
|
+
this.tests[index] = merge(this.tests[index], test);
|
|
54
|
+
return;
|
|
89
55
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
56
|
+
|
|
57
|
+
this.tests.push(test);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async finishRun(runParams) {
|
|
61
|
+
if (!this.isEnabled) return;
|
|
62
|
+
if (!this.issue) return;
|
|
63
|
+
|
|
64
|
+
if (runParams.tests) runParams.tests.forEach(t => this.addTest(t));
|
|
65
|
+
|
|
66
|
+
this.octokit = new Octokit({
|
|
67
|
+
auth: this.token,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const [owner, repo] = (this.repo || '').split('/');
|
|
71
|
+
if (!(owner || repo)) return;
|
|
72
|
+
|
|
73
|
+
// ... create a comment on GitHub
|
|
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
|
+
let summary = `${this.hiddenCommentData}
|
|
79
|
+
|
|
80
|
+
| [](https://testomat.io) | ${statusEmoji(
|
|
81
|
+
runParams.status,
|
|
82
|
+
)} ${`${process.env.GITHUB_JOB} ${runParams.status}`.toUpperCase()} |
|
|
111
83
|
| --- | --- |
|
|
112
84
|
| Tests | ✔️ **${this.tests.length}** tests run |
|
|
113
|
-
| Summary | ${failedCount ? `${
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
if (this.tests.length > 0) {
|
|
164
|
-
body += '\n<details>\n<summary><h3>🐢 Slowest Tests</h3></summary>\n\n';
|
|
165
|
-
body += this.tests
|
|
166
|
-
.sort((a, b) => b?.run_time - a?.run_time)
|
|
167
|
-
.slice(0, 5)
|
|
168
|
-
.map(t => `* ${(0, pipe_utils_js_1.fullName)(t)} (${(0, humanize_duration_1.default)(parseFloat(t.run_time))})`)
|
|
169
|
-
.join('\n');
|
|
170
|
-
body += '\n</details>';
|
|
171
|
-
}
|
|
172
|
-
await deletePreviousReport(this.octokit, owner, repo, this.issue, this.hiddenCommentData);
|
|
173
|
-
// add report as comment
|
|
174
|
-
try {
|
|
175
|
-
debug('Adding comment\n', body);
|
|
176
|
-
const resp = await this.octokit.rest.issues.createComment({
|
|
177
|
-
owner,
|
|
178
|
-
repo,
|
|
179
|
-
issue_number: this.issue,
|
|
180
|
-
body,
|
|
85
|
+
| Summary | ${failedCount ? `${statusEmoji('failed')} **${failedCount}** failed; ` : ''} ${statusEmoji(
|
|
86
|
+
'passed',
|
|
87
|
+
)} **${passedCount}** passed; **${statusEmoji('skipped')}** ${skippedCount} skipped |
|
|
88
|
+
| Duration | 🕐 **${humanizeDuration(
|
|
89
|
+
parseInt(
|
|
90
|
+
this.tests.reduce((a, t) => a + (t.run_time || 0), 0),
|
|
91
|
+
10,
|
|
92
|
+
),
|
|
93
|
+
{
|
|
94
|
+
maxDecimalPoints: 0,
|
|
95
|
+
},
|
|
96
|
+
)}** |`;
|
|
97
|
+
|
|
98
|
+
if (this.store.runUrl) {
|
|
99
|
+
summary += `\n| Testomat.io Report | 📊 [Run #${this.store.runId}](${this.store.runUrl}) | `;
|
|
100
|
+
}
|
|
101
|
+
if (process.env.GITHUB_WORKFLOW) {
|
|
102
|
+
summary += `\n| Job | 🗂️ [${this.jobKey}](${process.env.GITHUB_SERVER_URL || 'https://github.com'}/${
|
|
103
|
+
this.repo
|
|
104
|
+
}/actions/runs/${process.env.GITHUB_RUN_ID}) | `;
|
|
105
|
+
}
|
|
106
|
+
if (process.env.RUNNER_OS) {
|
|
107
|
+
summary += `\n| Operating System | 🖥️ \`${process.env.RUNNER_OS}\` ${process.env.RUNNER_ARCH || ''} | `;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const failures = this.tests
|
|
111
|
+
.filter(t => t.status === 'failed')
|
|
112
|
+
.slice(0, 20)
|
|
113
|
+
.map(t => {
|
|
114
|
+
let text = `#### ${statusEmoji('failed')} ${fullName(t)} `;
|
|
115
|
+
text += '\n\n';
|
|
116
|
+
if (t.message)
|
|
117
|
+
text += `> ${t.message
|
|
118
|
+
.replace(/[^\x20-\x7E]/g, '')
|
|
119
|
+
.replace(ansiRegExp(), '')
|
|
120
|
+
.trim()}\n`;
|
|
121
|
+
if (t.stack) text += `\`\`\`diff\n${t.stack.replace(ansiRegExp(), '').trim()}\n\`\`\`\n`;
|
|
122
|
+
|
|
123
|
+
if (t.artifacts && t.artifacts.length && !process.env.TESTOMATIO_PRIVATE_ARTIFACTS) {
|
|
124
|
+
t.artifacts
|
|
125
|
+
.filter(f => !!f)
|
|
126
|
+
.filter(f => f.endsWith('.png'))
|
|
127
|
+
.forEach(f => {
|
|
128
|
+
if (f.endsWith('.png')) {
|
|
129
|
+
text += `\n`;
|
|
130
|
+
return text;
|
|
131
|
+
}
|
|
132
|
+
text += `[📄 ${path.basename(f)}](${f})\n`;
|
|
133
|
+
return text;
|
|
181
134
|
});
|
|
182
|
-
const url = resp.data?.html_url;
|
|
183
|
-
debug('Comment URL:', url);
|
|
184
|
-
this.store.githubUrl = url;
|
|
185
|
-
console.log(constants_js_1.APP_PREFIX, picocolors_1.default.yellow('GitHub'), `Report created: ${picocolors_1.default.magenta(url)}`);
|
|
186
|
-
}
|
|
187
|
-
catch (err) {
|
|
188
|
-
console.log(constants_js_1.APP_PREFIX, picocolors_1.default.yellow('GitHub'), `Couldn't create GitHub report ${err}`);
|
|
189
135
|
}
|
|
136
|
+
|
|
137
|
+
text += '\n---\n';
|
|
138
|
+
|
|
139
|
+
return text;
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
let body = summary;
|
|
143
|
+
|
|
144
|
+
if (failures.length) {
|
|
145
|
+
body += `\n<details>\n<summary><h3>🟥 Failures (${failures.length})</h4></summary>\n\n${failures.join('\n')}\n`;
|
|
146
|
+
if (failures.length > 20) {
|
|
147
|
+
body += '\n> Notice\n> Only first 20 failures shown*';
|
|
148
|
+
}
|
|
149
|
+
body += '\n\n</details>';
|
|
190
150
|
}
|
|
191
|
-
|
|
192
|
-
|
|
151
|
+
|
|
152
|
+
if (this.tests.length > 0) {
|
|
153
|
+
body += '\n<details>\n<summary><h3>🐢 Slowest Tests</h3></summary>\n\n';
|
|
154
|
+
body += this.tests
|
|
155
|
+
// eslint-disable-next-line no-unsafe-optional-chaining
|
|
156
|
+
.sort((a, b) => b?.run_time - a?.run_time)
|
|
157
|
+
.slice(0, 5)
|
|
158
|
+
.map(t => `* ${fullName(t)} (${humanizeDuration(parseFloat(t.run_time))})`)
|
|
159
|
+
.join('\n');
|
|
160
|
+
body += '\n</details>';
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
await deletePreviousReport(this.octokit, owner, repo, this.issue, this.hiddenCommentData);
|
|
164
|
+
|
|
165
|
+
// add report as comment
|
|
166
|
+
try {
|
|
167
|
+
debug('Adding comment\n', body);
|
|
168
|
+
const resp = await this.octokit.rest.issues.createComment({
|
|
169
|
+
owner,
|
|
170
|
+
repo,
|
|
171
|
+
issue_number: this.issue,
|
|
172
|
+
body,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
const url = resp.data?.html_url;
|
|
176
|
+
debug('Comment URL:', url);
|
|
177
|
+
this.store.githubUrl = url;
|
|
178
|
+
|
|
179
|
+
console.log(APP_PREFIX, chalk.yellow('GitHub'), `Report created: ${chalk.magenta(url)}`);
|
|
180
|
+
} catch (err) {
|
|
181
|
+
console.log(APP_PREFIX, chalk.yellow('GitHub'), `Couldn't create GitHub report ${err}`);
|
|
193
182
|
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
toString() {
|
|
186
|
+
return 'GitHub Reporter';
|
|
187
|
+
}
|
|
194
188
|
}
|
|
189
|
+
|
|
195
190
|
async function deletePreviousReport(octokit, owner, repo, issue, hiddenCommentData) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
191
|
+
if (process.env.GH_KEEP_OUTDATED_REPORTS) return;
|
|
192
|
+
|
|
193
|
+
// get comments
|
|
194
|
+
let comments = [];
|
|
195
|
+
try {
|
|
196
|
+
const response = await octokit.rest.issues.listComments({
|
|
197
|
+
owner,
|
|
198
|
+
repo,
|
|
199
|
+
issue_number: issue,
|
|
200
|
+
});
|
|
201
|
+
comments = response.data;
|
|
202
|
+
} catch (e) {
|
|
203
|
+
console.error('Error while attempt to retrieve comments on GitHub Pull 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
|
+
await octokit.rest.issues.deleteComment({
|
|
214
|
+
owner,
|
|
215
|
+
repo,
|
|
216
|
+
issue_number: issue,
|
|
217
|
+
comment_id: comment.id,
|
|
205
218
|
});
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
// if comment was left by the same workflow
|
|
215
|
-
if (comment.body.includes(hiddenCommentData)) {
|
|
216
|
-
try {
|
|
217
|
-
// delete previous comment
|
|
218
|
-
await octokit.rest.issues.deleteComment({
|
|
219
|
-
owner,
|
|
220
|
-
repo,
|
|
221
|
-
issue_number: issue,
|
|
222
|
-
comment_id: comment.id,
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
catch (e) {
|
|
226
|
-
console.warn(`Can't delete previously added comment with testomat.io report. Ignore.`);
|
|
227
|
-
}
|
|
228
|
-
// pass next env var if need to clear all previous reports;
|
|
229
|
-
// only the last one is removed by default
|
|
230
|
-
if (!process.env.GITHUB_REMOVE_ALL_OUTDATED_REPORTS)
|
|
231
|
-
break;
|
|
232
|
-
// TODO: in case of many reports should implement pagination
|
|
233
|
-
}
|
|
219
|
+
} catch (e) {
|
|
220
|
+
console.warn(`Can't delete previously added comment with testomat.io report. Ignore.`);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// pass next env var if need to clear all previous reports;
|
|
224
|
+
// only the last one is removed by default
|
|
225
|
+
if (!process.env.GITHUB_REMOVE_ALL_OUTDATED_REPORTS) break;
|
|
226
|
+
// TODO: in case of many reports should implement pagination
|
|
234
227
|
}
|
|
228
|
+
}
|
|
235
229
|
}
|
|
230
|
+
|
|
236
231
|
module.exports = GitHubPipe;
|