cobench 0.0.9 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83be84557db1c5b0954853d6ceb77d18fc916628568220c65f9f6b9f0e190883
4
- data.tar.gz: 30c59ad9a54156120fbdb126b2ff33277b402a23d59a1efa50f602dd21e72d19
3
+ metadata.gz: 1a879b4cc5dd8f07f65060329407a6d7fd5892f79eb3bcdf79e5e5c6efd9af84
4
+ data.tar.gz: '058b53022f131002e0ea77729765496da7d852fc7ef117b6b93530a73ad209da'
5
5
  SHA512:
6
- metadata.gz: 6e320aea23c4a7bd7bffadb17e235dc24a607ec69ff82c392a07fb403442171a2366a631700a3907cd99246cdd93286c1524ecb469ea1bbf8be68c93689d1053
7
- data.tar.gz: 91fe1ed2ec75767b9bc2f5f67f62785e01bec6662a81ee3e798367af5dde1c96ef665f05897cb25d4caa733bc8675e8aeb975562f35424ad107cf36054c6464c
6
+ metadata.gz: fa959471fd51971a38acc61a25eb5007d622905be18eee168b4d71a56aa3c6246672f95d70d099860d09ab6fc4fb2e51e8d9c3639f20bffc33da44b9752dcc66
7
+ data.tar.gz: ea804c169413c276554397f4a79742b1c718b42c385d7911aa7561195100f1e8a3a15fa4f7de1ac172ca4801067690ae3cbda612dcf7b6fa709f189cc4c95c3e
data/assets/index.xsl CHANGED
@@ -24,6 +24,8 @@ SOFTWARE.
24
24
  -->
25
25
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
26
26
  <xsl:output encoding="UTF-8" method="html"/>
27
+ <xsl:param name="version"/>
28
+ <xsl:key name="titles" match="/cobench/titles/title" use="."/>
27
29
  <xsl:template match="/">
28
30
  <html>
29
31
  <head>
@@ -46,7 +48,7 @@ SOFTWARE.
46
48
  .num { text-align: right; }
47
49
  .left { border-bottom: 0; }
48
50
  header { text-align: center; }
49
- footer { text-align: center; font-size: 0.8em; }
51
+ footer { text-align: center; font-size: 0.8em; line-height: 1.2em; color: gray; }
50
52
  article { width: 60em; border: 0; }
51
53
  .sorter { cursor: pointer; }
52
54
  </style>
@@ -69,10 +71,20 @@ SOFTWARE.
69
71
  <xsl:text>The page was generated by </xsl:text>
70
72
  <a href="https://github.com/yegor256/cobench">
71
73
  <xsl:text>cobench</xsl:text>
74
+ <xsl:text> </xsl:text>
75
+ <xsl:value-of select="$version"/>
72
76
  </a>
73
77
  <xsl:text> on </xsl:text>
74
78
  <xsl:value-of select="cobench/@time"/>
75
- <xsl:text>.</xsl:text>
79
+ <xsl:text>. </xsl:text>
80
+ <xsl:text>"Pulls" is the total number of pull requests created by the user and merged. </xsl:text>
81
+ <xsl:text>"Issues" is the total number of issues submitted by the user. </xsl:text>
82
+ <xsl:text>"Commits" is the total number of commits authored by the user. </xsl:text>
83
+ <xsl:text>"Score" is an arithmetic summary of all other numbers with multipliers: </xsl:text>
84
+ <xsl:text>one Pull costs 100 points, </xsl:text>
85
+ <xsl:text>one Issue 50 points, </xsl:text>
86
+ <xsl:text>one Commit 5 points, </xsl:text>
87
+ <xsl:text>one HoC 1 point.</xsl:text>
76
88
  </p>
77
89
  <p>
78
90
  <xsl:text>The numbers you see reflect the activity of the last </xsl:text>
@@ -91,7 +103,7 @@ SOFTWARE.
91
103
  <thead>
