Skip to content

Commit

Permalink
SCAN-5585 : Use PR ref for pull request events.
Browse files Browse the repository at this point in the history
  • Loading branch information
steviemul committed Jul 30, 2024
1 parent 4b016f3 commit 38af10d
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
const core = require("@actions/core");
const github = require("@actions/github");

const PULL_REQUEST_EVENT = 'pull_request';
const WORKFLOW_DISPATCH = 'workflow_dispatch';
const PUSH_EVENT = 'push';
const DEFAULT_BRANCH_NAME = github.context.payload?.repository?.default_branch;

const getRef = () => {

switch (github.context.eventName) {
case PULL_REQUEST_EVENT: {
return github.context.payload?.pull_request?.head?.ref;
}
case PUSH_EVENT:
case WORKFLOW_DISPATCH: {
return github.context.payload?.ref;
}
default: {
core.warning(`Received unexpected github event ${github.context.eventName}`);
return github.context.payload?.ref;
}
}
};

const thisBranchName = () => {
core.info('Checking branch name');
core.info(JSON.stringify(github.context.payload, null, 2));

const refParts = github.context.payload.ref.split('/');
const ref = getRef();

const refParts = ref.split('/');

return refParts[refParts.length-1];
};
Expand Down Expand Up @@ -43,7 +63,8 @@ const checks = core.getBooleanInput("checks");
const codeQuality = core.getBooleanInput("codeQuality");
const defaultBranch = isDefaultBranch();

const label = core.getInput("label") || process.env.GITHUB_REF;
const ref = getRef();
const label = core.getInput("label") || ref;

// Pinning the local scanner version
const localScannerVersion = "1.0.10";
Expand All @@ -52,7 +73,7 @@ const memory = core.getInput("memory");
const path = core.getInput("path") || process.env.GITHUB_WORKSPACE;
const projectName =
core.getInput("projectName") || process.env.GITHUB_REPOSITORY;
const ref = process.env.GITHUB_REF;

const resourceGroup = core.getInput("resourceGroup");
const severity = core.getInput("severity")?.toLowerCase() || undefined;
const strategy = core.getInput("strategy") || "project";
Expand All @@ -63,6 +84,7 @@ const token = core.getInput("token");
core.debug(`Default branch name : ${DEFAULT_BRANCH_NAME}`);
core.debug(`This branch name : ${thisBranchName()}`);
core.debug(`Default branch resolved setting : ${defaultBranch}`)
core.debug(JSON.stringify(github.context, null, 2));

module.exports = {
apiUrl,
Expand Down

0 comments on commit 38af10d

Please sign in to comment.