diff --git a/bin/bugzillabot b/bin/bugzillabot index 70ec833..cf005e2 100755 --- a/bin/bugzillabot +++ b/bin/bugzillabot @@ -1,149 +1,164 @@ #!/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 'time' require_relative '../lib/bugzillabot' require_relative '../lib/monkey' require_relative '../lib/template' +# Super old legacy bugs which used NEEDSINFO as (semi-)closure state. +# Don't disturb them. This is also checked programatically but to save +# processing these well know ones are hardcoded. +BLACK_LIST = [142229, 151886, 171627, 196335, 214336, 219515, 257027, 261034, + 278816, 279471, 317893, 319419, 363242, 384661] + 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 = [] Bugzillabot::Bug.search(status: 'NEEDSINFO') do |bug| + next if BLACK_LIST.include?(bug.id) + 1.times { puts } if bug.product == 'krita' comments = bug.comments_since_status_change if comments.any? { |x| x.creator == bug.creator } puts "Bug ##{bug.id} had a comment from reporter -> reverting" to_revert << bug next end end # * 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 + # Skip super old bugs to not disturb legacy bugs. In the past some + # projects (in particular valgrind used NEEDSINFO as a closure state). + if delta >= 365 + puts "Bug #{bug.id} super old (#{delta}) -> skipping" + else + puts "Bug #{bug.id} had a comment within the last 30 days (#{delta}) -> REMIND" + to_remind << bug + end 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