audit: error on archived repos
This commit is contained in:
parent
dff330e336
commit
dab18076fa
@ -522,6 +522,30 @@ module Homebrew
|
||||
problem "Formulae in homebrew/core should not use `bottle :disabled`"
|
||||
end
|
||||
|
||||
def audit_github_repository_archived
|
||||
return if formula.deprecated?
|
||||
|
||||
user, repo = get_repo_data(%r{https?://github\.com/([^/]+)/([^/]+)/?.*}) if @online
|
||||
return if user.blank?
|
||||
|
||||
metadata = SharedAudits.github_repo_data(user, repo)
|
||||
return if metadata.nil?
|
||||
|
||||
problem "GitHub repo is archived" if metadata["archived"]
|
||||
end
|
||||
|
||||
def audit_gitlab_repository_archived
|
||||
return if formula.deprecated?
|
||||
|
||||
user, repo = get_repo_data(%r{https?://gitlab\.com/([^/]+)/([^/]+)/?.*}) if @online
|
||||
return if user.blank?
|
||||
|
||||
metadata = SharedAudits.gitlab_repo_data(user, repo)
|
||||
return if metadata.nil?
|
||||
|
||||
problem "GitLab repo is archived" if metadata["archived"]
|
||||
end
|
||||
|
||||
def audit_github_repository
|
||||
user, repo = get_repo_data(%r{https?://github\.com/([^/]+)/([^/]+)/?.*}) if @new_formula
|
||||
|
||||
|
||||
@ -195,6 +195,20 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
|
||||
describe "#audit_github_repository_archived" do
|
||||
specify "#audit_github_repository_archived when HOMEBREW_NO_GITHUB_API is set" do
|
||||
fa = formula_auditor "foo", <<~RUBY, strict: true, online: true
|
||||
class Foo < Formula
|
||||
homepage "https://github.com/example/example"
|
||||
url "https://brew.sh/foo-1.0.tgz"
|
||||
end
|
||||
RUBY
|
||||
|
||||
fa.audit_github_repository_archived
|
||||
expect(fa.problems).to eq([])
|
||||
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
|
||||
@ -209,6 +223,20 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
|
||||
describe "#audit_gitlab_repository_archived" do
|
||||
specify "#audit gitlab repository for archived status" 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_archived
|
||||
expect(fa.problems).to eq([])
|
||||
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
|
||||
|
||||
@ -5,13 +5,30 @@ require "utils/curl"
|
||||
module SharedAudits
|
||||
module_function
|
||||
|
||||
def github(user, repo)
|
||||
begin
|
||||
metadata = GitHub.repository(user, repo)
|
||||
def github_repo_data(user, repo)
|
||||
@github_repo_data ||= {}
|
||||
@github_repo_data["#{user}/#{repo}"] ||= GitHub.repository(user, repo)
|
||||
|
||||
@github_data["#{user}/#{repo}"]
|
||||
rescue GitHub::HTTPNotFoundError
|
||||
return
|
||||
nil
|
||||
end
|
||||
|
||||
def gitlab_repo_data(user, repo)
|
||||
@gitlab_repo_data ||= {}
|
||||
@gitlab_repo_data["#{user}/#{repo}"] ||= begin
|
||||
out, _, status= curl_output("--request", "GET", "https://gitlab.com/api/v4/projects/#{user}%2F#{repo}")
|
||||
return unless status.success?
|
||||
|
||||
JSON.parse(out)
|
||||
end
|
||||
|
||||
@gitlab_data["#{user}/#{repo}"]
|
||||
end
|
||||
|
||||
def github(user, repo)
|
||||
metadata = github_repo_data(user, repo)
|
||||
|
||||
return if metadata.nil?
|
||||
|
||||
return "GitHub fork (not canonical repository)" if metadata["fork"]
|
||||
@ -26,10 +43,8 @@ module SharedAudits
|
||||
end
|
||||
|
||||
def gitlab(user, repo)
|
||||
out, _, status= curl_output("--request", "GET", "https://gitlab.com/api/v4/projects/#{user}%2F#{repo}")
|
||||
return unless status.success?
|
||||
metadata = gitlab_repo_data(user, repo)
|
||||
|
||||
metadata = JSON.parse(out)
|
||||
return if metadata.nil?
|
||||
|
||||
return "GitLab fork (not canonical repository)" if metadata["fork"]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user