-
-
Notifications
You must be signed in to change notification settings - Fork 237
fix(vcs): Handle non-github workflow in find_base_sha #2897
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
Conversation
4433ce5 to
4f1cba4
Compare
| .map_err(Error::from) | ||
| .and_then(|event_path| std::fs::read_to_string(event_path).map_err(Error::from)) | ||
| .context("Failed to read GitHub event path")?; | ||
| pub fn find_base_sha(remote_name: &str) -> Result<Option<String>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m: As we no longer ever return Ok(None) from this function, we should simplify the signature to return Result<String>.
| pub fn find_base_sha(remote_name: &str) -> Result<Option<String>> { | |
| pub fn find_base_sha(remote_name: &str) -> Result<String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intention is that if the merge-base could not be found we return None. If that is not what the Rust code:
let remote_commit = remote_ref.peel_to_commit()?;
let merge_base_oid = repo.merge_base(head_commit.id(), remote_commit.id())?;
does could you suggest the best way to make it do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that is not what this code does. The ? will propagate any Err returned by these functions, causing find_base_sha to return Err(<whatever error from the method>).
Will add my suggestion for how to do this below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
szokeasaurusrex
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good for the most part, did notice a few improvements (and a typo), however.
Note: I am using the LOGAF scale in my comments
|
|
||
| let repo = git2::Repository::open_from_env()?; | ||
|
|
||
| let head_commit = repo.head()?.peel_to_commit()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l: Context for better error message:
| let head_commit = repo.head()?.peel_to_commit()?; | |
| let head_commit = repo.head() | |
| .and_then(|h| h.peel_to_commit()) | |
| .context("Could not find head commit")?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chromy are you also wanting to return None if this call fails?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I think this one should probably Error. It's legitimate that there might not be a merge-base for two commits, you can get it if the history is separate e.g.
$ git commit -m'foo' --allow-empty
[main (root-commit) fa819e8] foo
$ git commit -m'bar' --allow-empty
[main c35d2ee] bar
$ git checkout --orphan baz
Switched to a new branch 'baz'
$ git commit -m'baz' --allow-empty
[baz (root-commit) 27134ca] baz
$ git merge-base main baz
$ git merge-base HEAD baz
27134ca5b445526335d7a8d955790fac1e5d3690
This one:
$ git merge-base main baz
returns nothing because there is no common commit in the history of the main branch and the orphan baz branch.
However I don't think there can be a legitimate case where HEAD doesn't point at a commit. I think that will only happen if the repo is in quite a corrupt state.
src/utils/vcs.rs
Outdated
| let remote_commit = remote_ref.peel_to_commit()?; | ||
| let merge_base_oid = repo.merge_base(head_commit.id(), remote_commit.id())?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l: Would also add context for these
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above: the intention is that if the merge-base could not be found we return None.
I don't think there is value in adding context to peel_to_commit()
CHANGELOG.md
Outdated
|
|
||
| ### Fixes | ||
|
|
||
| - Fix auto filled git metadata when using the `build upload` subcommand in non-github workflow contexts ([#2897](https://github.com/getsentry/sentry-cli/pull/2897)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m: Can you please add some more detail to this changelog entry/make it more user-friendly? E.g. by being more specific of what metadata we can now add in non-GH workflow contexts? I have been putting more effort into creating human-readable changelog entries the past few releases.
l: Also, I would consider this more of a new feature than a fix; can we put it in a ### New Features section? (and if we do, please move the section above deprecations)
Maybe this works:
| ### Fixes | |
| - Fix auto filled git metadata when using the `build upload` subcommand in non-github workflow contexts ([#2897](https://github.com/getsentry/sentry-cli/pull/2897)) | |
| ### New Features | |
| - `build upload` now supports automatic git base commit detection in local development and all CI environments, not just GitHub Actions ([#2897](https://github.com/getsentry/sentry-cli/pull/2897)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been more specific in the message. I don't think it's a feature. This was intended behaviour since this was introduced (as seen in the head code and also in the calling code, that it did not work previously is a bug.
e4ec720 to
cf24ed0
Compare
3827998 to
64bbabb
Compare
`find_head_sha` supported both Github workflow contexts and 'raw git'
contexts however the matching function `find_base_sha` did not handle
raw git contexts.
Thi updates `find_base_sha` to return the equivalent of:
`git merge-base HEAD origin/HEAD`. For:
```
o---o---o---origin/main
/
---1---o---o---o---foo
```
We return the SHA of 1.
Apply suggestion from @szokeasaurusrex
Co-authored-by: Daniel Szoke <[email protected]>
Update src/utils/vcs.rs
Co-authored-by: Daniel Szoke <[email protected]>
64bbabb to
629a6a8
Compare
| .map_err(Error::from) | ||
| .and_then(|event_path| std::fs::read_to_string(event_path).map_err(Error::from)) | ||
| .context("Failed to read GitHub event path")?; | ||
| pub fn find_base_sha(remote_name: &str) -> Result<Option<String>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that is not what this code does. The ? will propagate any Err returned by these functions, causing find_base_sha to return Err(<whatever error from the method>).
Will add my suggestion for how to do this below
|
|
||
| let repo = git2::Repository::open_from_env()?; | ||
|
|
||
| let head_commit = repo.head()?.peel_to_commit()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chromy are you also wanting to return None if this call fails?
Co-authored-by: Daniel Szoke <[email protected]>
Co-authored-by: Daniel Szoke <[email protected]>
find_head_shasupported both Github workflow contexts and 'raw git'contexts however the matching function
find_base_shadid not handleraw git contexts.
Thi updates
find_base_shato return the equivalent of:git merge-base HEAD origin/HEAD. For:We return the SHA of 1.