Class: Mergem::AskRultor
- Inherits:
-
Object
- Object
- Mergem::AskRultor
- Defined in:
- lib/mergem/askrultor.rb
Overview
Ask Rultor to merge a pull request.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2022-2025 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
- #ask(repo, num) ⇒ Object
-
#initialize(api, loog) ⇒ AskRultor
constructor
A new instance of AskRultor.
Constructor Details
#initialize(api, loog) ⇒ AskRultor
9 10 11 12 13 |
# File 'lib/mergem/askrultor.rb', line 9 def initialize(api, loog) @api = api @loog = loog @bots = ['renovate[bot]', 'dependabot[bot]', 'dependabot-preview[bot]'] end |
Instance Method Details
#ask(repo, num) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mergem/askrultor.rb', line 15 def ask(repo, num) begin user = @api.user[:login] rescue Octokit:: user = 'yegor256' @loog.debug('You are not using GitHub token :( Try to use --token option.') end issue = @api.issue(repo, num) title = "#{repo}##{num}" = issue[:user][:login] unless @bots.include?() @loog.debug("#{title} is authored by @#{author} (not a bot)") return true end json = @api.issue_comments(repo, num) @loog.debug("Found #{json.count} comments in #{title}") unless json.find { |j| j[:user][:login] == user }.nil? @loog.debug("#{title} was already discussed by @#{user}") return true end sha = @api.pull_request(repo, num)[:head][:sha] checks = @api.check_runs_for_ref(repo, sha)[:check_runs] checks.each do |check| if check[:status] != 'completed' @loog.debug("Check #{check[:id]} at #{title} is still running, let's try to merge later") return false end if check[:conclusion] != 'success' @loog.debug("Check #{check[:id]} at #{title} failed, no reason to try to merge") return true end @loog.debug("Check #{check[:id]} at #{title} is '#{check[:status]}/#{check[:conclusion]}', good!") end @loog.debug("All #{checks.count} check(s) completed successfully in #{title}") msg = '@rultor please, try to merge' msg += ", since #{checks.count} checks have passed" if checks.any? @api.add_comment(repo, num, msg) @loog.info("Comment added to #{title}") true end |