Class: Cobench::Reviews
- Inherits:
-
Object
- Object
- Cobench::Reviews
- Defined in:
- lib/cobench/metrics/reviews.rb
Overview
Reviews in GitHub API.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2022 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#initialize(api, user, opts) ⇒ Reviews
constructor
A new instance of Reviews.
- #take(loog) ⇒ Object
Constructor Details
#initialize(api, user, opts) ⇒ Reviews
Returns a new instance of Reviews.
29 30 31 32 33 |
# File 'lib/cobench/metrics/reviews.rb', line 29 def initialize(api, user, opts) @api = api @user = user @opts = opts end |
Instance Method Details
#take(loog) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/cobench/metrics/reviews.rb', line 35 def take(loog) from = (Time.now - (60 * 60 * 24 * @opts[:days])).strftime('%Y-%m-%d') q = "reviewed-by:#{@user} merged:>#{from}" json = @api.search_issues(q) loog.debug("Found #{json.total_count} reviews") msgs = 0 total = json.items.count do |p| pr = p.pull_request.url.split('/')[-1] repo = p.repository_url.split('/')[-2..-1].join('/') next unless Cobench::Match.new(@opts, loog).matches?(repo) loog.debug("Including #{repo}##{pr} reviewed by @#{@user}") posted = @api.pull_request_comments(repo, pr).count { |c| c[:user][:login].downcase == @user } posted += @api.issue_comments(repo, pr).count { |c| c[:user][:login].downcase == @user } loog.debug("#{posted} messages posted by @#{@user} to #{repo}##{pr}") msgs += posted end [ { title: 'Reviews', total: total, href: Iri.new('https://github.com/search').add(q: q) }, { title: 'Msgs', total: msgs } ] end |