| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,7 @@ import * as github from "@actions/github"; | |||
| 2 | 2 | import test from "ava"; | |
| 3 | 3 | import sinon from "sinon"; | |
| 4 | 4 | ||
| 5 | + import { AnalysisKind } from "../analyses"; | ||
| 5 | 6 | import * as api from "../api-client"; | |
| 6 | 7 | import { RegistryProxyVars } from "../environment"; | |
| 7 | 8 | import { Feature } from "../feature-flags"; | |
@@ -18,7 +19,7 @@ setupTests(test); | |||
| 18 | 19 | ||
| 19 | 20 | test("getConfigFileInput returns undefined by default", async (t) => { | |
| 20 | 21 | await callee(getConfigFileInput) | |
| 21 | - .withArgs({}) | ||
| 22 | + .withArgs({}, undefined) | ||
| 22 | 23 | .withFeatures([Feature.ConfigFileRepositoryProperty]) | |
| 23 | 24 | .passes(t.is, undefined); | |
| 24 | 25 | }); | |
@@ -40,7 +41,7 @@ test("getConfigFileInput returns input value", async (t) => { | |||
| 40 | 41 | .withArgs("config-file") | |
| 41 | 42 | .returns(testInput); | |
| 42 | 43 | }) | |
| 43 | - .withArgs(repositoryProperties) | ||
| 44 | + .withArgs(repositoryProperties, undefined) | ||
| 44 | 45 | .logs(t, "Using configuration file input from workflow") | |
| 45 | 46 | .passes(t.is, testInput); | |
| 46 | 47 | }); | |
@@ -49,24 +50,52 @@ test("getConfigFileInput returns repository property value", async (t) => { | |||
| 49 | 50 | // Since there is no direct input, we should use the repository property. | |
| 50 | 51 | await callee(getConfigFileInput) | |
| 51 | 52 | .withFeatures([Feature.ConfigFileRepositoryProperty]) | |
| 52 | - .withArgs(repositoryProperties) | ||
| 53 | + .withArgs(repositoryProperties, undefined) | ||
| 53 | 54 | .logs(t, "Using configuration file input from repository property") | |
| 54 | 55 | .passes(t.is, repositoryProperties[RepositoryPropertyName.CONFIG_FILE]); | |
| 55 | 56 | }); | |
| 56 | 57 | ||
| 58 | + test("getConfigFileInput returns repository property value for Code Scanning", async (t) => { | ||
| 59 | + // Since there is no direct input, we should use the repository property. | ||
| 60 | + await callee(getConfigFileInput) | ||
| 61 | + .withFeatures([Feature.ConfigFileRepositoryProperty]) | ||
| 62 | + .withArgs(repositoryProperties, [AnalysisKind.CodeScanning]) | ||
| 63 | + .logs(t, "Using configuration file input from repository property") | ||
| 64 | + .passes(t.is, repositoryProperties[RepositoryPropertyName.CONFIG_FILE]); | ||
| 65 | + }); | ||
| 66 | + | ||
| 67 | + test("getConfigFileInput ignores repository property for other analysis kinds", async (t) => { | ||
| 68 | + const unsupportedCases = [ | ||
| 69 | + [AnalysisKind.CodeQuality], | ||
| 70 | + [AnalysisKind.RiskAssessment], | ||
| 71 | + [AnalysisKind.CodeScanning, AnalysisKind.CodeQuality], | ||
| 72 | + ]; | ||
| 73 | + | ||
| 74 | + const target = callee(getConfigFileInput).withFeatures([ | ||
| 75 | + Feature.ConfigFileRepositoryProperty, | ||
| 76 | + ]); | ||
| 77 | + | ||
| 78 | + for (const unsupportedCase of unsupportedCases) { | ||
| 79 | + // Since the analysis kind is unsupported, we should ignore the repository property. | ||
| 80 | + await target | ||
| 81 | + .withArgs(repositoryProperties, unsupportedCase) | ||
| 82 | + .passes(t.is, undefined); | ||
| 83 | + } | ||
| 84 | + }); | ||
| 85 | + | ||
| 57 | 86 | test("getConfigFileInput ignores empty repository property value", async (t) => { | |
| 58 | 87 | // Since the repository property value is an empty/whitespace string, we should ignore it. | |
| 59 | 88 | await callee(getConfigFileInput) | |
| 60 | 89 | .withFeatures([Feature.ConfigFileRepositoryProperty]) | |
| 61 | - .withArgs({ [RepositoryPropertyName.CONFIG_FILE]: " " }) | ||
| 90 | + .withArgs({ [RepositoryPropertyName.CONFIG_FILE]: " " }, undefined) | ||
| 62 | 91 | .passes(t.is, undefined); | |
| 63 | 92 | }); | |
| 64 | 93 | ||
| 65 | 94 | test("getConfigFileInput ignores repository property value when FF is off", async (t) => { | |
| 66 | 95 | // Since the FF is off, we should ignore the repository property value. | |
| 67 | 96 | await callee(getConfigFileInput) | |
| 68 | 97 | .withFeatures([]) | |
| 69 | - .withArgs(repositoryProperties) | ||
| 98 | + .withArgs(repositoryProperties, undefined) | ||
| 70 | 99 | .notLogs(t, "Using configuration file input from repository property") | |
| 71 | 100 | .logs( | |
| 72 | 101 | t, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | import { ActionState } from "../action-common"; | |
| 2 | + import { AnalysisKind } from "../analyses"; | ||
| 2 | 3 | import * as api from "../api-client"; | |
| 3 | 4 | import * as errorMessages from "../error-messages"; | |
| 4 | 5 | import { Feature } from "../feature-flags"; | |
@@ -34,6 +35,7 @@ export async function getConfigFileInput( | |||
| 34 | 35 | features, | |
| 35 | 36 | }: ActionState<["Logger", "Actions", "FeatureFlags"]>, | |
| 36 | 37 | repositoryProperties: Partial<RepositoryProperties>, | |
| 38 | + analysisKinds: AnalysisKind[] | undefined, | ||
| 37 | 39 | ): Promise<string | undefined> { | |
| 38 | 40 | const input = actions.getOptionalInput("config-file"); | |
| 39 | 41 | ||
@@ -45,7 +47,19 @@ export async function getConfigFileInput( | |||
| 45 | 47 | const propertyValue = | |
| 46 | 48 | repositoryProperties[RepositoryPropertyName.CONFIG_FILE]; | |
| 47 | 49 | ||
| 48 | - if (propertyValue !== undefined && propertyValue.trim().length > 0) { | ||
| 50 | + // Only allow the repository property to be used for standard Code Scanning analyses, | ||
| 51 | + // since we don't currently support some customisation options for Code Quality. | ||
| 52 | + // We don't expect customisations for Risk Assessments either. | ||
| 53 | + const analysisKindSupported = | ||
| 54 | + analysisKinds === undefined || | ||
| 55 | + (analysisKinds.includes(AnalysisKind.CodeScanning) && | ||
| 56 | + analysisKinds.length === 1); | ||
| 57 | + | ||
| 58 | + if ( | ||
| 59 | + analysisKindSupported && | ||
| 60 | + propertyValue !== undefined && | ||
| 61 | + propertyValue.trim().length > 0 | ||
| 62 | + ) { | ||
| 49 | 63 | // Only use the repository property value if the FF is enabled. | |
| 50 | 64 | const useRepositoryProperty = await features.getValue( | |
| 51 | 65 | Feature.ConfigFileRepositoryProperty, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -289,6 +289,7 @@ async function run( | |||
| 289 | 289 | configFile = await getConfigFileInput( | |
| 290 | 290 | actionStateWithFeatures, | |
| 291 | 291 | repositoryProperties, | |
| 292 | + analysisKinds, | ||
| 292 | 293 | ); | |
| 293 | 294 | ||
| 294 | 295 | // Send a status report indicating that an analysis is starting. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments