mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-17 06:47:09 +01:00
Merge pull request #7 from hudl/NOTICK-AllowMoreThan50Annotations
NOTICK: Allow more than 50 annotations
This commit is contained in:
commit
d5b3967dd9
4 changed files with 53 additions and 7 deletions
18
dist/index.js
generated
vendored
18
dist/index.js
generated
vendored
|
|
@ -284,6 +284,7 @@ function main() {
|
||||||
}
|
}
|
||||||
class TestReporter {
|
class TestReporter {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
this.maxAnnotationsPerBatch = 50;
|
||||||
this.artifact = core.getInput('artifact', { required: false });
|
this.artifact = core.getInput('artifact', { required: false });
|
||||||
this.name = core.getInput('name', { required: true });
|
this.name = core.getInput('name', { required: true });
|
||||||
this.path = core.getInput('path', { required: true });
|
this.path = core.getInput('path', { required: true });
|
||||||
|
|
@ -298,6 +299,19 @@ class TestReporter {
|
||||||
this.showHTMLNotice = core.getInput('show-html-notice', { required: false }) === 'true';
|
this.showHTMLNotice = core.getInput('show-html-notice', { required: false }) === 'true';
|
||||||
this.token = core.getInput('token', { required: true });
|
this.token = core.getInput('token', { required: true });
|
||||||
this.context = (0, github_utils_1.getCheckRunContext)();
|
this.context = (0, github_utils_1.getCheckRunContext)();
|
||||||
|
this.handleAnnotations = (annotations, requestParams) => __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const leftAnnotations = [...annotations];
|
||||||
|
let response;
|
||||||
|
do {
|
||||||
|
const toProcess = leftAnnotations.splice(0, 50);
|
||||||
|
const status = leftAnnotations.length > 0 ? 'in_progress' : 'completed';
|
||||||
|
response = yield this.updateAnnotation(toProcess, Object.assign(Object.assign({}, requestParams), { status }));
|
||||||
|
} while (leftAnnotations.length > 0);
|
||||||
|
return response;
|
||||||
|
});
|
||||||
|
this.updateAnnotation = (annotations, requestParams) => __awaiter(this, void 0, void 0, function* () {
|
||||||
|
return yield this.octokit.rest.checks.update(Object.assign(Object.assign({}, requestParams), { output: Object.assign(Object.assign({}, requestParams.output), { annotations }) }));
|
||||||
|
});
|
||||||
this.octokit = github.getOctokit(this.token);
|
this.octokit = github.getOctokit(this.token);
|
||||||
if (this.listSuites !== 'all' && this.listSuites !== 'failed') {
|
if (this.listSuites !== 'all' && this.listSuites !== 'failed') {
|
||||||
core.setFailed(`Input parameter 'list-suites' has invalid value`);
|
core.setFailed(`Input parameter 'list-suites' has invalid value`);
|
||||||
|
|
@ -307,7 +321,7 @@ class TestReporter {
|
||||||
core.setFailed(`Input parameter 'list-tests' has invalid value`);
|
core.setFailed(`Input parameter 'list-tests' has invalid value`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isNaN(this.maxAnnotations) || this.maxAnnotations < 0 || this.maxAnnotations > 50) {
|
if (isNaN(this.maxAnnotations) || this.maxAnnotations > 50) {
|
||||||
core.setFailed(`Input parameter 'max-annotations' has invalid value`);
|
core.setFailed(`Input parameter 'max-annotations' has invalid value`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -410,7 +424,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.handleAnnotations(annotations, Object.assign({ check_run_id: createResp.data.id, conclusion, status: 'completed', output: {
|
||||||
title: `${name} ${icon}`,
|
title: `${name} ${icon}`,
|
||||||
summary,
|
summary,
|
||||||
annotations
|
annotations
|
||||||
|
|
|
||||||
32
src/main.ts
32
src/main.ts
|
|
@ -1,13 +1,15 @@
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as github from '@actions/github'
|
import * as github from '@actions/github'
|
||||||
import {GitHub} from '@actions/github/lib/utils'
|
import {GitHub} from '@actions/github/lib/utils'
|
||||||
|
import {RestEndpointMethodTypes} from '@octokit/plugin-rest-endpoint-methods'
|
||||||
|
|
||||||
import {ArtifactProvider} from './input-providers/artifact-provider'
|
import {ArtifactProvider} from './input-providers/artifact-provider'
|
||||||
import {LocalFileProvider} from './input-providers/local-file-provider'
|
import {LocalFileProvider} from './input-providers/local-file-provider'
|
||||||
import {FileContent} from './input-providers/input-provider'
|
import {FileContent} from './input-providers/input-provider'
|
||||||
import {ParseOptions, TestParser} from './test-parser'
|
import {ParseOptions, TestParser} from './test-parser'
|
||||||
import {TestRunResult} from './test-results'
|
import {TestRunResult} from './test-results'
|
||||||
import {getAnnotations} from './report/get-annotations'
|
import {getAnnotations, Annotation} from './report/get-annotations'
|
||||||
|
import {UpdateChecksParametersWithOutput} from './report/patch-check'
|
||||||
import {getReport} from './report/get-report'
|
import {getReport} from './report/get-report'
|
||||||
|
|
||||||
import {DartJsonParser} from './parsers/dart-json/dart-json-parser'
|
import {DartJsonParser} from './parsers/dart-json/dart-json-parser'
|
||||||
|
|
@ -31,6 +33,7 @@ async function main(): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestReporter {
|
class TestReporter {
|
||||||
|
readonly maxAnnotationsPerBatch = 50
|
||||||
readonly artifact = core.getInput('artifact', {required: false})
|
readonly artifact = core.getInput('artifact', {required: false})
|
||||||
readonly name = core.getInput('name', {required: true})
|
readonly name = core.getInput('name', {required: true})
|
||||||
readonly path = core.getInput('path', {required: true})
|
readonly path = core.getInput('path', {required: true})
|
||||||
|
|
@ -60,7 +63,7 @@ class TestReporter {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNaN(this.maxAnnotations) || this.maxAnnotations < 0 || this.maxAnnotations > 50) {
|
if (isNaN(this.maxAnnotations) || this.maxAnnotations > 50) {
|
||||||
core.setFailed(`Input parameter 'max-annotations' has invalid value`)
|
core.setFailed(`Input parameter 'max-annotations' has invalid value`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -195,7 +198,7 @@ class TestReporter {
|
||||||
const icon = isFailed ? Icon.fail : Icon.success
|
const icon = isFailed ? Icon.fail : Icon.success
|
||||||
|
|
||||||
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.handleAnnotations(annotations, {
|
||||||
check_run_id: createResp.data.id,
|
check_run_id: createResp.data.id,
|
||||||
conclusion,
|
conclusion,
|
||||||
status: 'completed',
|
status: 'completed',
|
||||||
|
|
@ -237,6 +240,29 @@ class TestReporter {
|
||||||
throw new Error(`Input variable 'reporter' is set to invalid value '${reporter}'`)
|
throw new Error(`Input variable 'reporter' is set to invalid value '${reporter}'`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private handleAnnotations = async (
|
||||||
|
annotations: Annotation[],
|
||||||
|
requestParams: UpdateChecksParametersWithOutput
|
||||||
|
): Promise<RestEndpointMethodTypes['checks']['update']['response']> => {
|
||||||
|
const leftAnnotations = [...annotations]
|
||||||
|
let response: RestEndpointMethodTypes['checks']['update']['response']
|
||||||
|
do {
|
||||||
|
const toProcess = leftAnnotations.splice(0, 50)
|
||||||
|
const status = leftAnnotations.length > 0 ? 'in_progress' : 'completed'
|
||||||
|
response = await this.updateAnnotation(toProcess, {...requestParams, status})
|
||||||
|
} while (leftAnnotations.length > 0)
|
||||||
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private updateAnnotation = async (
|
||||||
|
annotations: Annotation[],
|
||||||
|
requestParams: UpdateChecksParametersWithOutput
|
||||||
|
): Promise<RestEndpointMethodTypes['checks']['update']['response']> => {
|
||||||
|
return await this.octokit.rest.checks.update({
|
||||||
|
...requestParams,
|
||||||
|
output: {...requestParams.output, annotations}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import {ellipsis, fixEol} from '../utils/markdown-utils'
|
||||||
import {TestRunResult} from '../test-results'
|
import {TestRunResult} from '../test-results'
|
||||||
import {getFirstNonEmptyLine} from '../utils/parse-utils'
|
import {getFirstNonEmptyLine} from '../utils/parse-utils'
|
||||||
|
|
||||||
type Annotation = {
|
export type Annotation = {
|
||||||
path: string
|
path: string
|
||||||
start_line: number
|
start_line: number
|
||||||
end_line: number
|
end_line: number
|
||||||
|
|
|
||||||
6
src/report/patch-check.ts
Normal file
6
src/report/patch-check.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
import {RestEndpointMethodTypes} from '@octokit/plugin-rest-endpoint-methods'
|
||||||
|
import {Annotation} from './get-annotations'
|
||||||
|
|
||||||
|
export type UpdateChecksParametersWithOutput = RestEndpointMethodTypes['checks']['update']['parameters'] & {
|
||||||
|
output: {title: string; summary: string; annotations: Annotation[]}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue