Module: SharedAudits Private

Defined in:
brew/Library/Homebrew/utils/shared_audits.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Auditing functions for rules common to both casks and formulae.

Constant Summary collapse

GITHUB_PRERELEASE_ALLOWLIST =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  "amd-power-gadget" => :all,
  "elm-format"       => "0.8.3",
  "gitless"          => "0.8.8",
  "infrakit"         => "0.5",
  "pock"             => :all,
  "riff"             => "0.5.0",
  "telegram-cli"     => "1.3.1",
  "toggl-track"      => :all,
  "volta"            => "0.8.6",
}.freeze
GITLAB_PRERELEASE_ALLOWLIST =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{}.freeze
GITHUB_FORK_ALLOWLIST =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%w[
  variar/klogg
].freeze

Class Method Summary collapse

Class Method Details

.bitbucket(user, repo) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'brew/Library/Homebrew/utils/shared_audits.rb', line 138

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

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

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

  return "Bitbucket fork (not canonical repository)" unless ["parent"].nil?

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

  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?

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

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

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

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

.github(user, repo) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'brew/Library/Homebrew/utils/shared_audits.rb', line 104

def github(user, repo)
   = github_repo_data(user, repo)

  return if .nil?

  if ["fork"] && !GITHUB_FORK_ALLOWLIST.include?("#{user}/#{repo}")
    return "GitHub fork (not canonical repository)"
  end

  if (["forks_count"] < 30) && (["subscribers_count"] < 30) &&
     (["stargazers_count"] < 75)
    return "GitHub repository not notable enough (<30 forks, <30 watchers and <75 stars)"
  end

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

  "GitHub repository too new (<30 days old)"
end

.github_release(user, repo, tag, formula: nil, cask: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'brew/Library/Homebrew/utils/shared_audits.rb', line 42

def github_release(user, repo, tag, formula: nil, cask: nil)
  release = github_release_data(user, repo, tag)
  return unless release

  if cask && GITHUB_PRERELEASE_ALLOWLIST[cask.token] == :all
    return if release["prerelease"]

    return "#{tag} is not a GitHub pre-release but cask '#{cask.token}' is in GITHUB_PRERELEASE_ALLOWLIST."
  end

  if release["prerelease"]
    return if formula && GITHUB_PRERELEASE_ALLOWLIST[formula.name] == formula.version

    return "#{tag} is a GitHub pre-release."
  end

  return "#{tag} is a GitHub draft." if release["draft"]
end

.github_release_data(user, repo, tag) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
23
24
25
26
27
28
# File 'brew/Library/Homebrew/utils/shared_audits.rb', line 20

def github_release_data(user, repo, tag)
  id = "#{user}/#{repo}/#{tag}"
  @github_release_data ||= {}
  @github_release_data[id] ||= GitHub.open_api("#{GitHub::API_URL}/repos/#{user}/#{repo}/releases/tags/#{tag}")

  @github_release_data[id]
rescue GitHub::HTTPNotFoundError
  nil
end

.github_repo_data(user, repo) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
12
13
14
15
16
17
18
# File 'brew/Library/Homebrew/utils/shared_audits.rb', line 11

def github_repo_data(user, repo)
  @github_repo_data ||= {}
  @github_repo_data["#{user}/#{repo}"] ||= GitHub.repository(user, repo)

  @github_repo_data["#{user}/#{repo}"]
rescue GitHub::HTTPNotFoundError
  nil
end

.github_tag_from_url(url) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



169
170
171
172
173
174
175
176
177
178
# File 'brew/Library/Homebrew/utils/shared_audits.rb', line 169

def github_tag_from_url(url)
  url = url.to_s
  tag = url.match(%r{^https://github\.com/[\w-]+/[\w-]+/archive/([^/]+)\.(tar\.gz|zip)$})
           .to_a
           .second
  tag ||= url.match(%r{^https://github\.com/[\w-]+/[\w-]+/releases/download/([^/]+)/})
             .to_a
             .second
  tag
end

.gitlab(user, repo) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'brew/Library/Homebrew/utils/shared_audits.rb', line 123

def gitlab(user, repo)
   = gitlab_repo_data(user, repo)

  return if .nil?

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

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

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

.gitlab_release(user, repo, tag, formula: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



90
91
92
93
94
95
96
97
98
# File 'brew/Library/Homebrew/utils/shared_audits.rb', line 90

def gitlab_release(user, repo, tag, formula: nil)
  release = gitlab_release_data(user, repo, tag)
  return unless release

  return if Date.parse(release["released_at"]) <= Date.today
  return if formula && GITLAB_PRERELEASE_ALLOWLIST[formula.name] == formula.version

  "#{tag} is a GitLab pre-release."
end

.gitlab_release_data(user, repo, tag) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'brew/Library/Homebrew/utils/shared_audits.rb', line 73

def gitlab_release_data(user, repo, tag)
  id = "#{user}/#{repo}/#{tag}"
  @gitlab_release_data ||= {}
  @gitlab_release_data[id] ||= begin
    out, _, status= curl_output(
      "https://gitlab.com/api/v4/projects/#{user}%2F#{repo}/releases/#{tag}", "--fail"
    )
    return unless status.success?

    JSON.parse(out)
  end

  @gitlab_release_data[id]
end

.gitlab_repo_data(user, repo) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



61
62
63
64
65
66
67
68
69
70
71
# File 'brew/Library/Homebrew/utils/shared_audits.rb', line 61

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_repo_data["#{user}/#{repo}"]
end

.gitlab_tag_from_url(url) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



180
181
182
183
184
185
# File 'brew/Library/Homebrew/utils/shared_audits.rb', line 180

def gitlab_tag_from_url(url)
  url = url.to_s
  url.match(%r{^https://gitlab\.com/[\w-]+/[\w-]+/-/archive/([^/]+)/})
     .to_a
     .second
end