How to get the full range of commits for a PR

We have some automation for our project (currently using Travis, want to switch to Github Actions) that checks whether all the commits in a Pull Request either mention an issue (closes: #321, ref: #643, etc.), or they say [noissue]. 

See this script:

We’re struggling to see how we would accomplish the same thing with Github Actions, though, because there is no obvious way to get the beginning of the commit range.  GITHUB_SHA only provides the last commit. How can we accomplish this?


When you trigger a workflow by pull requet event, in the github.event.pull_request context, there is a commits_url element, which show the pull request commits API url, you could use curl to get the response. Hope this could help. 

Please see my example: 

name: PR commits
on: pull_request
    runs-on: ubuntu-16.04
      - name: Dump GitHub context
          GITHUB_CONTEXT: ${{ github.event.pull_request.commits_url }}
        run: echo "$GITHUB_CONTEXT"
      - run: curl -o out.json ${{ github.event.pull_request.commits_url }}
      - name: Upload artifact
        uses: actions/upload-artifact@v1.0.0
          name: commits
          path: out.json
1 Like

@dralley  Will you accept the work around using pull request commits API url to get pull request commits? If you want to get it from the github.event context, I would encourage you to share your idea in the Feedback form for GitHub Actions.

I’m also interested in a solution to this that doesn’t require fetching individual events from the GitHub API.

The problem here is that there are other cases where you need access to the commit range being built that aren’t just pull requests. Primarily pushes to a main branch and unrelated triggers that need a delta from the latest commit successfully built. This logic is subtle and tricky to handle and would greatly benefit from the environmental-style GITHUB_COMMIT_RANGE simplifcation </pitch> :slight_smile:

1 Like