cobench 0.0.6 → 0.0.9

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: c86ef1d63046d93343152ea0cebea85bd7ff9bd985b2147d8a7320d0a6485980
4
- data.tar.gz: ef148324cf9faddaa324ecca18629b030f0a29a2c40224005fb5fadd2e49bcca
3
+ metadata.gz: 83be84557db1c5b0954853d6ceb77d18fc916628568220c65f9f6b9f0e190883
4
+ data.tar.gz: 30c59ad9a54156120fbdb126b2ff33277b402a23d59a1efa50f602dd21e72d19
5
5
  SHA512:
6
- metadata.gz: '0229a62e2c9748230de2d0123d16cdf8a25da67f1cdefcd60648df8a15235a84f2a903de9ac1203ecfc1da7fea494105c2f067da93d35b8cb3d73d05c0d2b255'
7
- data.tar.gz: 85592eeded980ef5b7728ccf79adabe9a85e46333f4cb16b10c864cc3e8a668a3e6c09848b91d6e26e0084d4fb1374ec41188df6c7fd2916ed35d104d13316f9
6
+ metadata.gz: 6e320aea23c4a7bd7bffadb17e235dc24a607ec69ff82c392a07fb403442171a2366a631700a3907cd99246cdd93286c1524ecb469ea1bbf8be68c93689d1053
7
+ data.tar.gz: 91fe1ed2ec75767b9bc2f5f67f62785e01bec6662a81ee3e798367af5dde1c96ef665f05897cb25d4caa733bc8675e8aeb975562f35424ad107cf36054c6464c
data/assets/index.xsl CHANGED
@@ -23,8 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
23
  SOFTWARE.
24
24
  -->
25
25
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
26
- <xsl:output encoding="UTF-8" method="xml"/>
27
- <xsl:key name="metrics" match="/cobench/coders/coder/metrics/m" use="@id"/>
26
+ <xsl:output encoding="UTF-8" method="html"/>
28
27
  <xsl:template match="/">
29
28
  <html>
30
29
  <head>
@@ -35,15 +34,16 @@ SOFTWARE.
35
34
  <link rel="icon" href="https://raw.githubusercontent.com/yegor256/cobench/master/logo.svg" type="image/svg"/>
36
35
  <link href="https://cdn.jsdelivr.net/gh/yegor256/tacit@gh-pages/tacit-css.min.css" rel="stylesheet"/>
37
36
  <link href="https://cdn.jsdelivr.net/gh/yegor256/drops@gh-pages/drops.min.css" rel="stylesheet"/>
38
- <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
39
- <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.31.3/js/jquery.tablesorter.min.js"></script>
37
+ <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"/>
38
+ <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.31.3/js/jquery.tablesorter.min.js"/>
40
39
  <script type="text/javascript">
41
40
  $(function() {
42
41
  $("#metrics").tablesorter();
43
42
  });
44
43
  </script>
45
44
  <style>
46
- td, th { text-align: right; font-family: monospace; font-size: 18px; }
45
+ td, th { font-family: monospace; font-size: 18px; }
46
+ .num { text-align: right; }
47
47
  .left { border-bottom: 0; }
48
48
  header { text-align: center; }
49
49
  footer { text-align: center; font-size: 0.8em; }
@@ -59,7 +59,10 @@ SOFTWARE.
59
59
  </p>
60
60
  </header>
61
61
  <article>
62
- <xsl:apply-templates select="cobench/coders"/>
62
+ <table id="metrics">
63
+ <xsl:apply-templates select="cobench/titles"/>
64
+ <xsl:apply-templates select="cobench/coders"/>
65
+ </table>
63
66
  </article>
64
67
  <footer>
65
68
  <p>
@@ -84,22 +87,23 @@ SOFTWARE.
84
87
  </body>
85
88
  </html>
86
89
  </xsl:template>
90
+ <xsl:template match="cobench/titles">
91
+ <thead>
92
+ <tr>
93
+ <th/>
94
+ <xsl:for-each select="title">
95
+ <xsl:sort select="."/>
96
+ <th class="sorter num">
97
+ <xsl:value-of select="."/>
98
+ </th>
99
+ </xsl:for-each>
100
+ </tr>
101
+ </thead>
102
+ </xsl:template>
87
103
  <xsl:template match="cobench/coders">
88
- <table id="metrics">
89
- <thead>
90
- <tr>
91
- <th/>
92
- <xsl:for-each select="coder/metrics/m[generate-id() = generate-id(key('metrics', @id)[1])]">
93
- <th class="sorter">
94
- <xsl:value-of select="@id"/>
95
- </th>
96
- </xsl:for-each>
97
- </tr>
98
- </thead>
99
- <tbody>
100
- <xsl:apply-templates select="coder"/>
101
- </tbody>
102
- </table>
104
+ <tbody>
105
+ <xsl:apply-templates select="coder"/>
106
+ </tbody>
103
107
  </xsl:template>
