Class: Cobench::Pulls

Inherits:
Object
  • Object
show all
Defined in:
lib/cobench/metrics/pulls.rb

Overview

Pulls in GitHub API.

Author

Yegor Bugayenko ([email protected])

Copyright

Copyright © 2022 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(api, user, opts) ⇒ Pulls

Returns a new instance of Pulls.



29
30
31
32
33
# File 'lib/cobench/metrics/pulls.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
# File 'lib/cobench/metrics/pulls.rb', line 35

def take(loog)
  from = (Time.now - (60 * 60 * 24 * @opts[:days])).strftime('%Y-%m-%d')
  q = "#{@user} in:comments type:pr author:#{@user} is:merged closed:>#{from}"
  json = @api.search_issues(q)
  total = json.items.count do |p|
    pr = p.pull_request.url.split('/')[-1]
    repo = p.repository_url.split('/')[-2..-1].join('/')
    if @opts[:include].none? { |m| Cobench::Mask.new(m).matches?(repo) }
      loog.debug("Excluding #{repo}##{pr} due to lack of --include")
      next
    end
    if @opts[:exclude].any? { |m| Cobench::Mask.new(m).matches?(repo) }
      loog.debug("Excluding #{repo}##{pr} due to --exclude")
      next
    end
    loog.debug("Including #{repo}#{pr}")
  end
  [total, Iri.new('https://github.com/search').add(q: q)]
end