-
Notifications
You must be signed in to change notification settings - Fork 450
Add analysis-kinds input
#3061
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add analysis-kinds input
#3061
Changes from 3 commits
e0104a2
06c39b6
f96201c
c1efb64
d72c7f1
270f7ad
d61a10a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import test from "ava"; | ||
|
|
||
| import { | ||
| AnalysisKind, | ||
| parseAnalysisKinds, | ||
| supportedAnalysisKinds, | ||
| } from "./analyses"; | ||
| import { ConfigurationError } from "./util"; | ||
|
|
||
| test("All known analysis kinds can be parsed successfully", async (t) => { | ||
| for (const analysisKind of supportedAnalysisKinds) { | ||
| t.deepEqual(await parseAnalysisKinds(analysisKind), [analysisKind]); | ||
| } | ||
| }); | ||
|
|
||
| test("Parsing analysis kinds returns unique results", async (t) => { | ||
| const analysisKinds = await parseAnalysisKinds( | ||
| "code-scanning,code-quality,code-scanning", | ||
| ); | ||
| t.deepEqual(analysisKinds, [ | ||
| AnalysisKind.CodeScanning, | ||
| AnalysisKind.CodeQuality, | ||
| ]); | ||
| }); | ||
|
|
||
| test("Parsing an unknown analysis kind fails with a configuration error", async (t) => { | ||
| await t.throwsAsync(parseAnalysisKinds("code-scanning,foo"), { | ||
| instanceOf: ConfigurationError, | ||
| }); | ||
| }); | ||
|
|
||
| test("Parsing analysis kinds requires at least one analysis kind", async (t) => { | ||
| await t.throwsAsync(parseAnalysisKinds(","), { | ||
| instanceOf: ConfigurationError, | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,40 @@ | ||
| import { ConfigurationError } from "./util"; | ||
|
|
||
| export enum AnalysisKind { | ||
| CodeScanning = "code-scanning", | ||
| CodeQuality = "code-quality", | ||
| } | ||
|
|
||
| // Exported for testing. A set of all known analysis kinds. | ||
| export const supportedAnalysisKinds = new Set(Object.values(AnalysisKind)); | ||
|
|
||
| /** | ||
| * Parses a comma-separated string into a list of unique analysis kinds. | ||
| * Throws a configuration error if the input contains unknown analysis kinds | ||
| * or doesn't contain at least one element. | ||
| * | ||
| * @param input The comma-separated string to parse. | ||
| * @returns The array of unique analysis kinds that were parsed from the input string. | ||
| */ | ||
| export async function parseAnalysisKinds( | ||
| input: string, | ||
| ): Promise<AnalysisKind[]> { | ||
| const components = input.split(","); | ||
|
|
||
| if (components.length < 1) { | ||
| throw new ConfigurationError( | ||
| "At least one analysis kind must be configured.", | ||
| ); | ||
| } | ||
|
|
||
| for (const component of components) { | ||
| if (!supportedAnalysisKinds.has(component as AnalysisKind)) { | ||
| throw new ConfigurationError(`Unknown analysis kind: ${component}`); | ||
| } | ||
| } | ||
|
|
||
| // Return all unique elements. | ||
| return Array.from( | ||
| new Set(components.map((component) => component as AnalysisKind)), | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of interest, where's this restriction coming from? We can address it in a follow up PR, but I think we want to be able to run code quality only analyses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this restriction will be lifted in a follow-up PR. It's just representative of the current state of the implementation as of this PR.