Merge pull request #12952 from issyl0/github-branch-exists

utils/github: Add a `branch_exists?` method
This commit is contained in:
Issy Long 2022-03-05 21:48:08 +00:00 committed by GitHub
commit 67512aed56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -80,6 +80,13 @@ module GitHub
["admin", "write"].include?(permission(repo, user)["permission"]) ["admin", "write"].include?(permission(repo, user)["permission"])
end end
def branch_exists?(user, repo, branch)
API.open_rest("#{API_URL}/repos/#{user}/#{repo}/branches/#{branch}")
true
rescue API::HTTPNotFoundError
false
end
def pull_requests(repo, **options) def pull_requests(repo, **options)
url = "#{API_URL}/repos/#{repo}/pulls?#{URI.encode_www_form(options)}" url = "#{API_URL}/repos/#{repo}/pulls?#{URI.encode_www_form(options)}"
API.open_rest(url) API.open_rest(url)