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 gitlab.com repositories #6272

Merged
merged 1 commit into from Sep 5, 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
2 changes: 1 addition & 1 deletion Library/Homebrew/.rubocop.yml
Expand Up @@ -56,7 +56,7 @@ Metrics/MethodLength:
Max: 300
Metrics/ModuleLength:
Enabled: true
Max: 500
Max: 550
Metrics/PerceivedComplexity:
Enabled: true
Max: 100
Expand Down
46 changes: 36 additions & 10 deletions Library/Homebrew/dev-cmd/audit.rb
Expand Up @@ -565,16 +565,8 @@ def audit_bottle_disabled
end

def audit_github_repository
return unless @core_tap
return unless @online
return unless @new_formula

regex = %r{https?://github\.com/([^/]+)/([^/]+)/?.*}
_, user, repo = *regex.match(formula.stable.url) if formula.stable
_, user, repo = *regex.match(formula.homepage) unless user
return if !user || !repo

repo.gsub!(/.git$/, "")
user, repo = get_repo_data(%r{https?://github\.com/([^/]+)/([^/]+)/?.*})
return if user.nil?

begin
metadata = GitHub.repository(user, repo)
Expand All @@ -595,6 +587,40 @@ def audit_github_repository
new_formula_problem "GitHub repository too new (<30 days old)"
end

def audit_gitlab_repository
SMillerDev marked this conversation as resolved.
Show resolved Hide resolved
user, repo = get_repo_data(%r{https?://gitlab\.com/([^/]+)/([^/]+)/?.*})
return if user.nil?

out, _, status= curl_output("--request", "GET", "https://gitlab.com/api/v4/projects/#{user}%2F#{repo}")
return unless status.success?

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

new_formula_problem "GitLab fork (not canonical repository)" if metadata["fork"]
if (metadata["forks_count"] < 30) && (metadata["star_count"] < 75)
new_formula_problem "GitLab repository not notable enough (<30 forks and <75 stars)"
end

return if Date.parse(metadata["created_at"]) <= (Date.today - 30)

new_formula_problem "GitLab repository too new (<30 days old)"
end

def get_repo_data(regex)
return unless @core_tap
return unless @online
return unless @new_formula

_, user, repo = *regex.match(formula.stable.url) if formula.stable
_, user, repo = *regex.match(formula.homepage) unless user
return if !user || !repo

repo.gsub!(/.git$/, "")

[user, repo]
end

def audit_specs
problem "Head-only (no stable download)" if head_only?(formula)
problem "Devel-only (no stable download)" if devel_only?(formula)
Expand Down
14 changes: 14 additions & 0 deletions Library/Homebrew/test/dev-cmd/audit_spec.rb
Expand Up @@ -225,6 +225,20 @@ class Foo < Formula
end
end

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

fa.audit_gitlab_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