class DeployLog::Github::Helper
Constants
- LINE_FORMAT
Public Class Methods
new(user_repo)
click to toggle source
# File lib/deploy_log/github/helper.rb, line 10 def initialize(user_repo) @client = ::Octokit::Client.new(login: ENV['GITHUB_USER'], password: ENV['GITHUB_TOKEN']) @repo_location = user_repo end
Public Instance Methods
pulls_in_timeframe(date_start = nil, date_end = nil)
click to toggle source
# File lib/deploy_log/github/helper.rb, line 15 def pulls_in_timeframe(date_start = nil, date_end = nil) @client.auto_paginate = true list = @client.pull_requests(@repo_location, state: :closed, per_page: 500, sort: 'long-running' ) prs_covered = 0 File.open('/tmp/github-deploys.log', 'w+') do |f| list.each do |pr| next unless (date_start..date_end).cover? pr.merged_at prs_covered += 1 f.write( sprintf( LINE_FORMAT, pr.title, pr.html_url, pr.user.login, pr.head.ref, user_who_merged(pr.number), formatted_time(pr.merged_at, true), pr.diff_url, committers_for(pr.number).join("\n -- ") ) ) end f.write("============================================================\n#{prs_covered} PR(s) merged from #{date_start} to #{date_end}\n============================================================\n") end return ::Notify.warning("No pull requests have been merged in the requested date range (#{date_start} - #{date_end})") if prs_covered.zero? system('cat /tmp/github-deploys.log') end
search_pulls_by(value, field = :title)
click to toggle source
# File lib/deploy_log/github/helper.rb, line 54 def search_pulls_by(value, field = :title) list = @client.pull_requests(@repo_location, :state => :all, :per_page => 100 ) prs_covered = 0 File.open('/tmp/github-deploys.log', 'w+') do |f| list.each do |pr| next unless nested_hash_value(pr, field).match?(/#{value}\b/) prs_covered += 1 f.write( sprintf( LINE_FORMAT, pr.title, pr.html_url, pr.user.login, pr.head.ref, user_who_merged(pr.number), formatted_time(pr.merged_at, true), pr.diff_url, committers_for(pr.number).join("\n -- ") ) ) end f.write("============================================================\n#{prs_covered} PR(s) matched\n============================================================\n") end return ::Notify.warning("No pull requests match the requested term (#{value})") if prs_covered.zero? system('cat /tmp/github-deploys.log') end