cobench 0.0.7 → 0.0.8

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: f373391e22ba904b48c65b3bbfcf7ca8ba7c8449809f3f61b94d21bc2d03ef56
4
- data.tar.gz: 49fab0a0e00dfc5c1638bc2a4e1c34e3fdcf44bfe266e5bc2cd83d81f1806957
3
+ metadata.gz: 1eaf9208a53326a257503d91e54aae018b2dd0964c0ec11ddde8d8b392a036cc
4
+ data.tar.gz: 5b1d155907221ec14edfbd5ca674f345531303e383c2f13aae88335bdc35c1cd
5
5
  SHA512:
6
- metadata.gz: 17b292e42c40fcd80af4106dda44718916a639a692cf9aa178b9025a639aeebd5fae6ac91778c7860f430e42785575e7fe7e462cd118df867779f069eea0d089
7
- data.tar.gz: ee3e364fd9fb37bac07085e2d26f3b0f5291cb9666ed07a08167e3000df841f9269605ef704affa1243fb9f310efefd3694c812501b882436f6a5d20fd6f9162
6
+ metadata.gz: 8c155780a0a14a843daf36336d66e5a3216b9886b0da46503d0a44ad3994a7e71eb2d4ee15c7bc4edfe3c236591673c7339e918ce9afbe697f7ca5f4bb415614
7
+ data.tar.gz: 2e7ca41724d9768abfbad82c6cbd2bff175b30783644c4af24650183f5868e65050832d7a72d2f776aa080d30afdb2aaaa4a82d315c5279e8f61a350e7cca72f
data/assets/index.xsl CHANGED
@@ -24,7 +24,6 @@ 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:key name="metrics" match="/cobench/coders/coder/metrics/m" use="@id"/>
28
27
  <xsl:template match="/">
29
28
  <html>
30
29
  <head>
@@ -60,7 +59,10 @@ SOFTWARE.
60
59
  </p>
61
60
  </header>
62
61
  <article>
63
- <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>
64
66
  </article>
65
67
  <footer>
66
68
  <p>
@@ -85,22 +87,23 @@ SOFTWARE.
85
87
  </body>
86
88
  </html>
87
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>
88
103
  <xsl:template match="cobench/coders">
89
- <table id="metrics">
90
- <thead>
91
- <tr>
92
- <th/>
93
- <xsl:for-each select="coder/metrics/m[generate-id() = generate-id(key('metrics', @id)[1])]">
94
- <th class="sorter num">
95
- <xsl:value-of select="@id"/>
96
- </th>
97
- </xsl:for-each>
98
- </tr>
99
- </thead>
100
- <tbody>
101
- <xsl:apply-templates select="coder"/>
102
- </tbody>
103
- </table>
104
+ <tbody>
105
+ <xsl:apply-templates select="coder"/>
106
+ </tbody>
104
107
  </xsl:template>
105
108
  <xsl:template match="coder">
106
109
  <tr>
@@ -110,14 +113,24 @@ SOFTWARE.
110
113
  <xsl:value-of select="@id"/>
111
114
  </a>
112
115
  </td>
113
- <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>
114
120
  </tr>
115
121
  </xsl:template>
116
122
  <xsl:template match="m">
117
123
  <td class="num">
118
- <a href="{@href}">
119
- <xsl:value-of select="."/>
120
- </a>
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>
121
134
  </td>
122
135
  </xsl:template>
123
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 = [Random.new.rand(100), '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,43 @@
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)
29
+ @opts = opts
30
+ end
31
+
32
+ def matches?(repo)
33
+ 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
+ return false
36
+ end
37
+ if @opts[:exclude].any? { |m| Cobench::Mask.new(m).matches?(repo) }
38
+ loog.debug("Excluding #{repo}##{pr} due to --exclude")
39
+ return false
40
+ end
41
+ true
42
+ end
43
+ 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).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).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.7'.freeze
26
+ VERSION = '0.0.8'.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.7
4
+ version: 0.0.8
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,6 +251,7 @@ 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