diff --git a/bin/bugzillabot b/bin/bugzillabot index a68ee6e..0346f4c 100755 --- a/bin/bugzillabot +++ b/bin/bugzillabot @@ -1,132 +1,144 @@ #!/usr/bin/env ruby # # Copyright (C) 2018 Harald Sitter # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 3 of # the License or any later version accepted by the membership of # KDE e.V. (or its successor approved by the membership of KDE # e.V.), which shall act as a proxy defined in Section 14 of # version 3 of the license. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . require 'pp' require 'date' require_relative '../lib/bugzillabot' require_relative '../lib/monkey' require_relative '../lib/template' warn 'FIXME: load username from config' BOT_USER = 'bug-janitor@kde.org'.freeze BUGZILLA_URL = Bugzillabot.config.bugzilla_url puts Bugzillabot::Connection.new.get('version').body # FIXME: our bugzilla is too old omg # p c.get 'whoami' def bug_reminded?(bug) comments = bug.comments_since_status_change comment = comments[-1] return false unless comment return true if comment.creator == BOT_USER if comment.creator == 'andrew.crouthamel@kdemail.net' && comment.text.downcase.include?('15 days. Please provide the requested information') return true end false end to_remind = [] to_close = [] +to_revert = [] bugs = Bugzillabot::Bug.search( # product: 'neon', status: 'NEEDSINFO' ) do |bug| 1.times { puts } # * Bugs placed into NEEDSINFO status will received a reminder if the ticket is: # - At least 15 days old begin delta = (Date.today - bug.changed_status_at.to_date).to_i if delta < 15 puts "Bug ##{bug.id} has needinfo for less than 15 days (#{delta}) -> skipping" next end end # AND # - Has not received any comment within 15 days # We'll now walk them again to determine the action for them. # - Bugs that had no comment in more than 15 days AND the last comment was from # the bot (i.e. a bug which was already reminded) will be closed # - Bugs which had no comment in more than 15 days get a reminder otherwise. # This will make the bot user the user to comment and thus trigger the above # scenario if it goes begin comments = bug.comments_since_status_change last_comment = comments[-1] was_reminded = bug_reminded?(bug) delta = (Date.today - last_comment.time.to_date).to_i unless comments.empty? delta ||= (Date.today - bug.changed_status_at.to_date).to_i if delta && delta >= 15 && was_reminded puts "Bug #{bug.id} had no comment within the last 30 days (#{delta}) -> CLOSE" to_close << bug elsif delta && delta >= 15 puts "Bug #{bug.id} had a comment within the last 30 days (#{delta}) -> REMIND" to_remind << bug elsif was_reminded warn "Bug #{bug.id} was already reminded. Reminder not old enough (#{delta})" else # !was_reminded # This bug is in needsinfo for more than 15 days but has a fairly recent # comment that is not a reminder and is thus considered active. warn "Bug #{bug.id} does not need actioning. [#{delta}; #{was_reminded}]" end end warn " -- Done with #{bug.id}" end 2.times { puts } # FIXME: revise config key and derive url from there to_remind.each do |bug| puts "REMINDING #{BUGZILLA_URL}/show_bug.cgi?id=#{bug.id}" end to_close.each do |bug| puts "CLOSING #{BUGZILLA_URL}/show_bug.cgi?id=#{bug.id}" end +to_revert.each do |bug| + puts "REVERTING #{BUGZILLA_URL}/show_bug.cgi?id=#{bug.id}" +end + # warn 'aborting here for now. NO CHANGES HAVE BEEN APPLIED' # exit puts "Going to close #{to_close.size} and remind #{to_remind.size} bugs" loop do puts 'enter "k" or ctrl-c to abort' break if gets.strip == 'k' end to_remind.each do |bug| puts "REMINDING #{BUGZILLA_URL}/show_bug.cgi?id=#{bug.id}" bug.comment(Template.remind) end to_close.each do |bug| puts "CLOSING #{BUGZILLA_URL}/show_bug.cgi?id=#{bug.id}" # FIXME: really worksforme? bug.update(status: 'RESOLVED', resolution: 'WORKSFORME', comment: { body: Template.close }) end + +to_revert.each do |bug| + puts "REVERTING #{BUGZILLA_URL}/show_bug.cgi?id=#{bug.id}" + bug.update(status: 'REPORTED', # NB: this is unconfirmed on bugstest still + comment: { body: Template.revert }) + +end diff --git a/data/revert.txt b/data/revert.txt new file mode 100644 index 0000000..29b36b7 --- /dev/null +++ b/data/revert.txt @@ -0,0 +1,6 @@ +Thanks for your comment! + +Automatically switching the status of this bug to REPORTED so that the KDE team +knows that the bug is ready to get confirmed. + +In the future you may also do this yourself when providing needed information. diff --git a/lib/template.rb b/lib/template.rb index ed047aa..4e49eae 100644 --- a/lib/template.rb +++ b/lib/template.rb @@ -1,47 +1,53 @@ # Copyright (C) 2018 Harald Sitter # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) version 3, or any # later version accepted by the membership of KDE e.V. (or its # successor approved by the membership of KDE e.V.), which shall # act as a proxy defined in Section 6 of version 3 of the license. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library. If not, see . # Comment templates. class Template - CLOSE = :close REMIND = :remind + CLOSE = :close + REVERT = :revert TEMPLATES = { + REMIND => 'remind.txt', CLOSE => 'close.txt', - REMIND => 'remind.txt' + REVERT => 'revert.txt' }.freeze attr_reader :data alias to_s data def initialize(type) file = TEMPLATES[type] raise "Invalid type #{type}" unless file @data = File.read(File.join(__dir__, '../data', file)) end class << self def remind Template.new(REMIND) end def close Template.new(CLOSE) end + + def revert + Template.new(REVERT) + end end end