pronto-gitlab_resolver 0.1.0

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: 5af1fa16554a37c187cf4d47bf7665cd008757b60787cd2b69e6754c1a91872a
4
+ data.tar.gz: c0b7d55c844040a2c07e62dc11d4457cff61ebb7c85f097786c802f37498f848
5
+ SHA512:
6
+ metadata.gz: fa23660d84dc2af2b4d880b0248dfef62c15209c4fb4b64c38b8e1d0d393223ed18f2bdff084b72c871596563f4b515fb2c62193903711c26604aec73adf994a
7
+ data.tar.gz: 38e062847e4fca332cf0f76707aa5fdb9297bbb1c0b022cf3b2c985e93e10c886e2a49f6f688468b26c3bc14c5f236df924550bcadeb646fe052e1cac0c53c08
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,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in pronto-gitlab_resolver.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+ gem "webmock"
12
+
13
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,102 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pronto-gitlab_resolver (0.1.0)
5
+ pronto (~> 0.11)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.8.1)
11
+ public_suffix (>= 2.0.2, < 6.0)
12
+ ast (2.4.2)
13
+ crack (0.4.5)
14
+ rexml
15
+ diff-lcs (1.5.0)
16
+ faraday (2.7.1)
17
+ faraday-net_http (>= 2.0, < 3.1)
18
+ ruby2_keywords (>= 0.0.4)
19
+ faraday-net_http (3.0.2)
20
+ gitlab (4.19.0)
21
+ httparty (~> 0.20)
22
+ terminal-table (>= 1.5.1)
23
+ hashdiff (1.0.1)
24
+ httparty (0.20.0)
25
+ mime-types (~> 3.0)
26
+ multi_xml (>= 0.5.2)
27
+ json (2.6.2)
28
+ mime-types (3.4.1)
29
+ mime-types-data (~> 3.2015)
30
+ mime-types-data (3.2022.0105)
31
+ multi_xml (0.6.0)
32
+ octokit (4.25.1)
33
+ faraday (>= 1, < 3)
34
+ sawyer (~> 0.9)
35
+ parallel (1.22.1)
36
+ parser (3.1.2.1)
37
+ ast (~> 2.4.1)
38
+ pronto (0.11.0)
39
+ gitlab (~> 4.4, >= 4.4.0)
40
+ httparty (>= 0.13.7)
41
+ octokit (~> 4.7, >= 4.7.0)
42
+ rainbow (>= 2.2, < 4.0)
43
+ rexml (~> 3.2)
44
+ rugged (>= 0.23.0, < 1.1.0)
45
+ thor (>= 0.20.3, < 2.0)
46
+ public_suffix (5.0.0)
47
+ rainbow (3.1.1)
48
+ rake (13.0.6)
49
+ regexp_parser (2.6.1)
50
+ rexml (3.2.5)
51
+ rspec (3.12.0)
52
+ rspec-core (~> 3.12.0)
53
+ rspec-expectations (~> 3.12.0)
54
+ rspec-mocks (~> 3.12.0)
55
+ rspec-core (3.12.0)
56
+ rspec-support (~> 3.12.0)
57
+ rspec-expectations (3.12.0)
58
+ diff-lcs (>= 1.2.0, < 2.0)
59
+ rspec-support (~> 3.12.0)
60
+ rspec-mocks (3.12.0)
61
+ diff-lcs (>= 1.2.0, < 2.0)
62
+ rspec-support (~> 3.12.0)
63
+ rspec-support (3.12.0)
64
+ rubocop (1.39.0)
65
+ json (~> 2.3)
66
+ parallel (~> 1.10)
67
+ parser (>= 3.1.2.1)
68
+ rainbow (>= 2.2.2, < 4.0)
69
+ regexp_parser (>= 1.8, < 3.0)
70
+ rexml (>= 3.2.5, < 4.0)
71
+ rubocop-ast (>= 1.23.0, < 2.0)
72
+ ruby-progressbar (~> 1.7)
73
+ unicode-display_width (>= 1.4.0, < 3.0)
74
+ rubocop-ast (1.23.0)
75
+ parser (>= 3.1.1.0)
76
+ ruby-progressbar (1.11.0)
77
+ ruby2_keywords (0.0.5)
78
+ rugged (1.0.1)
79
+ sawyer (0.9.2)
80
+ addressable (>= 2.3.5)
81
+ faraday (>= 0.17.3, < 3)
82
+ terminal-table (3.0.2)
83
+ unicode-display_width (>= 1.1.1, < 3)
84
+ thor (1.2.1)
85
+ unicode-display_width (2.3.0)
86
+ webmock (3.18.1)
87
+ addressable (>= 2.8.0)
88
+ crack (>= 0.3.2)
89
+ hashdiff (>= 0.4.0, < 2.0.0)
90
+
91
+ PLATFORMS
92
+ x86_64-darwin-21
93
+
94
+ DEPENDENCIES
95
+ pronto-gitlab_resolver!
96
+ rake (~> 13.0)
97
+ rspec (~> 3.0)
98
+ rubocop (~> 1.21)
99
+ webmock
100
+
101
+ BUNDLED WITH
102
+ 2.3.10
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 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 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,43 @@
1
+ # Pronto::GitlabResolver
2
+
3
+ Pronto gitlab formatter extension that marks fixed warning threads as resolved.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'pronto-github_resolver', require: false
11
+ ```
12
+ The line will probably go into `:lint` group, depending on your setup.
13
+
14
+ And then execute:
15
+ ```sh
16
+ bundle install
17
+ ```
18
+
19
+ Or just:
20
+
21
+ $ bundle add pronto-gitlab_resolver
22
+
23
+
24
+ ## Usage
25
+
26
+ Pronto will pick up this from gemfile automatically.
27
+ If you already have pronto set up and working with `gitlab_mr` formatter, it should just work.
28
+
29
+ Note that bot user should not be reused for other MR comments (because this will delete/resolve all other comments that are not returned by linters on current run).
30
+
31
+ ## Development
32
+
33
+ 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.
34
+
35
+ 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).
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Vasfed/pronto-gitlab_resolver.
40
+
41
+ ## License
42
+
43
+ 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]
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pronto
4
+ module GitlabResolver
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pronto"
4
+ require_relative "gitlab_resolver/version"
5
+
6
+ module Pronto
7
+ module Formatter
8
+ module GitlabResolver
9
+ def format(messages, repo, patches)
10
+ @messages = messages
11
+ @patches = patches
12
+ super
13
+ end
14
+
15
+ def approve_pull_request(_comments_count, _additions_count, client)
16
+ resolve_old_messages(client, new_comments(@messages, @patches))
17
+
18
+ super if defined?(super)
19
+ end
20
+
21
+ def resolve_old_messages(pronto_client, new_comments)
22
+ client = pronto_client.send(:client)
23
+ slug = pronto_client.send(:slug)
24
+ pull_id = pronto_client.send(:pull_id)
25
+ bot_id = client.user.id
26
+
27
+ # this is already done in #format upstream, repeated here not to monkey-patch that much
28
+ still_actual_comments = new_comments(@messages, @patches)
29
+
30
+ threads_to_resolve = client.merge_request_discussions(slug, pull_id).auto_paginate.select do |thread|
31
+ note = thread.notes&.first
32
+ # NOTE: this may cause issues if bot is reused for some other linters that also add code comments
33
+ next unless note&.author&.id == bot_id
34
+ next unless note["position"] && note.position&.[]("new_path")
35
+ note_position = [note.position.new_path, note.position.new_line]
36
+ next if still_actual_comments[note_position].any? { |comment| comment.body == note.body }
37
+ thread.notes.size == 1
38
+ end
39
+
40
+ threads_to_resolve.each do |thread|
41
+ if ENV['PRONTO_GITLAB_DELETE_RESOLVED']
42
+ client.delete_merge_request_discussion_note(slug, pull_id, thread.id, thread.notes.first.id)
43
+ else
44
+ client.resolve_merge_request_discussion(slug, pull_id, thread.id, resolved: true)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ # if pronto did not have formatters array frozen - instead of monkeypatch we might have
53
+ # class GitlabMergeRequestResolvingReviewFormatter < GitlabMergeRequestReviewFormatter
54
+ # prepend GitlabResolver
55
+ # end
56
+ Pronto::Formatter::GitlabMergeRequestReviewFormatter.prepend(Pronto::Formatter::GitlabResolver)
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/pronto/gitlab_resolver/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "pronto-gitlab_resolver"
7
+ spec.version = Pronto::GitlabResolver::VERSION
8
+ spec.authors = ["Vasily Fedoseyev"]
9
+ spec.email = ["vasilyfedoseyev@gmail.com"]
10
+
11
+ spec.summary = "Pronto gitlab formatter extension that marks resolved comments"
12
+ # spec.description = "TODO: Write a longer description or delete this line."
13
+ spec.homepage = "https://github.com/Vasfed/pronto-gitlab_resolver"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
20
+
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject do |f|
23
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
24
+ end
25
+ end
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_dependency "pronto", "~> 0.11"
29
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pronto-gitlab_resolver
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Vasily Fedoseyev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-11-22 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
39
+ - README.md
40
+ - Rakefile
41
+ - lib/pronto/gitlab_resolver.rb
42
+ - lib/pronto/gitlab_resolver/version.rb
43
+ - pronto-gitlab_resolver.gemspec
44
+ homepage: https://github.com/Vasfed/pronto-gitlab_resolver
45
+ licenses:
46
+ - MIT
47
+ metadata:
48
+ homepage_uri: https://github.com/Vasfed/pronto-gitlab_resolver
49
+ source_code_uri: https://github.com/Vasfed/pronto-gitlab_resolver
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 2.6.0
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubygems_version: 3.1.6
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: Pronto gitlab formatter extension that marks resolved comments
69
+ test_files: []