def make_bug_watch_updater(checkwatches_master, bug_watch, external_bugtracker, server_time=None, can_import_comments=False, can_push_comments=False, can_back_link=False): """Helper function to create a BugWatchUpdater instance.""" if server_time is None: server_time = datetime.now() remote_bug_updater = checkwatches_master.remote_bug_updater_factory( checkwatches_master, external_bugtracker, bug_watch.remotebug, [bug_watch.id], [], server_time) bug_watch_updater = BugWatchUpdater( remote_bug_updater, bug_watch, remote_bug_updater.external_bugtracker) bug_watch_updater.can_import_comments = can_import_comments bug_watch_updater.can_push_comments = can_push_comments bug_watch_updater.can_back_link = can_back_link return bug_watch_updater
def updateRemoteBug(self): with self.transaction: bug_watches = self._getBugWatchesForRemoteBug() # If there aren't any bug watches for this remote bug, # just log a warning and carry on. if len(bug_watches) == 0: self.warning( "Spurious remote bug ID: No watches found for " "remote bug %s on %s" % ( self.remote_bug, self.external_bugtracker.baseurl)) return # Mark them all as checked. for bug_watch in bug_watches: bug_watch.lastchecked = UTC_NOW bug_watch.next_check = None # Return if this one is definitely unmodified. if self.remote_bug in self.unmodified_remote_ids: return # Save the remote bug URL for error reporting. remote_bug_url = bug_watches[0].url # Save the list of local bug IDs for error reporting. local_ids = ", ".join( str(bug_id) for bug_id in sorted( watch.bug.id for watch in bug_watches)) try: new_remote_status = None new_malone_status = None new_remote_importance = None new_malone_importance = None error = None oops_id = None try: new_remote_status = ( self.external_bugtracker.getRemoteStatus( self.remote_bug)) new_malone_status = self._convertRemoteStatus( new_remote_status) new_remote_importance = ( self.external_bugtracker.getRemoteImportance( self.remote_bug)) new_malone_importance = self._convertRemoteImportance( new_remote_importance) except (InvalidBugId, BugNotFound, PrivateRemoteBug) as ex: error = get_bugwatcherrortype_for_error(ex) message = self.error_type_messages.get( error, self.error_type_message_default) self.logger.info( message % { 'bug_id': self.remote_bug, 'base_url': self.external_bugtracker.baseurl, 'local_ids': local_ids, }) # Set the error and activity on all bug watches with self.transaction: getUtility(IBugWatchSet).bulkSetError( bug_watches, error) getUtility(IBugWatchSet).bulkAddActivity( bug_watches, result=error) else: # Assuming nothing's gone wrong, we can now deal with # each BugWatch in turn. for bug_watch in bug_watches: bug_watch_updater = BugWatchUpdater( self, bug_watch, self.external_bugtracker) bug_watch_updater.updateBugWatch( new_remote_status, new_malone_status, new_remote_importance, new_malone_importance) except Exception as error: # Send the error to the log. oops_id = self.error( "Failure updating bug %r on %s (local bugs: %s)." % (self.remote_bug, self.bug_tracker_url, local_ids), properties=[ ('URL', remote_bug_url), ('bug_id', self.remote_bug), ('local_ids', local_ids)] + get_remote_system_oops_properties( self.external_bugtracker)) # We record errors against the bug watches and update # their lastchecked dates so that we don't try to # re-check them every time checkwatches runs. error_type = get_bugwatcherrortype_for_error(error) with self.transaction: getUtility(IBugWatchSet).bulkSetError( bug_watches, error_type) getUtility(IBugWatchSet).bulkAddActivity( bug_watches, result=error_type, oops_id=oops_id)