Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audit bitbucket.com repositories #6425

Merged
merged 1 commit into from Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions Library/Homebrew/dev-cmd/audit.rb
Expand Up @@ -607,6 +607,44 @@ def audit_gitlab_repository
new_formula_problem "GitLab repository too new (<30 days old)"
end

def audit_bitbucket_repository
user, repo = get_repo_data(%r{https?://bitbucket\.org/([^/]+)/([^/]+)/?.*})
return if user.nil?

api_url = "https://api.bitbucket.org/2.0/repositories/#{user}/#{repo}"
out, _, status= curl_output("--request", "GET", api_url)
return unless status.success?

metadata = JSON.parse(out)
return if metadata.nil?

new_formula_problem "Uses deprecated mercurial support in Bitbucket" if metadata["scm"] == "hg"

if metadata["parent"]["full_name"] == "#{user}/#{repo}"
new_formula_problem "Bitbucket fork (not canonical repository)"
end

if Date.parse(metadata["created_on"]) >= (Date.today - 30)
new_formula_problem "Bitbucket repository too new (<30 days old)"
end

forks_out, _, forks_status= curl_output("--request", "GET", "#{api_url}/forks")
return unless forks_status.success?

watcher_out, _, watcher_status= curl_output("--request", "GET", "#{api_url}/watchers")
return unless watcher_status.success?

forks_metadata = JSON.parse(forks_out)
return if forks_metadata.nil?

watcher_metadata = JSON.parse(watcher_out)
return if watcher_metadata.nil?

return if (forks_metadata["size"] < 30) && (watcher_metadata["size"] < 75)

new_formula_problem "Bitbucket repository not notable enough (<30 forks and <75 watchers)"
end

def get_repo_data(regex)
return unless @core_tap
return unless @online
Expand Down
14 changes: 14 additions & 0 deletions Library/Homebrew/test/dev-cmd/audit_spec.rb
Expand Up @@ -239,6 +239,20 @@ class Foo < Formula
end
end

describe "#audit_bitbucket_repository" do
specify "#audit_bitbucket_repository for stars, forks and creation date" do
fa = formula_auditor "foo", <<~RUBY, strict: true, online: true
class Foo < Formula
homepage "https://bitbucket.com/libtiff/libtiff"
url "https://brew.sh/foo-1.0.tgz"
end
RUBY

fa.audit_bitbucket_repository
expect(fa.problems).to eq([])
end
end

describe "#audit_deps" do
describe "a dependency on a macOS-provided keg-only formula" do
describe "which is whitelisted" do
Expand Down