13rac1 / block-fixup-merge-action

Github Action to block merge of Pull Requests containing fixup! or squash! commits
MIT License
46 stars 14 forks source link

Diff only compares current branch with master #2

Closed 13rac1 closed 3 years ago

13rac1 commented 4 years ago

The script only compares current branch with master right now. It could check for closest branch https://stackoverflow.com/questions/3161204/how-to-find-the-nearest-parent-of-a-git-branch but that isn't always correct.

git show-branch -a \
| grep '\*' \
| grep -v `git rev-parse --abbrev-ref HEAD` \
| head -n1 \
| sed 's/.*\[\(.*\)\].*/\1/' \
| sed 's/[\^~].*//'

The best way is probably using the Github API https://developer.github.com/v3/repos/commits/#list-pull-requests-associated-with-commit

GET /repos/:owner/:repo/commits/:commit_sha/pulls
jplatte commented 3 years ago

This is a big problem for repos that don't have a master branch (e.g. because they use GitHub's new default of main).

Maybe you could check whether GITHUB_BASE_REF is set and use that? According to the docs it's only set for forks but that doesn't really make sense to me, especially considering the corresponding context says that it's set for PRs.

jplatte commented 3 years ago

I've solved this in our fork https://github.com/lumeohq/block-fixup-merge-action, although it requires users to (only) run the action for pull_request events (which IMO makes a lot of sense, then there is no need for filtering out tag pushes). I'm not sure whether you're interested in still maintaining this action considering you didn't reply to my previous comment, but if you are and don't mind the change from push to pull_request events I can send a PR for this change.

13rac1 commented 3 years ago

Please submit a PR, I'd be happy to merge. Thank you