Class: Cobench::Commits

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

Overview

Commits 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) ⇒ Commits

Returns a new instance of Commits.



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

def take(loog)
  from = (Time.now - (60 * 60 * 24 * @opts[:days])).strftime('%Y-%m-%d')
  q = "author:#{@user} author-date:>#{from} is:public merge:false"
  json = @api.search_commits(q)
  loog.debug("Found #{json.total_count} commits")
  hoc = 0
  total = json.items.count do |c|
    sha = c.sha
    repo = c.repository.full_name
    next unless Cobench::Match.new(@opts, loog).matches?(repo)
    loog.debug("Including #{sha} in #{repo}")
    json = @api.commit(repo, sha)
    next unless json
    hocs = json.stats.total
    loog.debug("Found #{hocs} HoC in #{sha}")
    hoc += hocs
  end
  [
    {
      title: 'Commits',
      total: total,
      href: Iri.new('https://github.com/search').add(q: q)
    },
    {
      title: 'HoC',
      total: hoc
    }
  ]
end