Skip to content

Commit

Permalink
#1 AskRultor
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Nov 4, 2022
1 parent bbffd98 commit 6bbfe21
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bin/mergem
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ begin
total = 1
else
total = Mergem::Pulls.new(api, loog, opts[:repo]).each do |repo, pr|
loog.info("PR #{repo}##{pr} checked")
title = "#{repo}/##{pr}"
next unless File.readlines(cache).find(title).nil?
Mergem::AskRultor.new(api, loog).ask(repo, pr)
open(cache, 'a') { |f| f.puts title }
loog.info("#{title} checked")
end
end
loog.debug("#{total} PRs processed")
Expand Down
44 changes: 44 additions & 0 deletions lib/mergem/askrultor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright (c) 2022 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# Ask Rultor to merge a pull request.
# Author:: Yegor Bugayenko (yegor256@gmail.com)
# Copyright:: Copyright (c) 2022 Yegor Bugayenko
# License:: MIT
class Mergem::AskRultor
def initialize(api, loog)
@api = api
@loog = loog
end

def ask(repo, num)
begin
user = @api.user[:login]
rescue Octokit::Unauthorized
user = ''
@loog.debug('You are not using GitHub token...')
end
json = @api.issue_comments(repo, num)
@loog.debug("Found #{json.count} comments in #{repo}##{num}")
return false unless json.find { |j| j[:user][:login] == user }.nil?
@api.add_comment(repo, num, '@rultor please, try to merge')
true
end
end
40 changes: 40 additions & 0 deletions test/test_askrultor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) 2022 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

require 'minitest/autorun'
require 'octokit'
require 'loog'
require_relative '../lib/mergem/askrultor'

# Test for AskRultor.
# Author:: Yegor Bugayenko (yegor256@gmail.com)
# Copyright:: Copyright (c) 2022 Yegor Bugayenko
# License:: MIT
class TestAskRultor < Minitest::Test
def test_real
api = Octokit::Client.new
m = Mergem::AskRultor.new(api, Loog::VERBOSE)
asked = m.ask('yegor256/mergem', 1)
assert(!asked)
rescue Octokit::TooManyRequests => e
puts e.message
skip
end
end

0 comments on commit 6bbfe21

Please sign in to comment.