ghrt 0.1.0

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.
@@ -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
@@ -0,0 +1,12 @@
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
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,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).
@@ -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,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])
@@ -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
@@ -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,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&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>&#{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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ghrt
4
+ VERSION = '0.1.0'
5
+ end
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: []