Skip to content

Commit

Permalink
comment on PRs that used merge commits
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Feb 4, 2025
1 parent 76c08f1 commit 177e766
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/kennel/github_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def initialize(token, ref: "HEAD")
@token = token
commit = Utils.capture_sh("git show #{ref}")
@sha = commit[/^Merge: \S+ (\S+)/, 1] || commit[/\Acommit (\S+)/, 1] || raise("Unable to find commit")
@pr = commit[/^\s+.*\(#(\d+)\)/, 1] # from squash
@pr =
commit[/^\s+.*\(#(\d+)\)/, 1] || # from squash
commit[/^\s+Merge pull request #(\d+)/, 1] # from merge with unmodified commit message
@repo_part = ENV["GITHUB_REPOSITORY"] || begin
origin = ENV["PROJECT_REPOSITORY"] || Utils.capture_sh("git remote -v").split("\n").first
origin[%r{github\.com[:/](\S+?)(\.git|$)}, 1] || raise("no origin found in #{origin}")
Expand Down
9 changes: 8 additions & 1 deletion test/kennel/github_reporter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,20 @@
reporter.instance_variable_get(:@repo_part).must_equal "foo/bar"
end

it "can create PR comments" do
it "can create PR comments for squash" do
show_response << "\n foo (#123)"
request = stub_request(:post, "https://api.github.com/repos/foo/bar/issues/123/comments").to_return(status: 201)
Kennel::Console.capture_stdout { reporter.report { Kennel.out.puts "HEY" } }
assert_requested request
end

it "can create PR comments for merge" do
show_response << "\n Merge pull request #123"
request = stub_request(:post, "https://api.github.com/repos/foo/bar/issues/123/comments").to_return(status: 201)
Kennel::Console.capture_stdout { reporter.report { Kennel.out.puts "HEY" } }
assert_requested request
end

it "can create merge comments" do
show_response.replace "commit: nope\nMerge: foo abcd"
request = stub_request(:post, "https://api.github.com/repos/foo/bar/commits/abcd/comments").to_return(status: 201)
Expand Down

0 comments on commit 177e766

Please sign in to comment.