Skip to content

Commit

Permalink
- add API to configure and use old annotation approach
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepenz committed Mar 18, 2022
1 parent 0d2f2b5 commit d247291
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 124 deletions.
121 changes: 53 additions & 68 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

125 changes: 70 additions & 55 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export async function run(): Promise<void> {
return
}

const legacyApi = core.getInput('legacy') === 'false'
const updateCheck = core.getInput('update_check') === 'true'
const checkName = core.getInput('check_name')
const commit = core.getInput('commit')
Expand Down Expand Up @@ -86,59 +87,26 @@ export async function run(): Promise<void> {
core.startGroup(`🚀 Publish results`)

try {
for (const annotation of testResult.annotations) {
const properties: core.AnnotationProperties = {
title: annotation.title,
file: annotation.path,
startLine: annotation.start_line,
endLine: annotation.end_line,
startColumn: annotation.start_column,
endColumn: annotation.end_column
}
if (annotation.annotation_level === 'failure') {
core.error(annotation.message, properties)
} else if (annotation.annotation_level === 'warning') {
core.warning(annotation.message, properties)
} else {
core.notice(annotation.message, properties)
}
}

/*
const octokit = github.getOctokit(token)
if (updateCheck) {
const checks = await octokit.rest.checks.listForRef({
...github.context.repo,
ref: head_sha,
check_name: github.context.job,
status: 'in_progress',
filter: 'latest'
})
core.debug(JSON.stringify(checks, null, 2))
const check_run_id = checks.data.check_runs[0].id
core.info(`ℹ️ Updating checks ${testResult.annotations.length}`)
for (let i = 0; i < testResult.annotations.length; i = i + 50) {
const sliced = testResult.annotations.slice(i, i + 50)
const updateCheckRequest = {
...github.context.repo,
check_run_id,
output: {
title,
summary,
annotations: sliced
}
if (!legacyApi) {
for (const annotation of testResult.annotations) {
const properties: core.AnnotationProperties = {
title: annotation.title,
file: annotation.path,
startLine: annotation.start_line,
endLine: annotation.end_line,
startColumn: annotation.start_column,
endColumn: annotation.end_column
}
if (annotation.annotation_level === 'failure') {
core.error(annotation.message, properties)
} else if (annotation.annotation_level === 'warning') {
core.warning(annotation.message, properties)
} else {
core.notice(annotation.message, properties)
}
core.debug(JSON.stringify(updateCheckRequest, null, 2))
await octokit.rest.checks.update(updateCheckRequest)
}
} else {

const createCheckRequest = {
...github.context.repo,
name: checkName,
Expand All @@ -147,17 +115,64 @@ export async function run(): Promise<void> {
conclusion,
output: {
title,
summary,
annotations: testResult.annotations.slice(0, 50)
summary
}
}
core.debug(JSON.stringify(createCheckRequest, null, 2))
core.info(`ℹ️ Creating check`)
await octokit.rest.checks.create(createCheckRequest)
} else {
if (updateCheck) {
const checks = await octokit.rest.checks.listForRef({
...github.context.repo,
ref: head_sha,
check_name: github.context.job,
status: 'in_progress',
filter: 'latest'
})

core.debug(JSON.stringify(checks, null, 2))

const check_run_id = checks.data.check_runs[0].id

core.info(`ℹ️ Updating checks ${testResult.annotations.length}`)
for (let i = 0; i < testResult.annotations.length; i = i + 50) {
const sliced = testResult.annotations.slice(i, i + 50)

const updateCheckRequest = {
...github.context.repo,
check_run_id,
output: {
title,
summary,
annotations: sliced
}
}

core.debug(JSON.stringify(updateCheckRequest, null, 2))

await octokit.rest.checks.update(updateCheckRequest)
}
} else {
const createCheckRequest = {
...github.context.repo,
name: checkName,
head_sha,
status: 'completed',
conclusion,
output: {
title,
summary,
annotations: testResult.annotations.slice(0, 50)
}
}

core.debug(JSON.stringify(createCheckRequest, null, 2))

core.info(`ℹ️ Creating check`)
await octokit.rest.checks.create(createCheckRequest)
}
}
*/

if (failOnFailure && conclusion === 'failure') {
core.setFailed(`❌ Tests reported ${failed} failures`)
Expand Down

0 comments on commit d247291

Please sign in to comment.