[BUGFIX] Fix Danger::GitRepo::find_merge_base_with_incremental_fetch return value#1498
Merged
manicmaniac merged 4 commits intoSep 27, 2024
Conversation
fix to return merge_base not boolean
Danger::GitRepo::find_merge_base_with_incremental_fetch return valueDanger::GitRepo::find_merge_base_with_incremental_fetch return value
manicmaniac
reviewed
Sep 26, 2024
manicmaniac
requested changes
Sep 26, 2024
manicmaniac
left a comment
Member
There was a problem hiding this comment.
@nagataaaas
Thank you for your contribution 🥇
The purpose of this PR seems reasonable to me, but there appears to be a minor bug. Could you please fix it?
Member
|
📝 I wrote a couple of small and ad-hoc test cases to check this PR. the latter one diff --git a/spec/lib/danger/scm_source/git_repo_spec.rb b/spec/lib/danger/scm_source/git_repo_spec.rb
index 6509d27a..689b0461 100644
--- a/spec/lib/danger/scm_source/git_repo_spec.rb
+++ b/spec/lib/danger/scm_source/git_repo_spec.rb
@@ -269,4 +269,41 @@ RSpec.describe Danger::GitRepo, host: :github do
end
end
end
+
+ describe "#find_merge_base_with_incremental_fetch" do
+ it "returns SHA1 hash of the possible merge base if any" do
+ Dir.mktmpdir do |dir|
+ Dir.chdir(dir) do
+ `git clone --depth=1 --single-branch --branch=master git@github.com:danger/danger.git`
+ repo_path = File.join(dir, "danger")
+ Dir.chdir(repo_path) do
+ @dm = testing_dangerfile
+ repo = Git.open(repo_path)
+ # https://github.com/danger/danger/commit/16ebebd8045667dbd034c106d4a4deb5dbde1cba
+ from = "16ebebd8045667dbd034c106d4a4deb5dbde1cba"
+ to = "master"
+ possible_merge_base = @dm.env.scm.send(:find_merge_base_with_incremental_fetch, repo, from, to)
+ expect(possible_merge_base).to match /[0-9a-f]{40}/
+ end
+ end
+ end
+ end
+
+ it "returns nil when no possible merge base is found" do
+ Dir.mktmpdir do |dir|
+ Dir.chdir(dir) do
+ `git clone --depth=1 --single-branch --branch=master git@github.com:danger/danger.git`
+ repo_path = File.join(dir, "danger")
+ Dir.chdir(repo_path) do
+ @dm = testing_dangerfile
+ repo = Git.open(repo_path)
+ from = "0000000000000000000000000000000000000000"
+ to = "master"
+ possible_merge_base = @dm.env.scm.send(:find_merge_base_with_incremental_fetch, repo, from, to)
+ expect(possible_merge_base).to be_nil
+ end
+ end
+ end
+ end
+ end
end |
manicmaniac
approved these changes
Sep 27, 2024
manicmaniac
left a comment
Member
There was a problem hiding this comment.
LGTM, Thank you @nagataaaas 👍
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Looks like there's a bug.
In the method
Danger::GitRepo::find_merge_base_with_incremental_fetchwhich supposed to return string(possible_merge_base), we return boolean(possible_merge_base is found).This causes an error that passes string
trueorfalseas a branch to git.