92
104
  <tr>
93
105
  <th/>
94
- <xsl:for-each select="title">
106
+ <xsl:for-each select="title[generate-id() = generate-id(key('titles', .)[1])]">
95
107
  <xsl:sort select="."/>
96
108
  <th class="sorter num">
97
109
  <xsl:value-of select="."/>
data/bin/cobench CHANGED
@@ -51,6 +51,7 @@ opts = Slop.parse(args, strict: true, help: true) do |o|
51
51
  o.string '--to', 'Directory where to save all files to', default: './cobench'
52
52
  o.string '--token', 'GitHub authentication token'
53
53
  o.array '--coder', 'GitHub nickname of a coder to track'
54
+ o.array '--metrics', 'Names of metrics to use (all by default)'
54
55
  o.array '--include', 'Mask of GitHub repo to include, e.g. yegor256/*'
55
56
  o.array '--exclude', 'Mask of GitHub repo to exclude'
56
57
  end
@@ -91,28 +92,56 @@ begin
91
92
  end
92
93
  api.auto_paginate = true
93
94
  api = Obk.new(api, pause: 2000)
95
+ loog.info("Reading GitHub data for the last #{opts[:days]} days")
94
96
  titles = {}
95
97
  opts[:coder].each do |u|
96
98
  loog.info("Scanning #{u}...")
97
99
  data[u] = {}
98
100
  Dir[File.join(__dir__, '../lib/cobench/metrics/*.rb')].each do |f|
99
101
  name = File::basename(f).split('.')[0]
102
+ if !opts[:metrics].empty? && !opts[:metrics].include?(name)
103
+ loog.info("Ignoring #{u}/#{name} due to --metrics")
104
+ next
105
+ end
100
106
  type = "Cobench::#{name.capitalize}"
101
107
  loog.info("Reading #{u}/#{name}...")
102
108
  require_relative f
103
109
  m = type.split('::').reduce(Module, :const_get).new(api, u, opts)
104
110
  if opts.dry?
105
- measures = [{ title: 'Mock', total: Random.new.rand(100), href: 'https://github.com/' }]
111
+ measures = [
112
+ { title: 'Issues', total: Random.new.rand(100), href: 'https://github.com/' },
113
+ { title: 'Pulls', total: Random.new.rand(100), href: '' },
114
+ { title: 'HoC', total: Random.new.rand(100), href: '' },
115
+ { title: 'HoC', total: Random.new.rand(100), href: '' }
116
+ ]
106
117
  else
107
118
  measures = m.take(loog)
108
119
  end
109
120
  measures.each do |d|
110
- data[u][d[:title]] = { total: d[:total], href: d[:href] }
121
+ before = 0
122
+ before += data[u][d[:title]][:total] if data[u][d[:title]] != nil
123
+ data[u][d[:title]] = { total: d[:total] + before, href: d[:href] }
111
124
  titles[d[:title]] = d[:title]
112
125
  loog.info("The value of #{u}/#{d[:title]} is #{d[:total]}")
113
126
  end
114
127
  end
115
128
  end
129
+ data.each do |u, ms|
130
+ score = ms.map do |t, h|
131
+ h[:total] * if t == 'HoC'
132
+ 1
133
+ elsif t == 'Pulls'
134
+ 100
135
+ elsif t == 'Issues'
136
+ 50
137
+ elsif t == 'Commits'
138
+ 5
139
+ else
140
+ raise "Unknown title '#{t}'"
141
+ end
142
+ end.inject(0, :+)
143
+ data[u]['Score'] = { total: score, href: '' }
144
+ end
116
145
  builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
117
146
  xml.cobench(time: Time.now, days: opts[:days]) do
118
147
  xml.titles do
@@ -141,7 +170,7 @@ begin
141
170
  File.write(index, xml)
142
171
  loog.debug("XML saved to #{index} (#{File.size(index)} bytes)")
