pronto-github_resolver 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8853fcc6e38eef6f5fbaac5dc815cabd7e3e81e18136675a9cddfbc203f538d7
4
+ data.tar.gz: ab3620bd675754fc045ff7619f3053f27829786f4076a19f0cbd317ed3f84d56
5
+ SHA512:
6
+ metadata.gz: f7097355369c367d5d6232204fcc623cfb6755a494e4b81467904d97d671b46aa70c7d9339ebb92bc5a8a8e9ed4d56642cba344a73a31ecc56904959132d456a
7
+ data.tar.gz: cf0f065244dea041390ceabafb2cb76dcf71e46ea4d512666106b5ff9f1cc62f071bb5eb87945cb642cb08298d5873d9559db404ccd8f3cc5f64791248fa70db
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in pronto-github_resolver.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,108 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pronto-github_resolver (0.0.1)
5
+ pronto (~> 0.11)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.8.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
+ ast (2.4.2)
13
+ diff-lcs (1.4.4)
14
+ faraday (1.8.0)
15
+ faraday-em_http (~> 1.0)
16
+ faraday-em_synchrony (~> 1.0)
17
+ faraday-excon (~> 1.1)
18
+ faraday-httpclient (~> 1.0.1)
19
+ faraday-net_http (~> 1.0)
20
+ faraday-net_http_persistent (~> 1.1)
21
+ faraday-patron (~> 1.0)
22
+ faraday-rack (~> 1.0)
23
+ multipart-post (>= 1.2, < 3)
24
+ ruby2_keywords (>= 0.0.4)
25
+ faraday-em_http (1.0.0)
26
+ faraday-em_synchrony (1.0.0)
27
+ faraday-excon (1.1.0)
28
+ faraday-httpclient (1.0.1)
29
+ faraday-net_http (1.0.1)
30
+ faraday-net_http_persistent (1.2.0)
31
+ faraday-patron (1.0.0)
32
+ faraday-rack (1.0.0)
33
+ gitlab (4.17.0)
34
+ httparty (~> 0.18)
35
+ terminal-table (~> 1.5, >= 1.5.1)
36
+ httparty (0.20.0)
37
+ mime-types (~> 3.0)
38
+ multi_xml (>= 0.5.2)
39
+ mime-types (3.4.1)
40
+ mime-types-data (~> 3.2015)
41
+ mime-types-data (3.2021.1115)
42
+ multi_xml (0.6.0)
43
+ multipart-post (2.1.1)
44
+ octokit (4.21.0)
45
+ faraday (>= 0.9)
46
+ sawyer (~> 0.8.0, >= 0.5.3)
47
+ parallel (1.21.0)
48
+ parser (3.0.3.1)
49
+ ast (~> 2.4.1)
50
+ pronto (0.11.0)
51
+ gitlab (~> 4.4, >= 4.4.0)
52
+ httparty (>= 0.13.7)
53
+ octokit (~> 4.7, >= 4.7.0)
54
+ rainbow (>= 2.2, < 4.0)
55
+ rexml (~> 3.2)
56
+ rugged (>= 0.23.0, < 1.1.0)
57
+ thor (>= 0.20.3, < 2.0)
58
+ public_suffix (4.0.6)
59
+ rainbow (3.0.0)
60
+ rake (13.0.6)
61
+ regexp_parser (2.1.1)
62
+ rexml (3.2.5)
63
+ rspec (3.10.0)
64
+ rspec-core (~> 3.10.0)
65
+ rspec-expectations (~> 3.10.0)
66
+ rspec-mocks (~> 3.10.0)
67
+ rspec-core (3.10.1)
68
+ rspec-support (~> 3.10.0)
69
+ rspec-expectations (3.10.1)
70
+ diff-lcs (>= 1.2.0, < 2.0)
71
+ rspec-support (~> 3.10.0)
72
+ rspec-mocks (3.10.2)
73
+ diff-lcs (>= 1.2.0, < 2.0)
74
+ rspec-support (~> 3.10.0)
75
+ rspec-support (3.10.3)
76
+ rubocop (1.23.0)
77
+ parallel (~> 1.10)
78
+ parser (>= 3.0.0.0)
79
+ rainbow (>= 2.2.2, < 4.0)
80
+ regexp_parser (>= 1.8, < 3.0)
81
+ rexml
82
+ rubocop-ast (>= 1.12.0, < 2.0)
83
+ ruby-progressbar (~> 1.7)
84
+ unicode-display_width (>= 1.4.0, < 3.0)
85
+ rubocop-ast (1.13.0)
86
+ parser (>= 3.0.1.1)
87
+ ruby-progressbar (1.11.0)
88
+ ruby2_keywords (0.0.5)
89
+ rugged (1.0.1)
90
+ sawyer (0.8.2)
91
+ addressable (>= 2.3.5)
92
+ faraday (> 0.8, < 2.0)
93
+ terminal-table (1.8.0)
94
+ unicode-display_width (~> 1.1, >= 1.1.1)
95
+ thor (1.1.0)
96
+ unicode-display_width (1.8.0)
97
+
98
+ PLATFORMS
99
+ x86_64-darwin-21
100
+
101
+ DEPENDENCIES
102
+ pronto-github_resolver!
103
+ rake (~> 13.0)
104
+ rspec (~> 3.0)
105
+ rubocop (~> 1.21)
106
+
107
+ BUNDLED WITH
108
+ 2.2.31
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Vasily Fedoseyev
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,39 @@
1
+ # Pronto::GithubResolver
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/pronto/github_resolver`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'pronto-github_resolver'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install pronto-github_resolver
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pronto-github_resolver.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
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
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
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 "pronto/github_resolver"
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
@@ -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,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pronto
4
+ module GithubResolver
5
+ VERSION = "0.0.1"
6
+ end
7
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "github_resolver/version"
4
+ require 'pronto'
5
+
6
+ module Pronto
7
+
8
+ class Github < Client
9
+ def publish_pull_request_comments(comments, event: nil)
10
+ comments_left = comments.clone
11
+ while comments_left.any?
12
+ comments_to_publish = comments_left.slice!(0, warnings_per_review)
13
+ create_pull_request_review(comments_to_publish, event: event)
14
+ end
15
+ end
16
+
17
+ def create_pull_request_review(comments, event: nil)
18
+ options = {
19
+ event: event || @config.github_review_type,
20
+ accept: 'application/vnd.github.v3.diff+json', # https://developer.github.com/v3/pulls/reviews/#create-a-pull-request-review
21
+ comments: comments.map do |comment|
22
+ {
23
+ path: comment.path,
24
+ position: comment.position,
25
+ body: comment.body
26
+ }
27
+ end
28
+ }
29
+ client.create_pull_request_review(slug, pull_id, options)
30
+ end
31
+
32
+ def approve_pull_request(message=nil)
33
+ client.create_pull_request_review(slug, pull_id, {
34
+ event: 'APPROVE', body: message, accept: 'application/vnd.github.v3.diff+json'
35
+ })
36
+ end
37
+
38
+ def existing_pull_request_reviews
39
+ client.pull_request_reviews(slug, pull_id)
40
+ end
41
+
42
+ def bot_user_id
43
+ client.user.id
44
+ end
45
+ end
46
+
47
+ module Formatter
48
+ module GithubResolving
49
+ def format(messages, repo, patches)
50
+ client = client_module.new(repo)
51
+ existing = existing_comments(messages, client, repo)
52
+ comments = new_comments(messages, patches)
53
+ additions = remove_duplicate_comments(existing, comments)
54
+
55
+ if comments.none?
56
+ bot_reviews = client.existing_pull_request_reviews.select { |review| review.user.type == 'Bot' }
57
+ if bot_reviews.any?
58
+ bot_id = client.bot_user_id
59
+ current_bot_review_status = bot_reviews.inject(nil) do |prev_status, review|
60
+ next prev_status unless review.user.id == bot_id
61
+
62
+ case review.state
63
+ when 'CHANGES_REQUESTED' then review.state
64
+ when 'APPROVED' then nil
65
+ else
66
+ prev_status
67
+ end
68
+ end
69
+
70
+ client.approve_pull_request if current_bot_review_status == 'CHANGES_REQUESTED'
71
+ end
72
+ else
73
+ submit_comments(
74
+ client, additions,
75
+ event: messages.any? { |message| %i[error fatal].include?(message.level) } && 'REQUEST_CHANGES' || nil
76
+ )
77
+ end
78
+
79
+ "#{additions.count} Pronto messages posted to #{pretty_name}"
80
+ end
81
+
82
+ def submit_comments(client, comments, event: nil)
83
+ client.publish_pull_request_comments(comments, event: event)
84
+ rescue Octokit::UnprocessableEntity, HTTParty::Error => e
85
+ $stderr.puts "Failed to post: #{e.message}"
86
+ end
87
+ end
88
+
89
+ class GithubPullRequestResolvingReviewFormatter < PullRequestFormatter
90
+ prepend GithubResolving
91
+ end
92
+
93
+ Pronto::Formatter::GithubPullRequestReviewFormatter.prepend(GithubResolving)
94
+ end
95
+ end
96
+
97
+ module Pronto
98
+ module GithubResolver
99
+ end
100
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/pronto/github_resolver/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "pronto-github_resolver"
7
+ spec.version = Pronto::GithubResolver::VERSION
8
+ spec.authors = ["Vasily Fedoseyev"]
9
+ spec.email = ["vasilyfedoseyev@gmail.com"]
10
+
11
+ spec.summary = "Pronto formatter that marks resolved comments"
12
+ spec.homepage = "https://github.com/Vasfed/pronto-github_resolver"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 2.6.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
25
+ end
26
+ end
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "pronto", "~> 0.11"
30
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pronto-github_resolver
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Vasily Fedoseyev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-12-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pronto
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.11'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.11'
27
+ description:
28
+ email:
29
+ - vasilyfedoseyev@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rspec"
35
+ - ".rubocop.yml"
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - LICENSE.txt
39
+ - README.md
40
+ - Rakefile
41
+ - bin/console
42
+ - bin/setup
43
+ - lib/pronto/github_resolver.rb
44
+ - lib/pronto/github_resolver/version.rb
45
+ - pronto-github_resolver.gemspec
46
+ homepage: https://github.com/Vasfed/pronto-github_resolver
47
+ licenses:
48
+ - MIT
49
+ metadata:
50
+ homepage_uri: https://github.com/Vasfed/pronto-github_resolver
51
+ source_code_uri: https://github.com/Vasfed/pronto-github_resolver
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.6.0
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubygems_version: 3.0.9
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Pronto formatter that marks resolved comments
71
+ test_files: []