Class: OrganizationAudit::Repo
- Inherits:
-
Object
- Object
- OrganizationAudit::Repo
- Defined in:
- lib/organization_audit/repo.rb
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.
9 10 11 12 |
# File 'lib/organization_audit/repo.rb', line 9 def initialize(data, token=nil) @data = data @token = token end |
Class Method Details
.all(options) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/organization_audit/repo.rb', line 34 def self.all() user = if [:organization] "orgs/#{[:organization]}" elsif [:user] "users/#{[:user]}" else "user" end url = File.join(HOST, user, "repos") token = [:token] download_all_pages(url, headers(token)).map { |data| Repo.new(data, token) } end |
Instance Method Details
#clone_url ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/organization_audit/repo.rb', line 75 def clone_url if private? url.sub("https://", "git@").sub("/", ":") + ".git" else url + ".git" end end |
#content(file) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/organization_audit/repo.rb', line 48 def content(file) @content ||= {} @content[file] ||= begin if private? download_content_via_api(file) else download_content_via_raw(file) end end rescue OpenURI::HTTPError => e raise "Error downloading #{file} from #{url} (#{e})" unless e..start_with?("404") end |
#directory?(folder) ⇒ Boolean
87 88 89 |
# File 'lib/organization_audit/repo.rb', line 87 def directory?(folder) !!list(File.dirname(folder)).detect { |f| f["path"] == folder && f["type"] == "dir" } end |
#file_list(dir = ".") ⇒ Object
83 84 85 |
# File 'lib/organization_audit/repo.rb', line 83 def file_list(dir=".") list(dir).select { |f| f["type"] == "file" }.map { |file| file["path"] } end |
#gem? ⇒ Boolean
14 15 16 |
# File 'lib/organization_audit/repo.rb', line 14 def gem? !!gemspec_file end |
#gemspec_content ⇒ Object
18 19 20 |
# File 'lib/organization_audit/repo.rb', line 18 def gemspec_content content(gemspec_file) if gem? end |
#last_commiter ⇒ Object
69 70 71 72 73 |
# File 'lib/organization_audit/repo.rb', line 69 def last_commiter response = call_api("commits/#{branch}") committer = response["commit"]["committer"] "#{committer["name"]} <#{committer["email"]}>" end |
#name ⇒ Object
30 31 32 |
# File 'lib/organization_audit/repo.rb', line 30 def name api_url.split("/").last end |
#private? ⇒ Boolean
61 62 63 |
# File 'lib/organization_audit/repo.rb', line 61 def private? @data["private"] end |
#public? ⇒ Boolean
65 66 67 |
# File 'lib/organization_audit/repo.rb', line 65 def public? !private? end |
#to_s ⇒ Object
26 27 28 |
# File 'lib/organization_audit/repo.rb', line 26 def to_s "#{url} -- #{last_commiter}" end |
#url ⇒ Object
22 23 24 |
# File 'lib/organization_audit/repo.rb', line 22 def url api_url.sub("api.", "").sub("/repos", "") end |