143
172
  xslt = Nokogiri::XSLT(File.read(File.join(__dir__, '../assets/index.xsl')))
144
- html = xslt.transform(Nokogiri::XML(xml))
173
+ html = xslt.transform(Nokogiri::XML(xml), 'version' => "'#{Cobench::VERSION}'")
145
174
  loog.debug(html)
146
175
  front = File.join(home, 'index.html')
147
176
  File.write(front, html)
@@ -0,0 +1,64 @@
1
+ # Copyright (c) 2022 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require 'iri'
22
+ require_relative '../match'
23
+
24
+ # Commits in GitHub API.
25
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
26
+ # Copyright:: Copyright (c) 2022 Yegor Bugayenko
27
+ # License:: MIT
28
+ class Cobench::Commits
29
+ def initialize(api, user, opts)
30
+ @api = api
31
+ @user = user
32
+ @opts = opts
33
+ end
34
+
35
+ def take(loog)
36
+ from = (Time.now - (60 * 60 * 24 * @opts[:days])).strftime('%Y-%m-%d')
37
+ q = "author:#{@user} author-date:>#{from}"
38
+ json = @api.search_commits(q)
39
+ loog.debug("Found #{json.total_count} commits")
40
+ hoc = 0
41
+ total = json.items.count do |c|
42
+ sha = c.sha
43
+ repo = c.repository.full_name
44
+ next unless Cobench::Match.new(@opts, loog).matches?(repo)
45
+ loog.debug("Including #{sha} in #{repo}")
46
+ json = @api.commit(repo, sha)
47
+ hocs = json.stats.total
48
+ loog.debug("Found #{hocs} HoC in #{sha}")
49
+ hoc += hocs
50
+ end
51
+ [
52
+ {
53
+ title: 'Commits',
54
+ total: total,
55
+ href: Iri.new('https://github.com/search').add(q: q)
56
+ },
57
+ {
58
+ title: 'HoC',
59
+ total: hoc,
60
+ href: ''
61
+ }
62
+ ]
63
+ end
64
+ end
@@ -34,7 +34,7 @@ class Cobench::Issues
34
34
 
35
35
  def take(loog)
36
36
  from = (Time.now - (60 * 60 * 24 * @opts[:days])).strftime('%Y-%m-%d')
37
- q = "#{@user} in:comments type:issue author:#{@user} created:>#{from}"
37
+ q = "in:comments type:issue author:#{@user} created:>#{from}"
38
38
  json = @api.search_issues(q)
39
39
  loog.debug("Found #{json.total_count} issues")
40
40
  total = json.items.count do |p|
@@ -34,7 +34,7 @@ class Cobench::Pulls
34
34
 
35
35
  def take(loog)
36
36
  from = (Time.now - (60 * 60 * 24 * @opts[:days])).strftime('%Y-%m-%d')
37
- q = "#{@user} in:comments type:pr author:#{@user} is:merged closed:>#{from}"
37
+ q = "in:comments type:pr author:#{@user} is:merged closed:>#{from}"
38
38
  json = @api.search_issues(q)
39
39
  loog.debug("Found #{json.total_count} pull requests")
40
40
  hoc = 0
@@ -23,5 +23,5 @@
23
23
  # Copyright:: Copyright (c) 2022 Yegor Bugayenko
24
24
  # License:: MIT
25
25
  module Cobench
26
- VERSION = '0.0.9'.freeze
26
+ VERSION = '0.0.12'.freeze
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cobench
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-14 00:00:00.000000000 Z
11
+ date: 2022-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -252,6 +252,7 @@ files:
252
252
  - features/support/env.rb
253
253
  - lib/cobench/mask.rb
254
254
  - lib/cobench/match.rb
255
+ - lib/cobench/metrics/commits.rb
255
256
  - lib/cobench/metrics/issues.rb
256
257
  - lib/cobench/metrics/pulls.rb
257
258
  - lib/cobench/version.rb