Enforce Check Run API limits

This commit is contained in:
Michal Dorner 2021-01-25 10:23:49 +01:00
parent fdd3509024
commit 7af0073fa3
No known key found for this signature in database
GPG key ID: 9EEE04B48DA36786
5 changed files with 49 additions and 11 deletions

View file

@ -1,6 +1,9 @@
import * as github from '@actions/github'
import {EventPayloads} from '@octokit/webhooks'
import {TestResult} from '../parsers/parser-types'
import {ellipsis} from './markdown-utils'
export function getCheckRunSha(): string {
if (github.context.payload.pull_request) {
const pr = github.context.payload.pull_request as EventPayloads.WebhookPayloadPullRequestPullRequest
@ -9,3 +12,19 @@ export function getCheckRunSha(): string {
return github.context.sha
}
export function enforceCheckRunLimits(result: TestResult, maxAnnotations: number): void {
const output = result.output
if (!output) {
return
}
// Limit number of created annotations
output.annotations?.splice(maxAnnotations + 1)
// Limit number of characters in annotation fields
for (const err of output.annotations ?? []) {
err.title = ellipsis(err.title || '', 255)
err.message = ellipsis(err.message, 65535)
}
}