ghrt 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +18 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +33 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/exe/ghrt +39 -0
- data/ghrt.gemspec +44 -0
- data/lib/ghrt.rb +9 -0
- data/lib/ghrt/github.rb +56 -0
- data/lib/ghrt/reviewer_comments.rb +46 -0
- data/lib/ghrt/version.rb +5 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 779761a95af7bea42a4e965bc1bf3f82b04ea7422c01a883081810b8a5bf9303
|
4
|
+
data.tar.gz: 5538e1aea5a5a5dc77d2371fcd3d77929d2a22d5cbf2e69d3a25c655af4561b7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 18c15dda88becce67cd475e66cea1ce2faf6bd5be7a69a80a49978e9a90346a90068ad5e7c2ea8dda6a201c47a516bc31b946163a77b083e9cdae0bc24dc9975
|
7
|
+
data.tar.gz: 922e7ea004efe04b7f9ed8f9aea3da85f39e5aa7454f41f240fb2f0b651139da8f83c2874b777a25af853a2be0abe6bd24272cb1d93e75f308a91c8da57bb608
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -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'
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.3
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -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.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
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
|
+
Clone this repository and run `bundle exec rake install`.
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
* Ensure `GITHUB_USERNAME` is set with your GitHub username
|
16
|
+
* Ensure `GITHUB_TOKEN` is set with your GitHub token
|
17
|
+
* Run with `ghrt -p <pr_number> --repo <org/repo> > comments.html`
|
18
|
+
* e.g. `ghrt -p 1234 --repo amleaver/ghrt > comments.html`
|
19
|
+
* Full list of argument can be returned with `ghrt -h`
|
20
|
+
|
21
|
+
## Development
|
22
|
+
|
23
|
+
* Run `bin/setup` to install dependencies
|
24
|
+
* Run `rake spec` to run the tests (not implemented yet)
|
25
|
+
* Run `bin/console` for an interactive prompt that will allow you to experiment
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/amleaver/ghrt.
|
30
|
+
|
31
|
+
## License
|
32
|
+
|
33
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -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__)
|
data/bin/setup
ADDED
data/exe/ghrt
ADDED
@@ -0,0 +1,39 @@
|
|
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
|
+
end.parse!
|
34
|
+
|
35
|
+
raise '--repo and --pull-request parameters must be provided' unless options[:repo] && options[:pr]
|
36
|
+
|
37
|
+
puts options if options[:verbose]
|
38
|
+
|
39
|
+
puts Ghrt::ReviewerComments.to_html(options[:repo], options[:pr], options[:since], options[:verbose])
|
data/ghrt.gemspec
ADDED
@@ -0,0 +1,44 @@
|
|
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
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
19
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
20
|
+
# if spec.respond_to?(:metadata)
|
21
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
22
|
+
#
|
23
|
+
# spec.metadata["homepage_uri"] = spec.homepage
|
24
|
+
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
25
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
26
|
+
# else
|
27
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
28
|
+
# "public gem pushes."
|
29
|
+
# end
|
30
|
+
|
31
|
+
# Specify which files should be added to the gem when it is released.
|
32
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
33
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
34
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
35
|
+
end
|
36
|
+
spec.bindir = 'exe'
|
37
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
38
|
+
spec.require_paths = ['lib']
|
39
|
+
|
40
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
41
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
42
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
43
|
+
spec.add_development_dependency 'rubocop', '~> 0.63.1'
|
44
|
+
end
|
data/lib/ghrt.rb
ADDED
data/lib/ghrt/github.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'net/http'
|
5
|
+
require 'json'
|
6
|
+
require 'base64'
|
7
|
+
|
8
|
+
module Ghrt
|
9
|
+
class Github
|
10
|
+
def initialize(repo, verbose)
|
11
|
+
@repo = repo
|
12
|
+
@username = ENV['GITHUB_USERNAME']
|
13
|
+
@token = ENV['GITHUB_TOKEN']
|
14
|
+
@verbose = verbose
|
15
|
+
end
|
16
|
+
|
17
|
+
def review_comments(pull_request, since)
|
18
|
+
response = query_github("/pulls/#{pull_request}/comments?since=#{since}")
|
19
|
+
response.select { |comment| comment['user']['login'] == @username }
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def query_github(path)
|
25
|
+
url = URI("https://api.github.com/repos/#{@repo}#{path}")
|
26
|
+
puts url if @verbose
|
27
|
+
|
28
|
+
http = Net::HTTP.new(url.host, url.port)
|
29
|
+
http.use_ssl = true
|
30
|
+
|
31
|
+
request = Net::HTTP::Get.new(url)
|
32
|
+
request['Authorization'] = auth_header
|
33
|
+
|
34
|
+
parse_response(http.request(request))
|
35
|
+
end
|
36
|
+
|
37
|
+
def parse_response(response)
|
38
|
+
puts response if @verbose
|
39
|
+
raise "Unexpected API response status #{response.code}" unless response.code == '200'
|
40
|
+
|
41
|
+
JSON.parse(response.read_body)
|
42
|
+
end
|
43
|
+
|
44
|
+
def auth_header
|
45
|
+
auth_header = "Basic #{Base64.urlsafe_encode64("#{@username}:#{@token}")}"
|
46
|
+
puts auth_header if @verbose
|
47
|
+
auth_header
|
48
|
+
end
|
49
|
+
|
50
|
+
def validate_envars
|
51
|
+
return unless ENV['GITHUB_USERNAME'] && ENV['GITHUB_TOKEN']
|
52
|
+
|
53
|
+
raise 'GITHUB_USERNAME and GITHUB_TOKEN environment variables have not been set'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'erb'
|
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&skin=doxy&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>&#{comment['diff_hunk']}</code></pre>
|
31
|
+
<p class="text-muted" style="font-size: 1.1em">#{comment['body']}</p>
|
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
|
+
end
|
46
|
+
end
|
data/lib/ghrt/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ghrt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex Leaver
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-01-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.63.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.63.1
|
69
|
+
description: Provides tools for assisting with GitHub reviews
|
70
|
+
email:
|
71
|
+
- amleaver@gmail.com
|
72
|
+
executables:
|
73
|
+
- ghrt
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".rubocop.yml"
|
80
|
+
- ".ruby-version"
|
81
|
+
- ".travis.yml"
|
82
|
+
- Gemfile
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- bin/console
|
87
|
+
- bin/setup
|
88
|
+
- exe/ghrt
|
89
|
+
- ghrt.gemspec
|
90
|
+
- lib/ghrt.rb
|
91
|
+
- lib/ghrt/github.rb
|
92
|
+
- lib/ghrt/reviewer_comments.rb
|
93
|
+
- lib/ghrt/version.rb
|
94
|
+
homepage: https://github.com/amleaver/ghrt
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.7.6
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: GitHub Review Tools
|
118
|
+
test_files: []
|