dev-cmd/pr-pull: use GitHub API to get PR commits
This commit is contained in:
parent
1d7788077b
commit
415c36041a
@ -275,22 +275,20 @@ module Homebrew
|
||||
raise
|
||||
end
|
||||
|
||||
def cherry_pick_pr!(pr, args:, path: ".")
|
||||
def cherry_pick_pr!(user, repo, pr, args:, path: ".")
|
||||
if args.dry_run?
|
||||
puts <<~EOS
|
||||
git fetch --force origin +refs/pull/#{pr}/head
|
||||
git merge-base HEAD FETCH_HEAD
|
||||
git cherry-pick --ff --allow-empty $merge_base..FETCH_HEAD
|
||||
EOS
|
||||
else
|
||||
safe_system "git", "-C", path, "fetch", "--quiet", "--force", "origin", "+refs/pull/#{pr}/head"
|
||||
merge_base = Utils.popen_read("git", "-C", path, "merge-base", "HEAD", "FETCH_HEAD").strip
|
||||
commit_count = Utils.popen_read("git", "-C", path, "rev-list", "#{merge_base}..FETCH_HEAD").lines.count
|
||||
|
||||
ohai "Using #{commit_count} commit#{"s" unless commit_count == 1} from ##{pr}"
|
||||
Utils::Git.cherry_pick!(path, "--ff", "--allow-empty", "#{merge_base}..FETCH_HEAD",
|
||||
verbose: args.verbose?, resolve: args.resolve?)
|
||||
return
|
||||
end
|
||||
|
||||
commits = GitHub.pull_request_commits(user, repo, pr)
|
||||
safe_system "git", "-C", path, "fetch", "--quiet", "--force", "origin", commits.last
|
||||
ohai "Using #{commits.count} commit#{"s" unless commits.count == 1} from ##{pr}"
|
||||
Utils::Git.cherry_pick!(path, "--ff", "--allow-empty", *commits, verbose: args.verbose?, resolve: args.resolve?)
|
||||
end
|
||||
|
||||
def check_branch(path, ref, args:)
|
||||
@ -391,7 +389,7 @@ module Homebrew
|
||||
Dir.mktmpdir pr do |dir|
|
||||
cd dir do
|
||||
original_commit = Utils.popen_read("git", "-C", tap.path, "rev-parse", "HEAD").chomp
|
||||
cherry_pick_pr!(pr, path: tap.path, args: args)
|
||||
cherry_pick_pr!(user, repo, pr, path: tap.path, args: args)
|
||||
autosquash!(original_commit, path: tap.path, args: args) if args.autosquash?
|
||||
signoff!(pr, tap: tap, args: args) unless args.clean?
|
||||
|
||||
|
||||
@ -75,4 +75,11 @@ describe GitHub do
|
||||
expect(url).to eq("https://api.github.com/repos/Homebrew/homebrew-core/actions/artifacts/3557392/zip")
|
||||
end
|
||||
end
|
||||
|
||||
describe "::pull_request_commits", :needs_network do
|
||||
it "gets the correct commits hashes for a pull request" do
|
||||
hashes = %w[188606a4a9587365d930b02c98ad6857b1d00150 25a71fe1ea1558415d6496d23834dc70778ddee5]
|
||||
expect(subject.pull_request_commits("Homebrew", "legacy-homebrew", 50678)).to eq(hashes)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -747,4 +747,8 @@ module GitHub
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def pull_request_commits(user, repo, pr)
|
||||
open_api(url_to("repos", user, repo, "pulls", pr, "commits?per_page=100")).map { |c| c["sha"] }
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user