Skip to content

Commit

Permalink
Add Env Var to skip branch validation (#9)
Browse files Browse the repository at this point in the history
When running the scanner with ZTP, we manually set all relevant branch /
sha values, so we can skip the checks for a sane ADO environment.
  • Loading branch information
mathieu-lemay authored Jul 13, 2023
1 parent e5a6ad6 commit 49c36d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions source/src/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export function validateEnv(env: any, params: BoostParams) {
throw Error("this extension only supports Github and TfsGit repositories")
}

if (execEnv.SKIP_BRANCH_VALIDATION !== undefined) {
return;
}

if (execEnv.BUILD_REASON == "Manual") {
const sourceBranch =
execEnv.SYSTEM_PULLREQUEST_SOURCEBRANCH ?? execEnv.BUILD_SOURCEBRANCHNAME
Expand Down
15 changes: 15 additions & 0 deletions source/tests/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,21 @@ describe("validateEnv", () => {
)
})

test("skips branch validation when SKIP_BRANCH_VALIDATION is defined", async () => {
const params = new BoostParams(process.env, task)
process.env.BUILD_REPOSITORY_PROVIDER = "GitHub"
process.env.BUILD_REASON = "Manual"
process.env.SYSTEM_PULLREQUEST_SOURCEBRANCH = "invalid"

expect(() => {
scanner.validateEnv(process.env, params)
}).toThrow(scanner.ExecutionError)

// Value is irrelevant, just needs to be defined
process.env.SKIP_BRANCH_VALIDATION = ""
scanner.validateEnv(process.env, params)
})

describe("when BUILD_REASON is Manual", () => {
test("passes when BUILD_SOURCEBRANCHNAME is main branch", async () => {
const params = new BoostParams(process.env, task)
Expand Down

0 comments on commit 49c36d1

Please sign in to comment.