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
- #committers(list) ⇒ Object
- #file_content(path) ⇒ Object
-
#initialize(url) ⇒ Repository
constructor
A new instance of Repository.
- #issues ⇒ Object
- #issues_since(date) ⇒ Object
- #issues_since_tag(tag = nil) ⇒ Object
- #merge_requests ⇒ Object
- #pull_requests ⇒ Object
- #tags ⇒ Object
- #verified(item) ⇒ 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
132 133 134 135 136 137 138 139 |
# File 'lib/denmark/repository.rb', line 132 def commit(sha) case @flavor when :github, :gitlab @client.commit(@repo, sha) else Array.new end end |
#commit_date(sha) ⇒ Object
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/denmark/repository.rb', line 150 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 nil end end |
#commits ⇒ Object
141 142 143 144 145 146 147 148 |
# File 'lib/denmark/repository.rb', line 141 def commits case @flavor when :github, :gitlab @client.commits(@repo) else Array.new end end |
#commits_since_tag(tag = nil) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/denmark/repository.rb', line 161 def commits_since_tag(tag = nil) tag ||= [0] case @flavor when :github @client.commits_since(@repo, commit_date(tag.commit.sha)) when :gitlab @client.commits(@repo, since: tag.commit.created_at) else Array.new end end |
#commits_to_file(path) ⇒ Object
174 175 176 177 178 179 180 181 |
# File 'lib/denmark/repository.rb', line 174 def commits_to_file(path) case @flavor when :github, :gitlab @client.commits(@repo, path: path) else Array.new end end |
#committers(list) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/denmark/repository.rb', line 80 def committers(list) list = Array(list) case @flavor when :github list.reduce(Array.new) do |acc, item| acc << (item.&.login || commit(item.commit.sha)..login) end when :gitlab list.reduce(Array.new) do |acc, item| acc << item.commit. end else Array.new end end |
#file_content(path) ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/denmark/repository.rb', line 105 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 |
#issues_since(date) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/denmark/repository.rb', line 69 def issues_since(date) case @flavor when :github @client.issues(@repo, {:state => 'open', :since=> date}).reject {|i| i[:pull_request] } when :gitlab @client.issues(@repo, updated_after: date, scope: 'all') else Array.new end end |
#issues_since_tag(tag = nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/denmark/repository.rb', line 57 def issues_since_tag(tag = nil) tag ||= [0] case @flavor when :github issues_since(commit_date(tag.commit.sha)) when :gitlab issues_since(tag.commit.created_at) 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
96 97 98 99 100 101 102 103 |
# File 'lib/denmark/repository.rb', line 96 def case @flavor when :github, :gitlab @client.(@repo) else Array.new end end |
#verified(item) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/denmark/repository.rb', line 116 def verified(item) case @flavor when :github if item.commit.verification.nil? commit(item.commit.sha).commit.verification.verified else item.commit.verification&.verified end when :gitlab commit(tag.commit.id).verification.verification_status == 'verified' else false end end |