mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-17 06:47:09 +01:00
use existing check when possible
This commit is contained in:
parent
59060a80a8
commit
1deff739ec
2 changed files with 52 additions and 17 deletions
22
dist/index.js
generated
vendored
22
dist/index.js
generated
vendored
|
|
@ -292,6 +292,7 @@ class TestReporter {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
createReport(parser, name, files) {
|
createReport(parser, name, files) {
|
||||||
|
var _a;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
if (files.length === 0) {
|
if (files.length === 0) {
|
||||||
core.warning(`No file matches path ${this.path}`);
|
core.warning(`No file matches path ${this.path}`);
|
||||||
|
|
@ -313,13 +314,22 @@ class TestReporter {
|
||||||
}
|
}
|
||||||
core.info(`Creating check run ${name}`);
|
core.info(`Creating check run ${name}`);
|
||||||
try {
|
try {
|
||||||
const createResp = yield this.octokit.rest.checks.create(Object.assign({ head_sha: this.context.sha, name, status: 'in_progress', output: {
|
const existingChecks = yield this.octokit.rest.checks.listForRef(Object.assign(Object.assign({ ref: this.context.sha }, github.context.repo), { check_name: name, status: 'queued' }));
|
||||||
title: name,
|
const check = ((_a = existingChecks === null || existingChecks === void 0 ? void 0 : existingChecks.data) === null || _a === void 0 ? void 0 : _a.total_count) > 0
|
||||||
summary: ''
|
? yield this.octokit.rest.checks.get(Object.assign({ check_run_id: existingChecks.data.check_runs[0].id }, github.context.repo))
|
||||||
} }, github.context.repo));
|
: yield this.octokit.rest.checks.create(Object.assign({ head_sha: this.context.sha, name, status: 'in_progress', output: {
|
||||||
|
title: name,
|
||||||
|
summary: ''
|
||||||
|
} }, github.context.repo));
|
||||||
|
if (check.data.status === 'queued') {
|
||||||
|
yield this.octokit.rest.checks.update(Object.assign({ check_run_id: check.data.id, status: 'in_progress', output: {
|
||||||
|
title: name,
|
||||||
|
summary: ''
|
||||||
|
} }, github.context.repo));
|
||||||
|
}
|
||||||
core.info('Creating report summary');
|
core.info('Creating report summary');
|
||||||
const { listSuites, listTests, onlySummary } = this;
|
const { listSuites, listTests, onlySummary } = this;
|
||||||
const baseUrl = createResp.data.html_url || '';
|
const baseUrl = check.data.html_url || '';
|
||||||
const summary = (0, get_report_1.getReport)(results, { listSuites, listTests, baseUrl, onlySummary });
|
const summary = (0, get_report_1.getReport)(results, { listSuites, listTests, baseUrl, onlySummary });
|
||||||
core.info('Creating annotations');
|
core.info('Creating annotations');
|
||||||
const annotations = (0, get_annotations_1.getAnnotations)(results, this.maxAnnotations);
|
const annotations = (0, get_annotations_1.getAnnotations)(results, this.maxAnnotations);
|
||||||
|
|
@ -327,7 +337,7 @@ class TestReporter {
|
||||||
const conclusion = isFailed ? 'failure' : 'success';
|
const conclusion = isFailed ? 'failure' : 'success';
|
||||||
const icon = isFailed ? markdown_utils_1.Icon.fail : markdown_utils_1.Icon.success;
|
const icon = isFailed ? markdown_utils_1.Icon.fail : markdown_utils_1.Icon.success;
|
||||||
core.info(`Updating check run conclusion (${conclusion}) and output`);
|
core.info(`Updating check run conclusion (${conclusion}) and output`);
|
||||||
const resp = yield this.octokit.rest.checks.update(Object.assign({ check_run_id: createResp.data.id, conclusion, status: 'completed', output: {
|
const resp = yield this.octokit.rest.checks.update(Object.assign({ check_run_id: check.data.id, conclusion, status: 'completed', output: {
|
||||||
title: `${name} ${icon}`,
|
title: `${name} ${icon}`,
|
||||||
summary,
|
summary,
|
||||||
annotations
|
annotations
|
||||||
|
|
|
||||||
47
src/main.ts
47
src/main.ts
|
|
@ -218,20 +218,45 @@ class TestReporter {
|
||||||
|
|
||||||
core.info(`Creating check run ${name}`)
|
core.info(`Creating check run ${name}`)
|
||||||
try {
|
try {
|
||||||
const createResp = await this.octokit.rest.checks.create({
|
const existingChecks = await this.octokit.rest.checks.listForRef({
|
||||||
head_sha: this.context.sha,
|
ref: this.context.sha,
|
||||||
name,
|
...github.context.repo,
|
||||||
status: 'in_progress',
|
check_name: name,
|
||||||
output: {
|
status: 'queued'
|
||||||
title: name,
|
|
||||||
summary: ''
|
|
||||||
},
|
|
||||||
...github.context.repo
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const check =
|
||||||
|
existingChecks?.data?.total_count > 0
|
||||||
|
? await this.octokit.rest.checks.get({
|
||||||
|
check_run_id: existingChecks.data.check_runs[0].id,
|
||||||
|
...github.context.repo
|
||||||
|
})
|
||||||
|
: await this.octokit.rest.checks.create({
|
||||||
|
head_sha: this.context.sha,
|
||||||
|
name,
|
||||||
|
status: 'in_progress',
|
||||||
|
output: {
|
||||||
|
title: name,
|
||||||
|
summary: ''
|
||||||
|
},
|
||||||
|
...github.context.repo
|
||||||
|
})
|
||||||
|
|
||||||
|
if (check.data.status === 'queued') {
|
||||||
|
await this.octokit.rest.checks.update({
|
||||||
|
check_run_id: check.data.id,
|
||||||
|
status: 'in_progress',
|
||||||
|
output: {
|
||||||
|
title: name,
|
||||||
|
summary: ''
|
||||||
|
},
|
||||||
|
...github.context.repo
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
core.info('Creating report summary')
|
core.info('Creating report summary')
|
||||||
const {listSuites, listTests, onlySummary} = this
|
const {listSuites, listTests, onlySummary} = this
|
||||||
const baseUrl = createResp.data.html_url || ''
|
const baseUrl = check.data.html_url || ''
|
||||||
const summary = getReport(results, {listSuites, listTests, baseUrl, onlySummary})
|
const summary = getReport(results, {listSuites, listTests, baseUrl, onlySummary})
|
||||||
|
|
||||||
core.info('Creating annotations')
|
core.info('Creating annotations')
|
||||||
|
|
@ -243,7 +268,7 @@ class TestReporter {
|
||||||
|
|
||||||
core.info(`Updating check run conclusion (${conclusion}) and output`)
|
core.info(`Updating check run conclusion (${conclusion}) and output`)
|
||||||
const resp = await this.octokit.rest.checks.update({
|
const resp = await this.octokit.rest.checks.update({
|
||||||
check_run_id: createResp.data.id,
|
check_run_id: check.data.id,
|
||||||
conclusion,
|
conclusion,
|
||||||
status: 'completed',
|
status: 'completed',
|
||||||
output: {
|
output: {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue