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-2023 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
Returns a new instance of AskRultor.
26 27 28 29 30 |
# File 'lib/mergem/askrultor.rb', line 26 def initialize(api, loog) @api = api @loog = loog @bots = ['renovate[bot]', 'dependabot[bot]', 'dependabot-preview[bot]'] end |
Instance Method Details
#ask(repo, num) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/mergem/askrultor.rb', line 32 def ask(repo, num) begin user = @api.user[:login] rescue Octokit::Unauthorized 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 @#{} (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.count > 0 @api.add_comment(repo, num, msg) @loog.info("Comment added to #{title}") true end |