Check for write access instead of HOMEBREW_DEVELOPER.

This commit is contained in:
Markus Reiter 2019-02-15 16:27:19 +01:00
parent 57fefff942
commit 68e0c5f904
2 changed files with 18 additions and 4 deletions

View File

@ -17,16 +17,17 @@ module Cask
].freeze
def run
raise "This command may only be run by Homebrew maintainers." unless ENV["HOMEBREW_DEVELOPER"]
taps = OFFICIAL_CASK_TAPS.map(&Tap.public_method(:fetch))
access = taps.all? { |tap| GitHub.write_access?(tap.full_name) }
raise "This command may only be run by Homebrew maintainers." unless access
Homebrew.install_gem! "git_diff"
require "git_diff"
failed = []
OFFICIAL_CASK_TAPS.each do |tap_name|
tap = Tap.fetch(tap_name)
taps.each do |tap|
open_pull_requests = GitHub.pull_requests(tap.full_name, state: :open, base: "master")
open_pull_requests.each do |pr|

View File

@ -274,6 +274,19 @@ module GitHub
search_issues(name, state: "open", repo: "#{tap.user}/homebrew-#{tap.repo}", in: "title")
end
def user
@user ||= open_api("#{API_URL}/user")
end
def permission(repo, user)
open_api("#{API_URL}/repos/#{repo}/collaborators/#{user}/permission")
end
def write_access?(repo, user = nil)
user ||= self.user["login"]
["admin", "write"].include?(permission(repo, user)["permission"])
end
def pull_requests(repo, base:, state: :open, **_options)
url = "#{API_URL}/repos/#{repo}/pulls?#{URI.encode_www_form(base: base, state: state)}"
open_api(url)