class Denmark::Repository
Public Class Methods
new(url)
click to toggle source
# 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
Public Instance Methods
client()
click to toggle source
# File lib/denmark/repository.rb, line 27 def client @client end
commit(sha)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# File lib/denmark/repository.rb, line 161 def commits_since_tag(tag = nil) tag ||= tags[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)
click to toggle source
# 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)
click to toggle source
# 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.author&.login || commit(item.commit.sha).author.login) end when :gitlab list.reduce(Array.new) do |acc, item| acc << item.commit.author_name end else Array.new end end
file_content(path)
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/denmark/repository.rb, line 57 def issues_since_tag(tag = nil) tag ||= tags[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()
click to toggle source
# File lib/denmark/repository.rb, line 42 def merge_requests pull_requests end
pull_requests()
click to toggle source
# 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
verified(item)
click to toggle source
# 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