Class: DeployLog::Github::Helper
- Inherits:
-
Object
- Object
- DeployLog::Github::Helper
- Defined in:
- lib/deploy_log/github/helper.rb
Constant Summary collapse
- LINE_FORMAT =
"%s (%s)\n - Created by %s\n - Branch: %s\n - Merged by %s on %s\n - Changes: %s\n -- %s\n\n"
Instance Method Summary collapse
-
#initialize(user_repo) ⇒ Helper
constructor
A new instance of Helper.
- #pulls_in_timeframe(date_start = nil, date_end = nil) ⇒ Object
- #search_pulls_by(value, field = :title) ⇒ Object
Constructor Details
#initialize(user_repo) ⇒ Helper
Returns a new instance of Helper.
10 11 12 13 |
# 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 |
Instance Method Details
#pulls_in_timeframe(date_start = nil, date_end = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# 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) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# 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 |