Skip to content

Commit

Permalink
SCAN-5687 : Add better fallback logic when getting ref from event. (#8)
Browse files Browse the repository at this point in the history
* SCAN-5687 : Fallback to high level ref.

* [Auto] Image tag updated latest pushed version

* SCAN-5687 : Add error handling around ref retrieval.

* [Auto] Image tag updated latest pushed version

* SCAN-5687 : Include ref in error message.

* [Auto] Image tag updated latest pushed version

---------

Co-authored-by: Github <[email protected]>
  • Loading branch information
steviemul and Github authored Sep 10, 2024
1 parent cc47b19 commit 85af24a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ inputs:
default: ${{ github.token }}
runs:
using: 'docker'
image: 'docker://ghcr.io/contrast-security-oss/contrast-local-scan-action:sha-d2d24005fccf69c0f916bed5c97e720cc231b18b'
image: 'docker://ghcr.io/contrast-security-oss/contrast-local-scan-action:sha-9215789c436d9755e0f330b883793def98718018'
14 changes: 11 additions & 3 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,26 @@ const getRef = () => {
}
default: {
core.warning(`Received unexpected github event ${github.context.eventName}`);
return github.context.payload?.ref;
return github.context.payload?.ref || github.context.ref;
}
}
};

const thisBranchName = () => {

const ref = getRef();

try {

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

const refParts = ref.split('/');
return refParts[refParts.length-1];
}
catch (error) {
core.error(`Unable to get current branch name from ref ${ref} : ${error.message}`);
}

return refParts[refParts.length-1];
return DEFAULT_BRANCH_NAME
};

const isDefaultBranch = () => {
Expand Down

0 comments on commit 85af24a

Please sign in to comment.