Class: OrganizationAudit::Repo
- Inherits:
-
Object
- Object
- OrganizationAudit::Repo
- Defined in:
- lib/organization_audit/repo.rb
Defined Under Namespace
Classes: RequestError
Constant Summary collapse
- HOST =
"https://api.github.com"
Class Method Summary collapse
Instance Method Summary collapse
- #clone_url ⇒ Object
- #content(file) ⇒ Object
- #directory?(folder) ⇒ Boolean
- #file_list(dir = ".") ⇒ Object
- #gem? ⇒ Boolean
- #gemspec_content ⇒ Object
-
#initialize(data, token = nil) ⇒ Repo
constructor
A new instance of Repo.
- #last_commiter ⇒ Object
- #name ⇒ Object
- #private? ⇒ Boolean
- #public? ⇒ Boolean
- #to_s ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(data, token = nil) ⇒ Repo
Returns a new instance of Repo.
20 21 22 23 |
# File 'lib/organization_audit/repo.rb', line 20 def initialize(data, token=nil) @data = data @token = token end |
Class Method Details
.all(organization: nil, user: nil, max_pages: nil, token: nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/organization_audit/repo.rb', line 45 def self.all(organization: nil, user: nil, max_pages: nil, token: nil) user = if organization "orgs/#{organization}" elsif user "users/#{user}" else "user" end url = File.join(HOST, user, "repos") download_all_pages(url, headers(token), max_pages: max_pages).map { |data| Repo.new(data, token) } end |
Instance Method Details
#clone_url ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/organization_audit/repo.rb', line 84 def clone_url if private? url.sub("https://", "git@").sub("/", ":") + ".git" else url + ".git" end end |
#content(file) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/organization_audit/repo.rb', line 58 def content(file) (@content ||= {})[file] ||= begin if private? download_content_via_api(file) else download_content_via_raw(file) end end rescue RequestError => e raise unless e.code == 404 end |
#directory?(folder) ⇒ Boolean
96 97 98 |
# File 'lib/organization_audit/repo.rb', line 96 def directory?(folder) !!list(File.dirname(folder)).detect { |f| f["path"] == folder && f["type"] == "dir" } end |
#file_list(dir = ".") ⇒ Object
92 93 94 |
# File 'lib/organization_audit/repo.rb', line 92 def file_list(dir=".") list(dir).select { |f| f["type"] == "file" }.map { |file| file["path"] } end |
#gem? ⇒ Boolean
25 26 27 |
# File 'lib/organization_audit/repo.rb', line 25 def gem? !!gemspec_file end |
#gemspec_content ⇒ Object
29 30 31 |
# File 'lib/organization_audit/repo.rb', line 29 def gemspec_content content(gemspec_file) if gem? end |
#last_commiter ⇒ Object
78 79 80 81 82 |
# File 'lib/organization_audit/repo.rb', line 78 def last_commiter response = call_api("commits/#{branch}") committer = response["commit"]["committer"] "#{committer["name"]} <#{committer["email"]}>" end |
#name ⇒ Object
41 42 43 |
# File 'lib/organization_audit/repo.rb', line 41 def name api_url.split("/").last end |
#private? ⇒ Boolean
70 71 72 |
# File 'lib/organization_audit/repo.rb', line 70 def private? @data["private"] end |
#public? ⇒ Boolean
74 75 76 |
# File 'lib/organization_audit/repo.rb', line 74 def public? !private? end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/organization_audit/repo.rb', line 37 def to_s "#{url} -- #{last_commiter}" end |
#url ⇒ Object
33 34 35 |
# File 'lib/organization_audit/repo.rb', line 33 def url api_url.sub("api.", "").sub("/repos", "") end |