utils/github: Add a branch_exists? method
- I wrote this as part of https://github.com/issyl0/homebrew-maintenance-utils/blob/main/cmd/find-invalid-head-branches.rb, as I needed to check if a branch exists on a repo, and thought I'd properly add it in case it's useful to others.
This commit is contained in:
parent
3d689eb62b
commit
84632598a0
@ -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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user