Skip to content

Commit

Permalink
Merge pull request #7 from hudl/NOTICK-AllowMoreThan50Annotations
Browse files Browse the repository at this point in the history
NOTICK: Allow more than 50 annotations
  • Loading branch information
ema-aka-young authored Dec 21, 2023
2 parents eb46ec9 + 1829827 commit d5b3967
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
18 changes: 16 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 30 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import * as core from '@actions/core'
import * as github from '@actions/github'
import {GitHub} from '@actions/github/lib/utils'
import {RestEndpointMethodTypes} from '@octokit/plugin-rest-endpoint-methods'

import {ArtifactProvider} from './input-providers/artifact-provider'
import {LocalFileProvider} from './input-providers/local-file-provider'
import {FileContent} from './input-providers/input-provider'
import {ParseOptions, TestParser} from './test-parser'
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 {DartJsonParser} from './parsers/dart-json/dart-json-parser'
Expand All @@ -31,6 +33,7 @@ async function main(): Promise<void> {
}

class TestReporter {
readonly maxAnnotationsPerBatch = 50
readonly artifact = core.getInput('artifact', {required: false})
readonly name = core.getInput('name', {required: true})
readonly path = core.getInput('path', {required: true})
Expand Down Expand Up @@ -60,7 +63,7 @@ class TestReporter {
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`)
return
}
Expand Down Expand Up @@ -195,7 +198,7 @@ class TestReporter {
const icon = isFailed ? Icon.fail : Icon.success

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,
conclusion,
status: 'completed',
Expand Down Expand Up @@ -237,6 +240,29 @@ class TestReporter {
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()
2 changes: 1 addition & 1 deletion src/report/get-annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {ellipsis, fixEol} from '../utils/markdown-utils'
import {TestRunResult} from '../test-results'
import {getFirstNonEmptyLine} from '../utils/parse-utils'

type Annotation = {
export type Annotation = {
path: string
start_line: number
end_line: number
Expand Down
6 changes: 6 additions & 0 deletions src/report/patch-check.ts
Original file line number Diff line number Diff line change
@@ -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[]}
}

0 comments on commit d5b3967

Please sign in to comment.