ghrt 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8472f8b21106014d61a409b355493e0d0c053fce56e6a099f8b461a2f9acaec8
4
+ data.tar.gz: 8222ce6c112c2ed4faa574ab6ae9e6f3b044613cc78eeb0c3731f3809ea0bb4d
5
+ SHA512:
6
+ metadata.gz: f78178d097c7bf826b766f37c71ddf1950361fa9d346b2c45e53d6180349d96e8c7a31b19ec6d25d93e8449fcbc0b14e40dfc4aace92a549dc8baa1416ba718d
7
+ data.tar.gz: 3c9f8460aec4e9662b4bbf927bcf6aecd10d8ff80bba32ae9af85a3105e1414f4ce4a98e331c2a00a603a250f4c8a27c989bf45039ab51eedea1d54fedca9360
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ Gemfile.lock
13
+ /ghrt-*.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,18 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+
4
+ Documentation:
5
+ Enabled: false
6
+
7
+ # Following appears to be problematic with the slack-ruby-bot Gem
8
+ Style/FrozenStringLiteralComment:
9
+ Enabled: false
10
+
11
+ Metrics/LineLength:
12
+ Max: 120
13
+
14
+ Metrics/BlockLength:
15
+ Exclude:
16
+ - 'spec/**/*_spec.rb'
17
+ - 'lib/tasks/**/*.rake'
18
+ - 'db/schema.rb'
@@ -0,0 +1 @@
1
+ 2.5.3
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 1.16.6
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in ghrt.gemspec
8
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Alex Leaver
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # GHRT (GitHub Review Tool)
2
+
3
+ A simple Gem for for extracting your comments made against a PR and using this as a form of checklist
4
+ to identify your original comments and whether they have been addressed.
5
+
6
+ Not my finest piece of work, but a quick conversion of a Ruby script to a Gem so that it could be shared with
7
+ other developers.
8
+
9
+ ## Installation
10
+
11
+ ### From RubyGems.org
12
+
13
+ ```gem install ghrt```
14
+
15
+ ### From Source
16
+
17
+ Clone this repository and run `bundle exec rake install`.
18
+
19
+ ## Usage
20
+
21
+ * Ensure `GITHUB_USERNAME` is set with your GitHub username
22
+ * Ensure `GITHUB_TOKEN` is set with your GitHub token
23
+ * Run with `ghrt -p <pr_number> --repo <org/repo> > comments.html`
24
+ * e.g. `ghrt -p 1234 --repo amleaver/ghrt > comments.html`
25
+ * Full list of argument can be returned with `ghrt -h`
26
+
27
+ ## Development
28
+
29
+ * Run `bin/setup` to install dependencies
30
+ * Run `rake spec` to run the tests (not implemented yet)
31
+ * Run `bin/console` for an interactive prompt that will allow you to experiment
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/amleaver/ghrt.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'ghrt'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Allows the script to be called directly without installing the gem
5
+ begin
6
+ require 'ghrt'
7
+ rescue LoadError
8
+ require 'bundler/setup'
9
+ require 'ghrt'
10
+ end
11
+
12
+ require 'optparse'
13
+
14
+ options = {}
15
+ OptionParser.new do |opts|
16
+ opts.banner = 'Usage: ghrt [options]'
17
+
18
+ opts.on('-v', '--verbose', 'Run verbosely') do |v|
19
+ options[:verbose] = v
20
+ end
21
+
22
+ opts.on('-r', '--repo <org/repo>', 'Github repostiory') do |repo|
23
+ options[:repo] = repo
24
+ end
25
+
26
+ opts.on('-p', '--pull-request <number>', 'Pull request number') do |number|
27
+ options[:pr] = number
28
+ end
29
+
30
+ opts.on('-s', '--since <yyyy-mm-dd>', 'Only return comments since ISO date') do |date|
31
+ options[:since] = date
32
+ end
33
+
34
+ opts.separator ''
35
+ opts.separator "Version #{Ghrt::VERSION}"
36
+ end.parse!
37
+
38
+ raise '--repo and --pull-request parameters must be provided' unless options[:repo] && options[:pr]
39
+
40
+ puts options if options[:verbose]
41
+
42
+ puts Ghrt::ReviewerComments.to_html(options[:repo], options[:pr], options[:since], options[:verbose])
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'ghrt/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'ghrt'
9
+ spec.version = Ghrt::VERSION
10
+ spec.authors = ['Alex Leaver']
11
+ spec.email = ['amleaver@gmail.com']
12
+
13
+ spec.summary = 'GitHub Review Tools'
14
+ spec.description = 'Provides tools for assisting with GitHub reviews'
15
+ spec.homepage = 'https://github.com/amleaver/ghrt'
16
+ spec.license = 'MIT'
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = 'exe'
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.add_dependency 'kramdown', '~> 2.0'
28
+
29
+ spec.add_development_dependency 'bundler', '~> 1.16'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rspec', '~> 3.0'
32
+ spec.add_development_dependency 'rubocop', '~> 0.63.1'
33
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ghrt/version'
4
+ require 'ghrt/github'
5
+ require 'ghrt/reviewer_comments'
6
+
7
+ module Ghrt
8
+ # Your code goes here...
9
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri'
4
+ require 'net/http'
5
+ require 'json'
6
+ require 'base64'
7
+ require 'date'
8
+
9
+ module Ghrt
10
+ class Github
11
+ def initialize(repo, verbose)
12
+ @repo = repo
13
+ @username = ENV['GITHUB_USERNAME']
14
+ @token = ENV['GITHUB_TOKEN']
15
+ raise 'GITHUB_USERNAME and GITHUB_TOKEN environment variables must be set' unless @username && @token
16
+
17
+ @verbose = verbose
18
+ end
19
+
20
+ def review_comments(pull_request, since)
21
+ response = []
22
+ page = 1
23
+
24
+ loop do
25
+ paged_response = query_github("/pulls/#{pull_request}/comments?since=#{since}&per_page=100&page=#{page}")
26
+ break if paged_response.empty?
27
+
28
+ response.concat(paged_response)
29
+ page += 1
30
+ end
31
+
32
+ response.select do |comment|
33
+ comment['user']['login'] == @username &&
34
+ DateTime.parse(comment['created_at']) >= DateTime.parse(since) if since
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def query_github(path)
41
+ url = URI("https://api.github.com/repos/#{@repo}#{path}")
42
+ puts url if @verbose
43
+
44
+ http = Net::HTTP.new(url.host, url.port)
45
+ http.use_ssl = true
46
+
47
+ request = Net::HTTP::Get.new(url)
48
+ request['Authorization'] = auth_header
49
+
50
+ parse_response(http.request(request))
51
+ end
52
+
53
+ def parse_response(response)
54
+ puts response.code if @verbose
55
+ raise "Unexpected API response status #{response.code}" unless response.code == '200'
56
+
57
+ JSON.parse(response.read_body)
58
+ end
59
+
60
+ def auth_header
61
+ auth_header = "Basic #{Base64.urlsafe_encode64("#{@username}:#{@token}")}"
62
+ puts auth_header if @verbose
63
+ auth_header
64
+ end
65
+
66
+ def validate_envars
67
+ return unless ENV['GITHUB_USERNAME'] && ENV['GITHUB_TOKEN']
68
+
69
+ raise 'GITHUB_USERNAME and GITHUB_TOKEN environment variables have not been set'
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kramdown'
4
+
5
+ module Ghrt
6
+ class ReviewerComments
7
+ # rubocop:disable Metrics/MethodLength
8
+ def self.to_html(repo, pull_request, since, verbose)
9
+ user_comments = Github.new(repo, verbose).review_comments(pull_request, since)
10
+
11
+ # TODO: this really should be re-written using ERB or somesuch
12
+ html = <<~HTML
13
+ <html>
14
+ <head>
15
+ <title>PR #{pull_request}</title>
16
+ <link rel='stylesheet' href='https://stackpath.bootstrapcdn.com/bootswatch/4.2.1/darkly/bootstrap.min.css'/>
17
+ <script src="https://rawgit.com/google/code-prettify/master/loader/run_prettify.js?autoload=true&amp;skin=doxy&amp;lang=css"></script>
18
+ </head>
19
+ <body>
20
+ <div class="container">
21
+ <h2>#{user_comments.count} Comments#{since ? "Since #{since}" : nil}</h2>
22
+ HTML
23
+
24
+ user_comments.each_with_index do |comment, index|
25
+ html += <<~HTML
26
+ <div class="row" ondblclick="this.classList.add('collapse')">
27
+ <div class="col-xl-12 mb-2">
28
+ <a target="_blank" href='#{comment['html_url']}'><h3>##{index + 1} - #{comment['path']}:#{comment['original_position']}</h3></a>
29
+ <div class="pl-3">
30
+ <pre class="prettyprint"><code>#{normalise_diff_hunk(comment['diff_hunk'])}</code></pre>
31
+ <div class="text-muted" style="font-size: 1.1em">#{Kramdown::Document.new(comment['body']).to_html}</div>
32
+ </div>
33
+ </div>
34
+ </div>
35
+ HTML
36
+ end
37
+
38
+ html += <<~HTML
39
+ </div>
40
+ </body>
41
+ </html>
42
+ HTML
43
+ end
44
+ # rubocop:enable Metrics/MethodLength
45
+
46
+ # Make hunks 6 lines long and remove headers
47
+ def self.normalise_diff_hunk(hunk)
48
+ return hunk.lines.to_a[1..-1].join if hunk.lines.count <= 6
49
+
50
+ hunk.lines.to_a[(hunk.lines.count - 6)..-1].join
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ghrt
4
+ VERSION = '0.4.0'
5
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ghrt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Alex Leaver
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-04-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: kramdown
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.63.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.63.1
83
+ description: Provides tools for assisting with GitHub reviews
84
+ email:
85
+ - amleaver@gmail.com
86
+ executables:
87
+ - ghrt
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".rubocop.yml"
94
+ - ".ruby-version"
95
+ - ".travis.yml"
96
+ - Gemfile
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - bin/console
101
+ - bin/setup
102
+ - exe/ghrt
103
+ - ghrt.gemspec
104
+ - lib/ghrt.rb
105
+ - lib/ghrt/github.rb
106
+ - lib/ghrt/reviewer_comments.rb
107
+ - lib/ghrt/version.rb
108
+ homepage: https://github.com/amleaver/ghrt
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.7.6
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: GitHub Review Tools
132
+ test_files: []