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

docs: use GH base sha to lint PR commits #4198

Merged
merged 1 commit into from
Nov 24, 2024

Conversation

robjweiss
Copy link
Contributor

@robjweiss robjweiss commented Nov 22, 2024

Description

The current documentation suggests using HEAD~n to go through all PR commits where n is the number of commits in the PR. This may not always produce the desired result though, especially if the history is not perfectly linear and there is a complex history of merges.

GitHub Actions provides the base sha on the pull_request object as well. This should give a revision list in line with the git log and revisions shown on GitHub.

Motivation and Context

While using the previous CI workflow, I found that the commits being linted where different from those I was seeing in the PR. After reading a bit about how ~ and ^ work with git I came to the conclusion that going ~n will not necessarily point to the same revision as the first commit shown in the PR (merge base), especially if the history is complex.

These are my findings. If there's something I've overlooked or you think my conclusions are incorrect, please do let me know!

The original discussion on the GitHub docs seems to come from here: #586.

Usage examples

In a GitHub Action:

npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose

How Has This Been Tested?

I compared the commits linted by using each method. The commits linted by the existing method included some not shown in the PR. The commits linted by the new method matched exactly.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (documentation)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link

codesandbox-ci bot commented Nov 22, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@escapedcat
Copy link
Member

Hey @robjweiss , thanks for this. Would you mind removing the scope from your commit message? It's not a valid scope for this project.

@knocte wdyt?

@robjweiss robjweiss changed the title docs(ci-setup): use GH base sha to lint PR commits docs: use GH base sha to lint PR commits Nov 23, 2024
@robjweiss
Copy link
Contributor Author

@escapedcat no problem, updated.

@escapedcat escapedcat merged commit 0f5cb79 into conventional-changelog:master Nov 24, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants