Class: Denmark::Repository
- Inherits:
-
Object
- Object
- Denmark::Repository
- Defined in:
- lib/denmark/repository.rb
Instance Method Summary collapse
- #client ⇒ Object
- #commit(sha) ⇒ Object
- #commit_date(sha) ⇒ Object
- #commits ⇒ Object
- #commits_since_tag(tag = nil) ⇒ Object
- #commits_to_file(path) ⇒ Object
- #file_content(path) ⇒ Object
-
#initialize(url) ⇒ Repository
constructor
A new instance of Repository.
- #issues ⇒ Object
- #merge_requests ⇒ Object
- #pull_requests ⇒ Object
- #tags ⇒ Object
Constructor Details
#initialize(url) ⇒ Repository
Returns a new instance of Repository.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/denmark/repository.rb', line 4 def initialize(url) # This tool only makes sense for public repos, so don't bother to be too smart. case url when /github\.com/ require 'octokit' @flavor = :github @client = Octokit::Client.new(:access_token => Denmark.config(:github, :token)) @repo = Octokit::Repository.from_url(url).slug when /gitlab\.com/ require 'gitlab' @flavor = :gitlab @client = Gitlab.client( endpoint: 'https://gitlab.com/api/v4', private_token: Denmark.config(:gitlab, :token), ) @repo = URI.parse(url).path[1..-1] else raise "Unsupported git source: '#{url}'" end end |
Instance Method Details
#client ⇒ Object
27 28 29 |
# File 'lib/denmark/repository.rb', line 27 def client @client end |
#commit(sha) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/denmark/repository.rb', line 77 def commit(sha) case @flavor when :github, :gitlab @client.commit(@repo, sha) else Array.new end end |
#commit_date(sha) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/denmark/repository.rb', line 95 def commit_date(sha) case @flavor when :github @client.commit(@repo, sha).commit.committer.date.to_date when :gitlab @client.commit(@repo, sha).commit.created_at.to_date else Array.new end end |
#commits ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/denmark/repository.rb', line 86 def commits case @flavor when :github, :gitlab @client.commits(@repo) else Array.new end end |
#commits_since_tag(tag = nil) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/denmark/repository.rb', line 108 def commits_since_tag(tag = nil) tag ||= [0] case @flavor when :github @client.commits_since(@repo, tag.commit.committer.date) when :gitlab @client.commits(@repo, since: tag.commit.created_at) else Array.new end end |
#commits_to_file(path) ⇒ Object
121 122 123 124 125 126 127 128 |
# File 'lib/denmark/repository.rb', line 121 def commits_to_file(path) case @flavor when :github, :gitlab @client.commits(@repo, path: path) else Array.new end end |
#file_content(path) ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/denmark/repository.rb', line 66 def file_content(path) case @flavor when :github Base64.decode64(client.contents(@repo, :path => path).content) rescue nil when :gitlab client.file_contents(@repo, path) else '' end end |
#issues ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/denmark/repository.rb', line 46 def issues case @flavor when :github @client.issues(@repo).reject {|i| i[:pull_request] } when :gitlab @client.issues(@repo) else Array.new end end |
#merge_requests ⇒ Object
42 43 44 |
# File 'lib/denmark/repository.rb', line 42 def merge_requests pull_requests end |
#pull_requests ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/denmark/repository.rb', line 31 def pull_requests case @flavor when :github @client.issues(@repo).select {|i| i[:pull_request] } when :gitlab @client.merge_requests(@repo) else Array.new end end |
#tags ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/denmark/repository.rb', line 57 def case @flavor when :github, :gitlab @client.(@repo) else Array.new end end |