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

Documentation update: Use head_ref for comments on PR commits? #20

Closed
mpdude opened this issue Jun 18, 2020 · 4 comments · Fixed by #21
Closed

Documentation update: Use head_ref for comments on PR commits? #20

mpdude opened this issue Jun 18, 2020 · 4 comments · Fixed by #21

Comments

@mpdude
Copy link

mpdude commented Jun 18, 2020

While omitting the sha action input just works for regular commits on branches, these comments are not visible when the action is run for pull requests.

The reason is that for pull requests, actions are run on "merge commits", as you explained here and also documented elsewhere.

By using

            -   uses: peter-evans/commit-comment@v1
                with:
                    body: "I'm sorry Dave, I'm afraid I can't do that."
                    sha: ${{ github.head_ref }}

... things seem to work for both PRs and regular commits.

If this makes sense, you might want to add a short notice in the README file?

@peter-evans
Copy link
Owner

peter-evans commented Jun 19, 2020

Hi @mpdude

Does github.head_ref work for you? I've not tried it but I would be surprised if that works. The GitHub API is expecting a commit SHA, not a ref.

Even if it works, I think it might be more correct to use github.event.pull_request.head.sha instead. I know this works because I use it in my CI build. See here

Anyway, it's a good idea to add something to the readme about this. I'll add a section to explain about avoiding the merge commit.

@peter-evans
Copy link
Owner

I just checked and using head_ref does work because the API is converting the ref into the "last sha on the ref." There is a small risk that you will hit the wrong commit sha though. If another commit is pushed to the branch before the action runs it will add the comment to the latest commit SHA, not the commit SHA that the Actions run is executing on.

@peter-evans
Copy link
Owner

I don't think anyone would ever want to add a comment to the merge commit, so I'm now thinking of updating the action to detect that it is running on a pull_request event and just defaulting the SHA to the pull request branch HEAD.

@peter-evans
Copy link
Owner

Updated v1 to default sha to the branch HEAD on pull request events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants