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

Fix fallback to git diff command #1714

Merged
merged 18 commits into from
Apr 19, 2024
Merged

Conversation

massongit
Copy link
Contributor

@massongit massongit commented Apr 17, 2024

  • Updated Unreleased section in CHANGELOG or it's not notable changes.

Fix #1696

I fix the fallback to git diff command as follows:

  • Use GitHub API to get a merge base commit
  • Add git fetch command to get merge base and head commits

Copy link
Member

@haya14busa haya14busa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!

It's cool and interesting idea to get merge-base commit with GitHub API.

service/github/github.go Outdated Show resolved Hide resolved
service/github/github.go Outdated Show resolved Hide resolved
service/github/github.go Outdated Show resolved Hide resolved
service/github/github.go Outdated Show resolved Hide resolved
service/github/github_test.go Outdated Show resolved Hide resolved
service/github/github.go Outdated Show resolved Hide resolved
service/github/github.go Outdated Show resolved Hide resolved
service/github/github.go Outdated Show resolved Hide resolved
service/github/github.go Outdated Show resolved Hide resolved
service/github/github.go Outdated Show resolved Hide resolved
service/github/github.go Outdated Show resolved Hide resolved
@derekperkins
Copy link

This looks great!

service/github/github.go Outdated Show resolved Hide resolved
}
}

for _, sha := range []string{mergeBaseSha, headSha} {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to fetch headSha?
It didn't work without fetching it?

Copy link
Contributor Author

@massongit massongit Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/reviewdog/reviewdog/actions/runs/8746978073/job/24004712656?pr=1717 ( a5a03bd )

reviewdog: fail to get diff: failed to run git diff: exit status 128

It look like the above if I don't fetch the head sha.
This is probably because actions/checkout only gets
the commit that merged base ref into head ref by default.

https://github.com/reviewdog/reviewdog/actions/runs/8746978073/job/24004712656?pr=1717 ( a5a03bd )

/usr/bin/git checkout --progress --force refs/remotes/pull/1717/merge
...
  HEAD is now at f62528f Merge a5a03bda8166923b674c24eab300385361b41225 into e34989bf40a5fa7aa4cf5d9f45f3f2e5d1edd3c9
/usr/bin/git log -1 --format='%H'
'f62528f5a35c3964b6441798dae6f9081d8773d7'

In the above example, a5a03bd is head sha, e34989b is base sha and f62528f is merged commit sha.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a good idea to get the head sha using /usr/bin/git log -1 --format='%H' instead of GitHub API.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thank you for the investigation and explanation!
I'm fine with leaving it as is.

Copy link
Member

@haya14busa haya14busa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 💯

}
}

for _, sha := range []string{mergeBaseSha, headSha} {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thank you for the investigation and explanation!
I'm fine with leaving it as is.

@haya14busa haya14busa merged commit e71cc85 into reviewdog:master Apr 19, 2024
15 checks passed
@massongit massongit deleted the fix_diff branch April 19, 2024 10:30
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 this pull request may close these issues.

GitHub Pull Request diff API responds with 406 — diff too large
3 participants