Module: SharedAudits Private

Defined in:
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.

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.


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'Library/Homebrew/utils/shared_audits.rb', line 63

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.


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'Library/Homebrew/utils/shared_audits.rb', line 32

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

  return if .nil?

  return "GitHub fork (not canonical repository)" if ["fork"]
  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_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 '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

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


48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'Library/Homebrew/utils/shared_audits.rb', line 48

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_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.


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

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