mergem 0.0.2 → 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.
data/README.md CHANGED
@@ -1,41 +1,87 @@
1
- <img alt="mergem logo" src="/logo.svg" width="64px"/>
1
+ # Auto-Ask Rultor to Merge Pull Requests from Robots
2
2
 
3
3
  [![EO principles respected here](https://www.elegantobjects.org/badge.svg)](https://www.elegantobjects.org)
4
- [![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/mergem)](http://www.rultor.com/p/yegor256/mergem)
4
+ [![DevOps By Rultor.com](https://www.rultor.com/b/yegor256/mergem)](https://www.rultor.com/p/yegor256/mergem)
5
5
  [![We recommend RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
6
6
 
7
7
  [![rake](https://github.com/yegor256/mergem/actions/workflows/rake.yml/badge.svg)](https://github.com/yegor256/mergem/actions/workflows/rake.yml)
8
- [![PDD status](http://www.0pdd.com/svg?name=yegor256/mergem)](http://www.0pdd.com/p?name=yegor256/mergem)
9
- [![Gem Version](https://badge.fury.io/rb/mergem.svg)](http://badge.fury.io/rb/mergem)
8
+ [![Gem Version](https://badge.fury.io/rb/mergem.svg)](https://badge.fury.io/rb/mergem)
10
9
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/mergem/blob/master/LICENSE.txt)
11
- [![Maintainability](https://api.codeclimate.com/v1/badges/396ec0584e0a84adc723/maintainability)](https://codeclimate.com/github/yegor256/mergem/maintainability)
12
10
  [![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/mergem.svg)](https://codecov.io/github/yegor256/mergem?branch=master)
13
- ![Lines of code](https://img.shields.io/tokei/lines/github/yegor256/mergem)
14
11
  [![Hits-of-Code](https://hitsofcode.com/github/yegor256/mergem)](https://hitsofcode.com/view/github/yegor256/mergem)
15
12
 
16
13
  This simple script may help you deal with pull requests
17
14
  coming to your GitHub repositories from robots:
18
15
 
19
16
  ```bash
20
- $ gem install mergem
17
+ gem install mergem
21
18
  ```
22
19
 
23
20
  Then, run it locally and read its output:
24
21
 
25
22
  ```bash
26
- $ mergem --repo yegor256/mergem --verbose --token <YOUR_GITHUB_TOKEN>
23
+ mergem --repo yegor256/mergem --verbose --token <YOUR_GITHUB_TOKEN>
27
24
  ```
28
25
 
26
+ First, it will find all pull requests in `yegor256/mergem` GitHub repository,
27
+ which were not yet discussed by the owner of the token. Then, it will ignore
28
+ those pull requests that are coming not
29
+ from [Renovate](https://github.com/apps/renovate)
30
+ or [Dependabot](https://github.com/dependabot). Then, it will
31
+ post `@rultor please, try to merge` text message to each pull
32
+ request left in the list.
33
+
34
+ ## Token
35
+
36
+ `mergem` requires a GitHub token to be passed via the `--token` option.
37
+ To obtain one, go to your GitHub account, then navigate to "Settings," and then
38
+ to ["Developer Settings"](https://github.com/settings/tokens).
39
+
40
+ ### Classic Token
41
+
42
+ You can create a classic token with the `public_repo` ("Access public
43
+ repositories") scope. It will grant `mergem` all the necessary permissions to
44
+ read and write comments on repositories.
45
+
46
+ ### Fine-grained Token
47
+
48
+ Another option is to create a fine-grained token with "All Repositories" access.
49
+ In this case, you will need to assign the following permissions to the token:
50
+
51
+ * Issues, "Read and write"
52
+ * Pull requests, "Read and write"
53
+ * Contents, "Read and write"
54
+
55
+ Please note that fine-grained tokens might encounter issues with repositories
56
+ not owned by you or owned by an organization. In such cases, you may need to
57
+ obtain additional approval from the organization.
58
+
59
+ > During the beta, organizations must opt in to fine-grained personal access
60
+ > tokens. If your organization has not already opted-in, then you will be
61
+ > prompted
62
+ > to opt-in and set policies when you follow the steps below.
63
+
64
+ Read about [setting a personal access][PAT] token policy for your organization.
65
+
29
66
  ## How to contribute
30
67
 
31
- Read [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
32
- Make sure you build is green before you contribute
33
- your pull request. You will need to have [Ruby](https://www.ruby-lang.org/en/) 2.3+ and
34
- [Bundler](https://bundler.io/) installed. Then:
68
+ Read these [guidelines].
69
+ Make sure your build is green before you contribute your pull request. You will
70
+ need to have [Ruby](https://www.ruby-lang.org/en/) 2.3+
71
+ and [Bundler](https://bundler.io/) installed. Then:
35
72
 
36
- ```
37
- $ bundle update
38
- $ bundle exec rake
73
+ ```bash
74
+ bundle update
75
+ bundle exec rake
39
76
  ```
40
77
 
41
78
  If it's clean and you don't see any error messages, submit your pull request.
79
+
80
+ In order to run a single test:
81
+
82
+ ```bash
83
+ bundle exec ruby test/test_askrultor.rb
84
+ ```
85
+
86
+ [PAT]: https://docs.github.com/en/organizations/managing-programmatic-access-to-your-organization/setting-a-personal-access-token-policy-for-your-organization
87
+ [guidelines]: https://www.yegor256.com/2014/04/15/github-guidelines.html
data/REUSE.toml ADDED
@@ -0,0 +1,35 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2025 Yegor Bugayenko
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ version = 1
5
+ [[annotations]]
6
+ path = [
7
+ ".DS_Store",
8
+ ".gitattributes",
9
+ ".gitignore",
10
+ ".pdd",
11
+ "**.json",
12
+ "**.md",
13
+ "**.png",
14
+ "**.txt",
15
+ "**/.DS_Store",
16
+ "**/.gitignore",
17
+ "**/.pdd",
18
+ "**/*.csv",
19
+ "**/*.jpg",
20
+ "**/*.json",
21
+ "**/*.md",
22
+ "**/*.pdf",
23
+ "**/*.png",
24
+ "**/*.svg",
25
+ "**/*.txt",
26
+ "**/*.vm",
27
+ "**/CNAME",
28
+ "**/Gemfile.lock",
29
+ "Gemfile.lock",
30
+ "README.md",
31
+ "renovate.json",
32
+ ]
33
+ precedence = "override"
34
+ SPDX-FileCopyrightText = "Copyright (c) 2025 Yegor Bugayenko"
35
+ SPDX-License-Identifier = "MIT"
data/Rakefile CHANGED
@@ -1,22 +1,5 @@
1
- # Copyright (c) 2022 Yegor Bugayenko
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the 'Software'), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- # SOFTWARE.
1
+ # SPDX-FileCopyrightText: Copyright (c) 2022-2025 Yegor Bugayenko
2
+ # SPDX-License-Identifier: MIT
20
3
 
21
4
  require 'rubygems'
22
5
  require 'rake'
@@ -31,7 +14,7 @@ def version
31
14
  Gem::Specification.load(Dir['*.gemspec'].first).version
32
15
  end
33
16
 
34
- task default: %i[clean test features rubocop xcop copyright]
17
+ task default: %i[clean test features rubocop]
35
18
 
36
19
  require 'rake/testtask'
37
20
  desc 'Run all unit tests'
@@ -55,17 +38,9 @@ require 'rubocop/rake_task'
55
38
  desc 'Run RuboCop on all directories'
56
39
  RuboCop::RakeTask.new(:rubocop) do |task|
57
40
  task.fail_on_error = true
58
- task.requires << 'rubocop-rspec'
59
41
  task.options = ['--display-cop-names']
60
42
  end
61
43
 
62
- require 'xcop/rake_task'
63
- Xcop::RakeTask.new(:xcop) do |task|
64
- task.license = 'LICENSE.txt'
65
- task.includes = ['**/*.xml', '**/*.xsl', '**/*.xsd', '**/*.html']
66
- task.excludes = ['mergem/**', 'coverage/**']
67
- end
68
-
69
44
  require 'cucumber/rake/task'
70
45
  Cucumber::Rake::Task.new(:features) do
71
46
  Rake::Cleaner.cleanup_files(['coverage'])
@@ -73,11 +48,3 @@ end
73
48
  Cucumber::Rake::Task.new(:'features:html') do |t|
74
49
  t.profile = 'html_report'
75
50
  end
76
-
77
- task :copyright do
78
- sh "grep -q -r '#{Date.today.strftime('%Y')}' \
79
- --include '*.rb' \
80
- --include '*.txt' \
81
- --include 'Rakefile' \
82
- ."
83
- end
data/bin/mergem CHANGED
@@ -1,34 +1,21 @@
1
1
  #!/usr/bin/env ruby
2
- # Copyright (c) 2022 Yegor Bugayenko
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy
5
- # of this software and associated documentation files (the 'Software'), to deal
6
- # in the Software without restriction, including without limitation the rights
7
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the Software is
9
- # furnished to do so, subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in all
12
- # copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
17
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- # SOFTWARE.
2
+ # SPDX-FileCopyrightText: Copyright (c) 2022-2025 Yegor Bugayenko
3
+ # SPDX-License-Identifier: MIT
21
4
 
22
5
  STDOUT.sync = true
23
6
 
24
7
  require 'slop'
25
8
  require 'loog'
26
9
  require 'octokit'
10
+ require 'digest'
11
+ require 'tacky'
27
12
  require 'backtrace'
28
13
  require 'fileutils'
29
14
  require 'obk'
30
15
  require_relative '../lib/mergem/version'
31
16
  require_relative '../lib/mergem/pulls'
17
+ require_relative '../lib/mergem/repos'
18
+ require_relative '../lib/mergem/askrultor'
32
19
 
33
20
  loog = Loog::REGULAR
34
21
 
@@ -48,9 +35,11 @@ opts = Slop.parse(args, strict: true, help: true) do |o|
48
35
  o.bool '--verbose', 'Print as much log messages as possible'
49
36
  o.bool '--dry', 'Make no real round trips to GitHub'
50
37
  o.string '--cache', 'Use this file as a cache, to avoid duplicated roudtrips to GitHub', default: '.mergem-cache'
51
- o.integer '--delay', 'Delay between HTTP calls to GitHub API, in milliseconds', default: 1000
38
+ o.string '--github-cache', 'Place in GitHub for cache file, e.g. "yegor256/mergem/cache/latest.txt" (repo, branch, path)'
39
+ o.integer '--delay', 'Delay between HTTP calls to GitHub API, in milliseconds', default: 100
52
40
  o.string '--token', 'GitHub authentication token'
53
- o.array '--repo', 'GitHub repo to check, e.g. yegor256/blog'
41
+ o.array '--repo', 'GitHub repo to check, e.g. yegor256/blog or yegor256/*'
42
+ o.array '--exclude', 'GitHub repository to exclude (no mask here, just name)'
54
43
  end
55
44
 
56
45
  if opts.help?
@@ -78,31 +67,70 @@ def api(opts, loog)
78
67
  loog.warn("Connecting to GitHub without a token, this may lead to errors, use --token")
79
68
  end
80
69
  api.auto_paginate = true
81
- Obk.new(api, pause: opts[:delay])
70
+ Tacky.new(Obk.new(api, pause: opts[:delay]))
82
71
  end
83
72
 
84
73
  begin
74
+ api = api(opts, loog)
85
75
  cache = File.absolute_path(opts[:cache])
76
+ blog = ''
77
+ if opts['github-cache']
78
+ org, repo, branch, path = opts['github-cache'].split('/', 4)
79
+ c = api.contents("#{org}/#{repo}", path: path, ref: branch)
80
+ File.write(cache, c[:content])
81
+ loog.info("Cache is taken from '#{org}/#{repo}' (#{File.readlines(cache).count} lines)")
82
+ sha = c[:sha]
83
+ loog.info("SHA of cache is '#{sha}'")
84
+ end
86
85
  if File.exist?(cache)
87
- loog.debug("Cache file is '#{cache}' (#{File.readlines(cache)} lines)")
86
+ loog.debug("Cache file is '#{cache}' (#{File.readlines(cache).count} lines)")
88
87
  else
89
88
  File.write(cache, '')
90
89
  loog.debug("Cache file '#{cache}' was absent")
91
90
  end
92
- api = api(opts, loog)
93
91
  if opts.dry?
94
92
  total = 1
95
93
  else
96
- total = Mergem::Pulls.new(api, loog, opts[:repo]).each do |repo, pr|
97
- title = "#{repo}/##{pr}"
98
- next unless File.readlines(cache).find(title).nil?
99
- Mergem::AskRultor.new(api, loog).ask(repo, pr)
100
- open(cache, 'a') { |f| f.puts title }
101
- loog.info("#{title} checked")
94
+ seen = File.readlines(cache, chomp: true).map { |t| t.strip }
95
+ total = 0
96
+ Mergem::Repos.new(api, loog, opts[:repo]).each do |repo|
97
+ if opts[:exclude].include?(repo)
98
+ loog.debug("'#{repo}' skipped because of --exclude")
99
+ next
100
+ end
101
+ total += Mergem::Pulls.new(api, loog, repo).each do |pr|
102
+ title = "#{repo}##{pr}"
103
+ if seen.include?(title)
104
+ loog.debug("'#{title}' is already in cache, skipping it")
105
+ next
106
+ end
107
+ if Mergem::AskRultor.new(api, loog).ask(repo, pr)
108
+ seen << title
109
+ loog.info("#{title} checked")
110
+ else
111
+ loog.info("#{title} must be checked later")
112
+ end
113
+ end
102
114
  end
115
+ File.write(cache, seen.join("\n"))
103
116
  end
104
117
  loog.debug("#{total} PRs processed")
118
+ loog.debug("There are #{File.readlines(cache).count} lines in the cache file '#{cache}'")
119
+ if opts['github-cache']
120
+ org, repo, branch, path = opts['github-cache'].split('/', 4)
121
+ lines = File.readlines(cache).count
122
+ if lines > 5000
123
+ head = lines - 5000
124
+ File.write(cache, File.readlines(cache).drop(head).join)
125
+ loog.info("Cache file is too long, we removed #{head} lines from its head")
126
+ end
127
+ api.update_contents(
128
+ "#{org}/#{repo}", path, "#{File.readlines(cache).count} lines",
129
+ sha, File.read(cache), branch: branch, file: cache
130
+ )
131
+ loog.info("Cache file was placed to '#{org}/#{repo}' (#{lines} lines)")
132
+ end
105
133
  rescue StandardError => e
106
134
  loog.error(Backtrace.new(e))
107
- exit -1
135
+ exit 1
108
136
  end
data/features/cli.feature CHANGED
@@ -1,3 +1,5 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2022-2025 Yegor Bugayenko
2
+ # SPDX-License-Identifier: MIT
1
3
  Feature: Simple Reporting
2
4
  I want to be able to build a report
3
5
 
@@ -14,3 +16,8 @@ Feature: Simple Reporting
14
16
  When I run bin/mergem with "--repo yegor256/mergem --dry --verbose"
15
17
  Then Stdout contains "1 PRs processed"
16
18
  And Exit code is zero
19
+
20
+ Scenario: Skip all repos
21
+ When I run bin/mergem with "--repo yegor256/mergem --exclude yegor256/mergem --verbose"
22
+ Then Stdout contains "skipped"
23
+ And Exit code is zero
@@ -1,3 +1,5 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2022-2025 Yegor Bugayenko
2
+ # SPDX-License-Identifier: MIT
1
3
  Feature: Gem Package
2
4
  As a source code writer I want to be able to
3
5
  package the Gem into .gem file
@@ -1,22 +1,5 @@
1
- # Copyright (c) 2022 Yegor Bugayenko
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the 'Software'), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- # SOFTWARE.
1
+ # SPDX-FileCopyrightText: Copyright (c) 2022-2025 Yegor Bugayenko
2
+ # SPDX-License-Identifier: MIT
20
3
 
21
4
  require 'nokogiri'
22
5
  require 'tmpdir'
@@ -40,13 +23,13 @@ end
40
23
 
41
24
  Given(/^I have a "([^"]*)" file with content:$/) do |file, text|
42
25
  FileUtils.mkdir_p(File.dirname(file)) unless File.exist?(file)
43
- File.write(file, text.gsub(/\\xFF/, 0xFF.chr))
26
+ File.write(file, text.gsub('\\xFF', 0xFF.chr))
44
27
  end
45
28
 
46
29
  When(%r{^I run bin/mergem with "([^"]*)"$}) do |arg|
47
30
  home = File.join(File.dirname(__FILE__), '../..')
48
31
  @stdout = `ruby -I#{home}/lib #{home}/bin/mergem #{arg}`
49
- @exitstatus = $CHILD_STATUS.exitstatus
32
+ @status = $CHILD_STATUS.exitstatus
50
33
  end
51
34
 
52
35
  Then(/^Stdout contains "([^"]*)"$/) do |txt|
@@ -58,23 +41,23 @@ Then(/^Stdout is empty$/) do
58
41
  end
59
42
 
60
43
  Then(/^Exit code is zero$/) do
61
- raise "Non-zero exit #{@exitstatus}:\n#{@stdout}" unless @exitstatus.zero?
44
+ raise "Non-zero exit #{@status}:\n#{@stdout}" unless @status.zero?
62
45
  end
63
46
 
64
47
  Then(/^Exit code is not zero$/) do
65
- raise 'Zero exit code' if @exitstatus.zero?
48
+ raise 'Zero exit code' if @status.zero?
66
49
  end
67
50
 
68
51
  When(/^I run bash with "([^"]*)"$/) do |text|
69
52
  FileUtils.copy_entry(@cwd, File.join(@dir, 'mergem'))
70
53
  @stdout = `#{text}`
71
- @exitstatus = $CHILD_STATUS.exitstatus
54
+ @status = $CHILD_STATUS.exitstatus
72
55
  end
73
56
 
74
57
  When(/^I run bash with:$/) do |text|
75
58
  FileUtils.copy_entry(@cwd, File.join(@dir, 'mergem'))
76
59
  @stdout = `#{text}`
77
- @exitstatus = $CHILD_STATUS.exitstatus
60
+ @status = $CHILD_STATUS.exitstatus
78
61
  end
79
62
 
80
63
  Given(/^It is Unix$/) do
@@ -1,21 +1,4 @@
1
- # Copyright (c) 2022 Yegor Bugayenko
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the 'Software'), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- # SOFTWARE.
1
+ # SPDX-FileCopyrightText: Copyright (c) 2022-2025 Yegor Bugayenko
2
+ # SPDX-License-Identifier: MIT
20
3
 
21
4
  require 'simplecov'
@@ -1,32 +1,15 @@
1
- # Copyright (c) 2022 Yegor Bugayenko
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the 'Software'), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- # SOFTWARE.
1
+ # SPDX-FileCopyrightText: Copyright (c) 2022-2025 Yegor Bugayenko
2
+ # SPDX-License-Identifier: MIT
20
3
 
21
4
  # Ask Rultor to merge a pull request.
22
5
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
23
- # Copyright:: Copyright (c) 2022 Yegor Bugayenko
6
+ # Copyright:: Copyright (c) 2022-2025 Yegor Bugayenko
24
7
  # License:: MIT
25
8
  class Mergem::AskRultor
26
9
  def initialize(api, loog)
27
10
  @api = api
28
11
  @loog = loog
29
- @bots = ['renovate[bot]']
12
+ @bots = ['renovate[bot]', 'dependabot[bot]', 'dependabot-preview[bot]']
30
13
  end
31
14
 
32
15
  def ask(repo, num)
@@ -34,14 +17,39 @@ class Mergem::AskRultor
34
17
  user = @api.user[:login]
35
18
  rescue Octokit::Unauthorized
36
19
  user = 'yegor256'
37
- @loog.debug('You are not using GitHub token...')
20
+ @loog.debug('You are not using GitHub token :( Try to use --token option.')
38
21
  end
39
22
  issue = @api.issue(repo, num)
40
- return false unless @bots.include?(issue[:user][:login])
23
+ title = "#{repo}##{num}"
24
+ author = issue[:user][:login]
25
+ unless @bots.include?(author)
26
+ @loog.debug("#{title} is authored by @#{author} (not a bot)")
27
+ return true
28
+ end
41
29
  json = @api.issue_comments(repo, num)
42
- @loog.debug("Found #{json.count} comments in #{repo}##{num}")
43
- return false unless json.find { |j| j[:user][:login] == user }.nil?
44
- @api.add_comment(repo, num, '@rultor please, try to merge')
30
+ @loog.debug("Found #{json.count} comments in #{title}")
31
+ unless json.find { |j| j[:user][:login] == user }.nil?
32
+ @loog.debug("#{title} was already discussed by @#{user}")
33
+ return true
34
+ end
35
+ sha = @api.pull_request(repo, num)[:head][:sha]
36
+ checks = @api.check_runs_for_ref(repo, sha)[:check_runs]
37
+ checks.each do |check|
38
+ if check[:status] != 'completed'
39
+ @loog.debug("Check #{check[:id]} at #{title} is still running, let's try to merge later")
40
+ return false
41
+ end
42
+ if check[:conclusion] != 'success'
43
+ @loog.debug("Check #{check[:id]} at #{title} failed, no reason to try to merge")
44
+ return true
45
+ end
46
+ @loog.debug("Check #{check[:id]} at #{title} is '#{check[:status]}/#{check[:conclusion]}', good!")
47
+ end
48
+ @loog.debug("All #{checks.count} check(s) completed successfully in #{title}")
49
+ msg = '@rultor please, try to merge'
50
+ msg += ", since #{checks.count} checks have passed" if checks.any?
51
+ @api.add_comment(repo, num, msg)
52
+ @loog.info("Comment added to #{title}")
45
53
  true
46
54
  end
47
55
  end
data/lib/mergem/pulls.rb CHANGED
@@ -1,43 +1,24 @@
1
- # Copyright (c) 2022 Yegor Bugayenko
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the 'Software'), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- # SOFTWARE.
1
+ # SPDX-FileCopyrightText: Copyright (c) 2022-2025 Yegor Bugayenko
2
+ # SPDX-License-Identifier: MIT
20
3
 
21
4
  # Pulls in GitHub API.
22
5
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
23
- # Copyright:: Copyright (c) 2022 Yegor Bugayenko
6
+ # Copyright:: Copyright (c) 2022-2025 Yegor Bugayenko
24
7
  # License:: MIT
25
8
  class Mergem::Pulls
26
- def initialize(api, loog, repos)
9
+ def initialize(api, loog, repo)
27
10
  @api = api
28
11
  @loog = loog
29
- @repos = repos
12
+ @repo = repo
30
13
  end
31
14
 
32
15
  def each
16
+ json = @api.pull_requests(@repo, state: 'open')
17
+ @loog.debug("Found #{json.count} pull requests in #{@repo}")
33
18
  total = 0
34
- @repos.each do |repo|
35
- json = @api.pull_requests(repo, state: 'open')
36
- @loog.debug("Found #{json.count} pull requests in #{repo}")
37
- json.each do |p|
38
- yield repo, p[:number]
39
- total += 1
40
- end
19
+ json.each do |p|
20
+ yield p[:number]
21
+ total += 1
41
22
  end
42
23
  total
43
24
  end
@@ -0,0 +1,41 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2022-2025 Yegor Bugayenko
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ # Find all repositories by the locations provided.
5
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
6
+ # Copyright:: Copyright (c) 2022-2025 Yegor Bugayenko
7
+ # License:: MIT
8
+ class Mergem::Repos
9
+ def initialize(api, loog, masks)
10
+ @api = api
11
+ @loog = loog
12
+ @masks = masks
13
+ end
14
+
15
+ def each
16
+ total = 0
17
+ names = []
18
+ @masks.each do |repo|
19
+ if repo.end_with?('/*')
20
+ org = repo.split('/')[0]
21
+ @api.repositories(org).each do |r|
22
+ n = r['full_name']
23
+ @loog.debug("Found #{n} repo in @#{org}")
24
+ names << n
25
+ end
26
+ else
27
+ names << repo
28
+ end
29
+ end
30
+ names.shuffle.each do |n|
31
+ r = @api.repository(n)
32
+ if r[:archived]
33
+ @loog.debug("Repository #{n} is archived, ignoring")
34
+ next
35
+ end
36
+ yield n
37
+ total += 1
38
+ end
39
+ total
40
+ end
41
+ end
@@ -1,27 +1,10 @@
1
- # Copyright (c) 2022 Yegor Bugayenko
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the 'Software'), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in all
11
- # copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- # SOFTWARE.
1
+ # SPDX-FileCopyrightText: Copyright (c) 2022-2025 Yegor Bugayenko
2
+ # SPDX-License-Identifier: MIT
20
3
 
21
4
  # mergem main module.
22
5
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
23
- # Copyright:: Copyright (c) 2022 Yegor Bugayenko
6
+ # Copyright:: Copyright (c) 2022-2025 Yegor Bugayenko
24
7
  # License:: MIT
25
8
  module Mergem
26
- VERSION = '0.0.2'.freeze
9
+ VERSION = '0.1.0'.freeze
27
10
  end