Audit gitlab.com repositories
This commit is contained in:
parent
9a03431845
commit
0cca6cb8bd
@ -56,7 +56,7 @@ Metrics/MethodLength:
|
||||
Max: 300
|
||||
Metrics/ModuleLength:
|
||||
Enabled: true
|
||||
Max: 500
|
||||
Max: 550
|
||||
Metrics/PerceivedComplexity:
|
||||
Enabled: true
|
||||
Max: 100
|
||||
|
@ -565,16 +565,8 @@ module Homebrew
|
||||
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)
|
||||
@ -595,6 +587,40 @@ module Homebrew
|
||||
new_formula_problem "GitHub repository too new (<30 days old)"
|
||||
end
|
||||
|
||||
def audit_gitlab_repository
|
||||
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)
|
||||
|
@ -225,6 +225,20 @@ module Homebrew
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user