Skip to content

Commit

Permalink
⚡ Fallback to actions/core API if Checks API for annotations is not a…
Browse files Browse the repository at this point in the history
…vailable
  • Loading branch information
tiulpin committed Jun 17, 2023
1 parent 9ee2bde commit bf7642e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
27 changes: 26 additions & 1 deletion scan/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64429,12 +64429,37 @@ var require_annotations = __commonJS({
yield publishGitHubCheck(failedByThreshold, name, token, problems);
}
} catch (error) {
core2.debug(`Failed to publish annotations \u2013 ${error.message}`);
core2.info(`Not able to publish annotations with Checks API \u2013 ${error.message},
using limited (10 problems per level) output instead. Check job permissions (checks: write, pull-requests: write needed)`);
for (const p of problems.annotations) {
const properties = toAnnotationProperties(p);
switch (p.annotation_level) {
case exports2.ANNOTATION_FAILURE:
core2.error(p.message, properties);
break;
case exports2.ANNOTATION_WARNING:
core2.warning(p.message, properties);
break;
default:
core2.notice(p.message, properties);
}
}
}
});
}
__name(publishAnnotations, "publishAnnotations");
exports2.publishAnnotations = publishAnnotations;
function toAnnotationProperties(a) {
return {
title: a.title,
file: a.path,
startLine: a.start_line,
endLine: a.end_line,
startColumn: a.start_column,
endColumn: a.end_column
};
}
__name(toAnnotationProperties, "toAnnotationProperties");
}
});

Expand Down
30 changes: 29 additions & 1 deletion scan/src/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {Log, Result, Tool} from 'sarif'
import {context, getOctokit} from '@actions/github'
import {getProblemPlural, getWorkflowRunUrl} from './utils'
import {GitHub} from '@actions/github/lib/utils'
import {AnnotationProperties} from '@actions/core'

function getQodanaHelpString(): string {
return `This result was published with [Qodana GitHub Action](${getWorkflowRunUrl()})`
Expand Down Expand Up @@ -260,6 +261,33 @@ export async function publishAnnotations(
await publishGitHubCheck(failedByThreshold, name, token, problems)
}
} catch (error) {
core.debug(`Failed to publish annotations – ${(error as Error).message}`)
core.info(`Not able to publish annotations with Checks API – ${
(error as Error).message
},
using limited (10 problems per level) output instead. Check job permissions (checks: write, pull-requests: write needed)`)
for (const p of problems.annotations) {
const properties = toAnnotationProperties(p)
switch (p.annotation_level) {
case ANNOTATION_FAILURE:
core.error(p.message, properties)
break
case ANNOTATION_WARNING:
core.warning(p.message, properties)
break
default:
core.notice(p.message, properties)
}
}
}
}

function toAnnotationProperties(a: Annotation): AnnotationProperties {
return {
title: a.title,
file: a.path,
startLine: a.start_line,
endLine: a.end_line,
startColumn: a.start_column,
endColumn: a.end_column
}
}

0 comments on commit bf7642e

Please sign in to comment.