104
108
  <xsl:template match="coder">
105
109
  <tr>
@@ -109,14 +113,24 @@ SOFTWARE.
109
113
  <xsl:value-of select="@id"/>
110
114
  </a>
111
115
  </td>
112
- <xsl:apply-templates select="metrics/m"/>
116
+ <xsl:for-each select="metrics/m">
117
+ <xsl:sort select="@id"/>
118
+ <xsl:apply-templates select="."/>
119
+ </xsl:for-each>
113
120
  </tr>
114
121
  </xsl:template>
115
122
  <xsl:template match="m">
116
- <td>
117
- <a href="{@href}">
118
- <xsl:value-of select="."/>
119
- </a>
123
+ <td class="num">
124
+ <xsl:choose>
125
+ <xsl:when test="@href">
126
+ <a href="{@href}">
127
+ <xsl:value-of select="."/>
128
+ </a>
129
+ </xsl:when>
130
+ <xsl:otherwise>
131
+ <xsl:value-of select="."/>
132
+ </xsl:otherwise>
133
+ </xsl:choose>
120
134
  </td>
121
135
  </xsl:template>
122
136
  <xsl:template match="node()|@*">
data/bin/cobench CHANGED
@@ -91,6 +91,7 @@ begin
91
91
  end
92
92
  api.auto_paginate = true
93
93
  api = Obk.new(api, pause: 2000)
94
+ titles = {}
94
95
  opts[:coder].each do |u|
95
96
  loog.info("Scanning #{u}...")
96
97
  data[u] = {}
@@ -101,30 +102,38 @@ begin
101
102
  require_relative f
102
103
  m = type.split('::').reduce(Module, :const_get).new(api, u, opts)
103
104
  if opts.dry?
104
- v, t = [42, 'https://github.com/']
105
+ measures = [{ title: 'Mock', total: Random.new.rand(100), href: 'https://github.com/' }]
105
106
  else
106
- v, t = m.take(loog)
107
+ measures = m.take(loog)
108
+ end
109
+ measures.each do |d|
110
+ data[u][d[:title]] = { total: d[:total], href: d[:href] }
111
+ titles[d[:title]] = d[:title]
112
+ loog.info("The value of #{u}/#{d[:title]} is #{d[:total]}")
107
113
  end
108
- data[u][name] = [v, t]
109
- loog.info("The value of #{u}/#{name} is #{v}")
110
114
  end
111
115
  end
112
116
  builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
113
- xml.cobench(time: Time.now, days: opts[:days]) {
114
- xml.coders {
117
+ xml.cobench(time: Time.now, days: opts[:days]) do
118
+ xml.titles do
119
+ data.map { |_, ms| ms.keys }.flatten.each do |t|
120
+ xml.title t
121
+ end
122
+ end
123
+ xml.coders do
115
124
  data.each do |u, ms|
116
- xml.coder(id: u) {
117
- xml.metrics {
125
+ xml.coder(id: u) do
126
+ xml.metrics do
118
127
  ms.each do |k, v|
119
- xml.m(id: k, href: v[1]) {
120
- xml.text v[0]
121
- }
128
+ xml.m(id: k, href: v[:href]) do
129
+ xml.text v[:total]
130
+ end
122
131
  end
123
- }
124
- }
132
+ end
133
+ end
125
134
  end
126
- }
127
- }
135
+ end
136
+ end
128
137
  end
129
138
  index = File.join(home, 'index.xml')
130
139
  xml = builder.to_xml
@@ -0,0 +1,44 @@
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_relative 'mask'
22
+
23
+ # Match of masks.
24
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
25
+ # Copyright:: Copyright (c) 2022 Yegor Bugayenko
26
+ # License:: MIT
27
+ class Cobench::Match
28
+ def initialize(opts, loog)
29
+ @opts = opts
30
+ @loog = loog
31
+ end
32
+
33
+ def matches?(repo)
34
+ if !@opts[:include].empty? && @opts[:include].none? { |m| Cobench::Mask.new(m).matches?(repo) }
35
+ @loog.debug("Excluding #{repo} due to lack of --include")
36
+ return false
37
+ end
38
+ if @opts[:exclude].any? { |m| Cobench::Mask.new(m).matches?(repo) }
39
+ @loog.debug("Excluding #{repo} due to --exclude")
40
+ return false
41
+ end
42
+ true
43
+ end
44
+ end
@@ -19,7 +19,7 @@
19
19
  # SOFTWARE.
20
20
 
