Skip to content
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

Pull Request head sha not correct #61

Closed
lawndoc opened this issue Feb 7, 2023 · 3 comments · Fixed by #62
Closed

Pull Request head sha not correct #61

lawndoc opened this issue Feb 7, 2023 · 3 comments · Fixed by #62
Assignees
Labels
bug Something isn't working

Comments

@lawndoc
Copy link
Collaborator

lawndoc commented Feb 7, 2023

Describe the bug
When triggered by pull_request, both the GITHUB_REF_NAME and GITHUB_SHA default variables will reference the last merge commit of the pull request merge branch rather than the actual last commit to the head branch (see documentation). This causes pull request runs to scan 0 commits most of the time (see screenshots).

To Reproduce
Steps to reproduce the behavior:

  1. Create a branch in a repo with this workflow set up
  2. Create any number of regular commits in the repo
  3. Create a pull request
  4. Compare the last commit hash to the head commit hash used and check the number of commits scanned

Expected behavior
Gitleaks should be scanning from the last commit of the head branch

Screenshots
Workflow run
workflow run

SHA of last commit on head branch that triggered the above workflow
last commit

Additional context
According to the documentation linked above, we should be able to get what we need from github.event.pull_request.head.sha, but it will probably need to be passed into the script somehow.

@lawndoc lawndoc self-assigned this Feb 7, 2023
@lawndoc lawndoc added the bug Something isn't working label Feb 7, 2023
@lawndoc
Copy link
Collaborator Author

lawndoc commented Feb 7, 2023

I'll work on this one in my fork

@lawndoc
Copy link
Collaborator Author

lawndoc commented Feb 7, 2023

I found a way to fix this with minimal modification. In entrypoint.sh, we can change the head_sha variable to:

head_sha=$(git rev-list --no-merges -n 1 refs/remotes/pull/${GITHUB_REF_NAME})

which will grab the most recent commit from the head branch while excluding merge commits.

@lawndoc
Copy link
Collaborator Author

lawndoc commented Feb 7, 2023

Yep, looks like that fixed it:

image

@lawndoc lawndoc linked a pull request Feb 8, 2023 that will close this issue
DariuszPorowski pushed a commit that referenced this issue Feb 8, 2023
Closes major bug #61 and minor bug #58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant