cobench 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: defa3e4cde7aac6bc7160fd2d7a36a536fa462942e55a6112d967022a3c957a6
4
+ data.tar.gz: 7b8f61c26ab4409299ce0a115918c0ba14474e71af44b50366d6df745702588d
5
+ SHA512:
6
+ metadata.gz: 65c63f32bf1b00544287310255c98f0ccc3bb914e617d752698061272e976bc32b311f78ece515515d9cb3db502ef035fe86c26b4d84a863e657afa0cbbec7c7
7
+ data.tar.gz: be70f5224f7fc676efac529f84c0839408fa2182f1926e1fc9e168b1aa7beef252d0ab493f9e6766d34fbe7872bfa85ea1020128eaaf9f0bdf4fee8c022eb59f
data/.0pdd.yml ADDED
@@ -0,0 +1,9 @@
1
+ errors:
2
+ - yegor256@gmail.com
3
+ # alerts:
4
+ # github:
5
+ # - yegor256
6
+
7
+ tags:
8
+ - pdd
9
+ - bug
data/.gitattributes ADDED
@@ -0,0 +1,7 @@
1
+ # Check out all text files in UNIX format, with LF as end of line
2
+ # Don't change this file. If you have any ideas about it, please
3
+ # submit a separate issue about it and we'll discuss.
4
+
5
+ * text=auto eol=lf
6
+ *.java ident
7
+ *.xml ident
@@ -0,0 +1,11 @@
1
+ ---
2
+ name: pdd
3
+ on:
4
+ push:
5
+ pull_request:
6
+ jobs:
7
+ pdd:
8
+ runs-on: ubuntu-20.04
9
+ steps:
10
+ - uses: actions/checkout@v2
11
+ - uses: g4s8/pdd-action@master
@@ -0,0 +1,23 @@
1
+ ---
2
+ name: rake
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ branches:
9
+ - master
10
+ jobs:
11
+ test:
12
+ strategy:
13
+ matrix:
14
+ os: [ubuntu-20.04, macos-12]
15
+ ruby: ['2.7', '3.0']
16
+ runs-on: ${{ matrix.os }}
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+ - uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: ${{ matrix.ruby }}
22
+ - run: bundle update
23
+ - run: bundle exec rake
@@ -0,0 +1,11 @@
1
+ ---
2
+ name: xcop
3
+ on:
4
+ push:
5
+ pull_request:
6
+ jobs:
7
+ xcop:
8
+ runs-on: ubuntu-20.04
9
+ steps:
10
+ - uses: actions/checkout@v2
11
+ - uses: g4s8/xcop-action@master
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ coverage/
2
+ Gemfile.lock
3
+ .idea/
4
+ *.gem
5
+ .bundle/
6
+ .DS_Store
7
+ rdoc/
8
+ /cobench/
data/.pdd ADDED
@@ -0,0 +1,7 @@
1
+ --source=.
2
+ --verbose
3
+ --exclude target/**/*
4
+ --exclude coverage/**/*
5
+ --rule min-words:20
6
+ --rule min-estimate:15
7
+ --rule max-estimate:90
data/.rubocop.yml ADDED
@@ -0,0 +1,23 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'bin/**/*'
4
+ - 'assets/**/*'
5
+ DisplayCopNames: true
6
+ TargetRubyVersion: 2.2
7
+ NewCops: enable
8
+ SuggestExtensions: false
9
+
10
+ Metrics/CyclomaticComplexity:
11
+ Max: 10
12
+ Metrics/MethodLength:
13
+ Enabled: false
14
+ Layout/MultilineMethodCallIndentation:
15
+ Enabled: false
16
+ Metrics/AbcSize:
17
+ Enabled: false
18
+ Metrics/BlockLength:
19
+ Max: 50
20
+ Layout/EmptyLineAfterGuardClause:
21
+ Enabled: false
22
+ Style/ClassAndModuleChildren:
23
+ Enabled: false
data/.rultor.yml ADDED
@@ -0,0 +1,22 @@
1
+ assets:
2
+ rubygems.yml: yegor256/home#assets/rubygems.yml
3
+ install: |
4
+ pdd -f /dev/null
5
+ sudo bundle install --no-color "--gemfile=$(pwd)/Gemfile"
6
+ release:
7
+ script: |-
8
+ bundle exec rake
9
+ rm -rf *.gem
10
+ sed -i "s/0\.0\.0/${tag}/g" lib/cobench/version.rb
11
+ git add lib/cobench/version.rb
12
+ git commit -m "version set to ${tag}"
13
+ gem build cobench.gemspec
14
+ chmod 0600 ../rubygems.yml
15
+ gem push *.gem --config-file ../rubygems.yml
16
+ merge:
17
+ script: |-
18
+ bundle exec rake
19
+ deploy:
20
+ script: |-
21
+ echo "There is nothing to deploy"
22
+ exit -1
data/.simplecov ADDED
@@ -0,0 +1,38 @@
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
+ if Gem.win_platform?
22
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
23
+ SimpleCov::Formatter::HTMLFormatter
24
+ ]
25
+ SimpleCov.start do
26
+ add_filter '/test/'
27
+ add_filter '/features/'
28
+ end
29
+ else
30
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
31
+ [SimpleCov::Formatter::HTMLFormatter]
32
+ )
33
+ SimpleCov.start do
34
+ add_filter '/test/'
35
+ add_filter '/features/'
36
+ minimum_coverage 80
37
+ end
38
+ end
data/Gemfile ADDED
@@ -0,0 +1,22 @@
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 NONINFRINGEMENT. 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
+ source 'https://rubygems.org'
22
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2022 Yegor Bugayenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the 'Software'), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ <img alt="cobench logo" src="/logo.svg" width="64px"/>
2
+
3
+ [![EO principles respected here](https://www.elegantobjects.org/badge.svg)](https://www.elegantobjects.org)
4
+ [![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/cobench)](http://www.rultor.com/p/yegor256/cobench)
5
+ [![We recommend RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
6
+
7
+ [![rake](https://github.com/yegor256/cobench/actions/workflows/rake.yml/badge.svg)](https://github.com/yegor256/cobench/actions/workflows/rake.yml)
8
+ [![PDD status](http://www.0pdd.com/svg?name=yegor256/cobench)](http://www.0pdd.com/p?name=yegor256/cobench)
9
+ [![Gem Version](https://badge.fury.io/rb/cobench.svg)](http://badge.fury.io/rb/cobench)
10
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/cobench/blob/master/LICENSE.txt)
11
+ [![Maintainability](https://api.codeclimate.com/v1/badges/396ec0584e0a84adc723/maintainability)](https://codeclimate.com/github/yegor256/cobench/maintainability)
12
+ [![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/cobench.svg)](https://codecov.io/github/yegor256/cobench?branch=master)
13
+ ![Lines of code](https://img.shields.io/tokei/lines/github/yegor256/cobench)
14
+ [![Hits-of-Code](https://hitsofcode.com/github/yegor256/cobench)](https://hitsofcode.com/view/github/yegor256/cobench)
15
+
16
+ This simple script will help you collect statistics about your
17
+ programmers and generate a simple HTML report. First, install it:
18
+
19
+ ```bash
20
+ $ gem install cobench
21
+ ```
22
+
23
+ Then, run it locally and read its output:
24
+
25
+ ```bash
26
+ $ cobench --coder yegor256 --verbose
27
+ ```
28
+
29
+ ## How to contribute
30
+
31
+ Read [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
32
+ Make sure you build is green before you contribute
33
+ your pull request. You will need to have [Ruby](https://www.ruby-lang.org/en/) 2.3+ and
34
+ [Bundler](https://bundler.io/) installed. Then:
35
+
36
+ ```
37
+ $ bundle update
38
+ $ bundle exec rake
39
+ ```
40
+
41
+ If it's clean and you don't see any error messages, submit your pull request.
data/Rakefile ADDED
@@ -0,0 +1,76 @@
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 NONINFRINGEMENT. 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 'rubygems'
22
+ require 'rake'
23
+ require 'rdoc'
24
+ require 'rake/clean'
25
+
26
+ def name
27
+ @name ||= File.basename(Dir['*.gemspec'].first, '.*')
28
+ end
29
+
30
+ def version
31
+ Gem::Specification.load(Dir['*.gemspec'].first).version
32
+ end
33
+
34
+ task default: %i[clean test features rubocop copyright]
35
+
36
+ require 'rake/testtask'
37
+ desc 'Run all unit tests'
38
+ Rake::TestTask.new(:test) do |test|
39
+ Rake::Cleaner.cleanup_files(['coverage'])
40
+ test.libs << 'lib' << 'test'
41
+ test.pattern = 'test/**/test_*.rb'
42
+ test.verbose = false
43
+ end
44
+
45
+ require 'rdoc/task'
46
+ desc 'Build RDoc documentation'
47
+ Rake::RDocTask.new do |rdoc|
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "#{name} #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
53
+
54
+ require 'rubocop/rake_task'
55
+ desc 'Run RuboCop on all directories'
56
+ RuboCop::RakeTask.new(:rubocop) do |task|
57
+ task.fail_on_error = true
58
+ task.requires << 'rubocop-rspec'
59
+ task.options = ['--display-cop-names']
60
+ end
61
+
62
+ require 'cucumber/rake/task'
63
+ Cucumber::Rake::Task.new(:features) do
64
+ Rake::Cleaner.cleanup_files(['coverage'])
65
+ end
66
+ Cucumber::Rake::Task.new(:'features:html') do |t|
67
+ t.profile = 'html_report'
68
+ end
69
+
70
+ task :copyright do
71
+ sh "grep -q -r '#{Date.today.strftime('%Y')}' \
72
+ --include '*.rb' \
73
+ --include '*.txt' \
74
+ --include 'Rakefile' \
75
+ ."
76
+ end
data/assets/index.xsl ADDED
@@ -0,0 +1,105 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ (The MIT License)
4
+
5
+ Copyright (c) 2022 Yegor Bugayenko
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the 'Software'), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
24
+ -->
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"/>
28
+ <xsl:template match="/">
29
+ <html>
30
+ <head>
31
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
32
+ <title>cobench</title>
33
+ <meta charset="UTF-8"/>
34
+ <meta content="width=device-width, initial-scale=1.0" name="viewport"/>
35
+ <link rel="icon" href="https://raw.githubusercontent.com/yegor256/cobench/master/logo.svg" type="image/svg"/>
36
+ <link href="https://cdn.jsdelivr.net/gh/yegor256/tacit@gh-pages/tacit-css.min.css" rel="stylesheet"/>
37
+ <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>
40
+ <script type="text/javascript">
41
+ $(function() {
42
+ $("#metrics").tablesorter();
43
+ });
44
+ </script>
45
+ </head>
46
+ <body>
47
+ <xsl:apply-templates select="cobench/coders"/>
48
+ <p>
49
+ <xsl:text>The page was generated by on </xsl:text>
50
+ <a href="https://github.com/yegor256/cobench">
51
+ <xsl:text>cobench</xsl:text>
52
+ </a>
53
+ <xsl:text> on </xsl:text>
54
+ <xsl:value-of select="cobench/@time"/>
55
+ <xsl:text>. The numbers you see reflect the activity of the last </xsl:text>
56
+ <b>
57
+ <xsl:value-of select="cobench/@days"/>
58
+ <xsl:text> days</xsl:text>
59
+ </b>
60
+ <xsl:text>.</xsl:text>
61
+ </p>
62
+ </body>
63
+ </html>
64
+ </xsl:template>
65
+ <xsl:template match="cobench/coders">
66
+ <table id="metrics">
67
+ <thead>
68
+ <tr>
69
+ <th/>
70
+ <xsl:for-each select="coder/metrics/m[generate-id() = generate-id(key('metrics', @id)[1])]">
71
+ <th>
72
+ <xsl:value-of select="@id"/>
73
+ </th>
74
+ </xsl:for-each>
75
+ </tr>
76
+ </thead>
77
+ <tbody>
78
+ <xsl:apply-templates select="coder"/>
79
+ </tbody>
80
+ </table>
81
+ </xsl:template>
82
+ <xsl:template match="coder">
83
+ <tr>
84
+ <td>
85
+ <a href="https://github.com/{@id}">
86
+ <xsl:text>@</xsl:text>
87
+ <xsl:value-of select="@id"/>
88
+ </a>
89
+ </td>
90
+ <xsl:apply-templates select="metrics/m"/>
91
+ </tr>
92
+ </xsl:template>
93
+ <xsl:template match="m">
94
+ <td>
95
+ <a href="{@href}">
96
+ <xsl:value-of select="."/>
97
+ </a>
98
+ </td>
99
+ </xsl:template>
100
+ <xsl:template match="node()|@*">
101
+ <xsl:copy>
102
+ <xsl:apply-templates select="node()|@*"/>
103
+ </xsl:copy>
104
+ </xsl:template>
105
+ </xsl:stylesheet>
data/bin/cobench ADDED
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright (c) 2022 Yegor Bugayenko
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the 'Software'), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ # SOFTWARE.
21
+
22
+ STDOUT.sync = true
23
+
24
+ require 'slop'
25
+ require 'loog'
26
+ require 'octokit'
27
+ require 'nokogiri'
28
+ require 'backtrace'
29
+ require 'fileutils'
30
+ require_relative '../lib/cobench/version'
31
+
32
+ loog = Loog::REGULAR
33
+
34
+ def config(path)
35
+ f = File.expand_path(path)
36
+ args = []
37
+ args += File.readlines(f).map(&:strip) if File.exist?(f)
38
+ args
39
+ end
40
+
41
+ args = config('~/.cobench') + config('.cobench') + ARGV
42
+
43
+ opts = Slop.parse(args, strict: true, help: true) do |o|
44
+ o.banner = "Usage (#{Cobench::VERSION}): cobench [options]"
45
+ o.bool '-h', '--help', 'Show these instructions'
46
+ o.bool '--version', 'Show current version'
47
+ o.bool '--verbose', 'Print as much log messages as possible'
48
+ o.bool '--dry', 'Make no real round trips to GitHub'
49
+ o.integer '--days', 'How many days to measure', default: 7
50
+ o.array '--to', 'Directory where to save all files to', default: './cobench'
51
+ o.array '--token', 'GitHub authentication token'
52
+ o.array '--coder', 'GitHub nickname of a coder to track'
53
+ o.array '--include', 'Mask of GitHub repo to include, e.g. yegor256/*'
54
+ o.array '--exclude', 'Mask of GitHub repo to exclude'
55
+ end
56
+
57
+ if opts.help?
58
+ puts opts
59
+ exit
60
+ end
61
+
62
+ if opts.verbose?
63
+ loog = Loog::VERBOSE
64
+ end
65
+
66
+ if opts.version?
67
+ loog.info(Cobench::VERSION)
68
+ exit
69
+ end
70
+
71
+ Encoding.default_external = Encoding::UTF_8
72
+ Encoding.default_internal = Encoding::UTF_8
73
+
74
+ data = {}
75
+
76
+ begin
77
+ home = File.absolute_path(opts[:to])
78
+ loog.debug("All files generated will be saved to #{home}")
79
+ if File.exist?(home)
80
+ loog.debug("Directory #{home} exists")
81
+ else
82
+ FileUtils.mkdir_p(home)
83
+ loog.debug("Directory #{home} created")
84
+ end
85
+ if opts.token?
86
+ api = Octokit::Client.new(:access_token => opts[:token])
87
+ else
88
+ api = Octokit::Client.new
89
+ loog.warn("Connecting to GitHub without a token, this may lead to errors, use --token")
90
+ end
91
+ api.auto_paginate = true
92
+ opts[:coder].each do |u|
93
+ loog.info("Scanning #{u}...")
94
+ data[u] = {}
95
+ Dir[File.join(__dir__, '../lib/cobench/metrics/*.rb')].each do |f|
96
+ name = File::basename(f).split('.')[0]
97
+ type = "Cobench::#{name.capitalize}"
98
+ loog.info("Reading #{u}/#{name}...")
99
+ require_relative f
100
+ m = type.split('::').reduce(Module, :const_get).new(api, u, opts)
101
+ if opts.dry?
102
+ v, t = [42, 'https://github.com/']
103
+ else
104
+ v, t = m.take(loog)
105
+ end
106
+ data[u][name] = [v, t]
107
+ loog.info("The value of #{u}/#{name} is #{v}")
108
+ end
109
+ end
110
+ builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
111
+ xml.cobench(time: Time.now, days: opts[:days]) {
112
+ xml.coders {
113
+ data.each do |u, ms|
114
+ xml.coder(id: u) {
115
+ xml.metrics {
116
+ ms.each do |k, v|
117
+ xml.m(id: k, href: v[1]) {
118
+ xml.text v[0]
119
+ }
120
+ end
121
+ }
122
+ }
123
+ end
124
+ }
125
+ }
126
+ end
127
+ index = File.join(home, 'index.xml')
128
+ xml = builder.to_xml
129
+ loog.debug(xml)
130
+ File.write(index, xml)
131
+ loog.debug("XML saved to #{index} (#{File.size(index)} bytes)")
132
+ xslt = Nokogiri::XSLT(File.read(File.join(__dir__, '../assets/index.xsl')))
133
+ html = xslt.transform(Nokogiri::XML(xml))
134
+ loog.debug(html)
135
+ front = File.join(home, 'index.html')
136
+ File.write(front, html)
137
+ loog.debug("HTML saved to #{front} (#{File.size(front)} bytes)")
138
+ rescue StandardError => e
139
+ loog.error(Backtrace.new(e))
140
+ exit -1
141
+ end
data/cobench.gemspec ADDED
@@ -0,0 +1,57 @@
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 NONINFRINGEMENT. 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 'English'
22
+
23
+ lib = File.expand_path('lib', __dir__)
24
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
25
+ require_relative 'lib/cobench/version'
26
+
27
+ Gem::Specification.new do |s|
28
+ s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
29
+ s.required_ruby_version = '>= 2.2'
30
+ s.name = 'cobench'
31
+ s.version = Cobench::VERSION
32
+ s.license = 'MIT'
33
+ s.metadata = { 'rubygems_mfa_required' => 'true' }
34
+ s.summary = 'Coders Benchmarking Toolkit'
35
+ s.description = 'Downloads statistics from GitHub and builds a nice HTML report'
36
+ s.authors = ['Yegor Bugayenko']
37
+ s.email = 'yegor256@gmail.com'
38
+ s.homepage = 'http://github.com/yegor256/cobench'
39
+ s.files = `git ls-files`.split($RS)
40
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
41
+ s.rdoc_options = ['--charset=UTF-8']
42
+ s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
43
+ s.add_runtime_dependency 'backtrace', '~>0.3'
44
+ s.add_runtime_dependency 'iri', '~>0.5'
45
+ s.add_runtime_dependency 'loog', '~>0.2'
46
+ s.add_runtime_dependency 'nokogiri', '~>1.10'
47
+ s.add_runtime_dependency 'octokit', '~>4.0'
48
+ s.add_runtime_dependency 'rainbow', '~>3.0'
49
+ s.add_runtime_dependency 'slop', '~>4.4'
50
+ s.add_development_dependency 'codecov', '0.6.0'
51
+ s.add_development_dependency 'cucumber', '8.0.0'
52
+ s.add_development_dependency 'minitest', '5.15.0'
53
+ s.add_development_dependency 'rake', '13.0.6'
54
+ s.add_development_dependency 'rdoc', '6.4.0'
55
+ s.add_development_dependency 'rubocop', '1.32.0'
56
+ s.add_development_dependency 'rubocop-rspec', '2.11.1'
57
+ end
@@ -0,0 +1,17 @@
1
+ Feature: Simple Reporting
2
+ I want to be able to build a report
3
+
4
+ Scenario: Help can be printed
5
+ When I run bin/cobench with "-h"
6
+ Then Exit code is zero
7
+ And Stdout contains "--help"
8
+
9
+ Scenario: Version can be printed
10
+ When I run bin/cobench with "--version"
11
+ Then Exit code is zero
12
+
13
+ Scenario: Simple report
14
+ When I run bin/cobench with "--coder yegor256 --verbose --dry"
15
+ Then Stdout contains "XML saved to"
16
+ And Exit code is zero
17
+