21
21
  require 'iri'
22
- require_relative '../mask'
22
+ require_relative '../match'
23
23
 
24
24
  # Issues in GitHub API.
25
25
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -36,19 +36,19 @@ class Cobench::Issues
36
36
  from = (Time.now - (60 * 60 * 24 * @opts[:days])).strftime('%Y-%m-%d')
37
37
  q = "#{@user} in:comments type:issue author:#{@user} created:>#{from}"
38
38
  json = @api.search_issues(q)
39
+ loog.debug("Found #{json.total_count} issues")
39
40
  total = json.items.count do |p|
40
41
  pr = p.url.split('/')[-1]
41
42
  repo = p.repository_url.split('/')[-2..-1].join('/')
42
- if @opts[:include].none? { |m| Cobench::Mask.new(m).matches?(repo) }
43
- loog.debug("Excluding #{repo}##{pr} due to lack of --include")
44
- next
45
- end
46
- if @opts[:exclude].any? { |m| Cobench::Mask.new(m).matches?(repo) }
47
- loog.debug("Excluding #{repo}##{pr} due to --exclude")
48
- next
49
- end
43
+ next unless Cobench::Match.new(@opts, loog).matches?(repo)
50
44
  loog.debug("Including #{repo}#{pr}")
51
45
  end
52
- [total, Iri.new('https://github.com/search').add(q: q)]
46
+ [
47
+ {
48
+ title: 'Issues',
49
+ total: total,
50
+ href: Iri.new('https://github.com/search').add(q: q)
51
+ }
52
+ ]
53
53
  end
54
54
  end
@@ -19,7 +19,7 @@
19
19
  # SOFTWARE.
20
20
 
21
21
  require 'iri'
22
- require_relative '../mask'
22
+ require_relative '../match'
23
23
 
24
24
  # Pulls in GitHub API.
25
25
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -36,19 +36,28 @@ class Cobench::Pulls
36
36
  from = (Time.now - (60 * 60 * 24 * @opts[:days])).strftime('%Y-%m-%d')
37
37
  q = "#{@user} in:comments type:pr author:#{@user} is:merged closed:>#{from}"
38
38
  json = @api.search_issues(q)
39
+ loog.debug("Found #{json.total_count} pull requests")
40
+ hoc = 0
39
41
  total = json.items.count do |p|
40
42
  pr = p.pull_request.url.split('/')[-1]
41
43
  repo = p.repository_url.split('/')[-2..-1].join('/')
42
- if @opts[:include].none? { |m| Cobench::Mask.new(m).matches?(repo) }
43
- loog.debug("Excluding #{repo}##{pr} due to lack of --include")
44
- next
45
- end
46
- if @opts[:exclude].any? { |m| Cobench::Mask.new(m).matches?(repo) }
47
- loog.debug("Excluding #{repo}##{pr} due to --exclude")
48
- next
49
- end
50
- loog.debug("Including #{repo}#{pr}")
44
+ next unless Cobench::Match.new(@opts, loog).matches?(repo)
45
+ pr_json = @api.pull_request(repo, pr)
46
+ hocs = pr_json.additions + pr_json.deletions
47
+ hoc += hocs
48
+ loog.debug("Including #{repo}##{pr} with #{hocs}")
51
49
  end
52
- [total, Iri.new('https://github.com/search').add(q: q)]
50
+ [
51
+ {
52
+ title: 'Pulls',
53
+ total: total,
54
+ href: Iri.new('https://github.com/search').add(q: q)
55
+ },
56
+ {
57
+ title: 'HoC',
58
+ total: hoc,
59
+ href: ''
60
+ }
61
+ ]
53
62
  end
54
63
  end
@@ -23,5 +23,5 @@
23
23
  # Copyright:: Copyright (c) 2022 Yegor Bugayenko
24
24
  # License:: MIT
25
25
  module Cobench
26
- VERSION = '0.0.6'.freeze
26
+ VERSION = '0.0.9'.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.6
4
+ version: 0.0.9
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-10 00:00:00.000000000 Z
11
+ date: 2022-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -251,12 +251,14 @@ files:
251
251
  - features/step_definitions/steps.rb
252
252
  - features/support/env.rb
253
253
  - lib/cobench/mask.rb
254
+ - lib/cobench/match.rb
254
255
  - lib/cobench/metrics/issues.rb
255
256
  - lib/cobench/metrics/pulls.rb
256
257
  - lib/cobench/version.rb
257
258
  - logo.svg
258
259
  - test/test__helper.rb
259
260
  - test/test_mask.rb
261
+ - test/test_match.rb
260
262
  homepage: http://github.com/yegor256/cobench
261
263
  licenses:
262
264
  - MIT