cobench 0.0.8 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1eaf9208a53326a257503d91e54aae018b2dd0964c0ec11ddde8d8b392a036cc
4
- data.tar.gz: 5b1d155907221ec14edfbd5ca674f345531303e383c2f13aae88335bdc35c1cd
3
+ metadata.gz: 106c637350232c212145a1a648680688634f9b44f488fbe660f2003666faba23
4
+ data.tar.gz: eaff88cb6edbc88d3d5616df41d1344c38380b38aca26b642987420f73805a93
5
5
  SHA512:
6
- metadata.gz: 8c155780a0a14a843daf36336d66e5a3216b9886b0da46503d0a44ad3994a7e71eb2d4ee15c7bc4edfe3c236591673c7339e918ce9afbe697f7ca5f4bb415614
7
- data.tar.gz: 2e7ca41724d9768abfbad82c6cbd2bff175b30783644c4af24650183f5868e65050832d7a72d2f776aa080d30afdb2aaaa4a82d315c5279e8f61a350e7cca72f
6
+ metadata.gz: 73f87f462a82919c5d435237276952a5b94be9397a053b68c17ad636e50e0b5c71dbe54b6d3118a19600e6eaf9bbd5d113e350ebf5c1330e635f5b38fd49e3b3
7
+ data.tar.gz: fd592b9422b5f48802723027eabcc93ba5a7a23d9f2eedf17d0cd184acf014a7668c1464e3821750a650da4771c81b9b936cdaf02a2fa9c3e43b7ab0ccc988dd
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,18 +92,26 @@ 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: 'https://github.com/' }
114
+ ]
106
115
  else
107
116
  measures = m.take(loog)
108
117
  end
@@ -113,6 +122,22 @@ begin
113
122
  end
114
123
  end
115
124
  end
125
+ data.each do |u, ms|
126
+ score = ms.map do |t, h|
127
+ h[:total] * if t == 'HoC'
128
+ 1
129
+ elsif t == 'Pulls'
130
+ 100
131
+ elsif t == 'Issues'
132
+ 50
133
+ elsif t == 'Commits'
134
+ 5
135
+ else
136
+ raise "Unknown title '#{t}'"
137
+ end
138
+ end.inject(0, :+)
139
+ data[u]['Score'] = { total: score, href: '' }
140
+ end
116
141
  builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
117
142
  xml.cobench(time: Time.now, days: opts[:days]) do
118
143
  xml.titles do
@@ -141,7 +166,7 @@ begin
141
166
  File.write(index, xml)
142
167
  loog.debug("XML saved to #{index} (#{File.size(index)} bytes)")
143
168
  xslt = Nokogiri::XSLT(File.read(File.join(__dir__, '../assets/index.xsl')))
144
- html = xslt.transform(Nokogiri::XML(xml))
169
+ html = xslt.transform(Nokogiri::XML(xml), 'version' => "'#{Cobench::VERSION}'")
145
170
  loog.debug(html)
146
171
  front = File.join(home, 'index.html')
147
172
  File.write(front, html)
data/lib/cobench/match.rb CHANGED
@@ -25,17 +25,18 @@ require_relative 'mask'
25
25
  # Copyright:: Copyright (c) 2022 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  class Cobench::Match
28
- def initialize(opts)
28
+ def initialize(opts, loog)
29
29
  @opts = opts
30
+ @loog = loog
30
31
  end
31
32
 
32
33
  def matches?(repo)
33
34
  if !@opts[:include].empty? && @opts[:include].none? { |m| Cobench::Mask.new(m).matches?(repo) }
34
- loog.debug("Excluding #{repo}##{pr} due to lack of --include")
35
+ @loog.debug("Excluding #{repo} due to lack of --include")
35
36
  return false
36
37
  end
37
38
  if @opts[:exclude].any? { |m| Cobench::Mask.new(m).matches?(repo) }
38
- loog.debug("Excluding #{repo}##{pr} due to --exclude")
39
+ @loog.debug("Excluding #{repo} due to --exclude")
39
40
  return false
40
41
  end
41
42
  true
@@ -0,0 +1,54 @@
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
+ total = json.items.count do |c|
41
+ sha = c.sha
42
+ repo = c.repository.full_name
43
+ next unless Cobench::Match.new(@opts, loog).matches?(repo)
44
+ loog.debug("Including #{sha} in #{repo}")
45
+ end
46
+ [
47
+ {
48
+ title: 'Commits',
49
+ total: total,
50
+ href: Iri.new('https://github.com/search').add(q: q)
51
+ }
52
+ ]
53
+ end
54
+ end
@@ -34,13 +34,13 @@ 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|
41
41
  pr = p.url.split('/')[-1]
42
42
  repo = p.repository_url.split('/')[-2..-1].join('/')
43
- next unless Cobench::Match.new(@opts).matches?(repo)
43
+ next unless Cobench::Match.new(@opts, loog).matches?(repo)
44
44
  loog.debug("Including #{repo}#{pr}")
45
45
  end
46
46
  [
@@ -34,14 +34,14 @@ 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
41
41
  total = json.items.count do |p|
42
42
  pr = p.pull_request.url.split('/')[-1]
43
43
  repo = p.repository_url.split('/')[-2..-1].join('/')
44
- next unless Cobench::Match.new(@opts).matches?(repo)
44
+ next unless Cobench::Match.new(@opts, loog).matches?(repo)
45
45
  pr_json = @api.pull_request(repo, pr)
46
46
  hocs = pr_json.additions + pr_json.deletions
47
47
  hoc += hocs
@@ -23,5 +23,5 @@
23
23
  # Copyright:: Copyright (c) 2022 Yegor Bugayenko
24
24
  # License:: MIT
25
25
  module Cobench
26
- VERSION = '0.0.8'.freeze
26
+ VERSION = '0.0.11'.freeze
27
27
  end
@@ -0,0 +1,41 @@
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 'minitest/autorun'
22
+ require 'loog'
23
+ require_relative '../lib/cobench/match'
24
+
25
+ # Test for Match.
26
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
27
+ # Copyright:: Copyright (c) 2022 Yegor Bugayenko
28
+ # License:: MIT
29
+ class TestMatch < Minitest::Test
30
+ def test_positive
31
+ loog = Loog::NULL
32
+ opts = { include: [], exclude: [] }
33
+ assert Cobench::Match.new(opts, loog).matches?('foo/bar')
34
+ end
35
+
36
+ def test_negative
37
+ loog = Loog::NULL
38
+ opts = { include: ['*/*'], exclude: ['foo/*'] }
39
+ assert !Cobench::Match.new(opts, loog).matches?('foo/bar')
40
+ end
41
+ 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.8
4
+ version: 0.0.11
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,12 +252,14 @@ 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
258
259
  - logo.svg
259
260
  - test/test__helper.rb
260
261
  - test/test_mask.rb
262
+ - test/test_match.rb
261
263
  homepage: http://github.com/yegor256/cobench
262
264
  licenses:
263
265
  - MIT