def test_process_one(self): remote_bug = { "id": 12345, "number": 1234, "state": "open", "labels": [], } _add_rate_limit_response("api.github.com") responses.add( "GET", "https://api.github.com/repos/user/repository/issues/1234", json=remote_bug) bug = self.factory.makeBug() bug_tracker = self.factory.makeBugTracker( base_url="https://github.com/user/repository/issues", bugtrackertype=BugTrackerType.GITHUB) bug.addWatch( bug_tracker, "1234", getUtility(ILaunchpadCelebrities).janitor) self.assertEqual( [("1234", None)], [(watch.remotebug, watch.remotestatus) for watch in bug_tracker.watches]) transaction.commit() logger = BufferLogger() bug_watch_updater = CheckwatchesMaster(transaction, logger=logger) github = get_external_bugtracker(bug_tracker) bug_watch_updater.updateBugWatches(github, bug_tracker.watches) self.assertEqual( "INFO Updating 1 watches for 1 bugs on " "https://api.github.com/repos/user/repository\n", logger.getLogBuffer()) self.assertEqual( [("1234", BugTaskStatus.NEW)], [(watch.remotebug, github.convertRemoteStatus(watch.remotestatus)) for watch in bug_tracker.watches])
def test_process_many(self): remote_bugs = [ {"id": bug_id + 1, "number": bug_id, "state": "open" if (bug_id % 2) == 0 else "closed", "labels": []} for bug_id in range(1000, 1010)] _add_rate_limit_response("api.github.com") responses.add( "GET", "https://api.github.com/repos/user/repository/issues", json=remote_bugs) bug = self.factory.makeBug() bug_tracker = self.factory.makeBugTracker( base_url="https://github.com/user/repository/issues", bugtrackertype=BugTrackerType.GITHUB) for remote_bug in remote_bugs: bug.addWatch( bug_tracker, str(remote_bug["number"]), getUtility(ILaunchpadCelebrities).janitor) transaction.commit() logger = BufferLogger() bug_watch_updater = CheckwatchesMaster(transaction, logger=logger) github = get_external_bugtracker(bug_tracker) bug_watch_updater.updateBugWatches(github, bug_tracker.watches) self.assertEqual( "INFO Updating 10 watches for 10 bugs on " "https://api.github.com/repos/user/repository\n", logger.getLogBuffer()) self.assertContentEqual( [(str(bug_id), BugTaskStatus.NEW) for bug_id in (1000, 1002, 1004, 1006, 1008)] + [(str(bug_id), BugTaskStatus.FIXRELEASED) for bug_id in (1001, 1003, 1005, 1007, 1009)], [(watch.remotebug, github.convertRemoteStatus(watch.remotestatus)) for watch in bug_tracker.watches])
def import_debian_bugs(bugs_to_import, logger=None): """Import the specified Debian bugs into Launchpad.""" if logger is None: logger = log debbugs = getUtility(ILaunchpadCelebrities).debbugs external_debbugs = get_external_bugtracker(debbugs) bug_watch_updater = CheckwatchesMaster(transaction, logger) debian = getUtility(ILaunchpadCelebrities).debian for debian_bug in bugs_to_import: existing_bug_ids = [ str(bug.id) for bug in debbugs.getBugsWatching(debian_bug) ] if len(existing_bug_ids) > 0: logger.warning( "Not importing debbugs #%s, since it's already linked" " from LP bug(s) #%s." % (debian_bug, ', '.join(existing_bug_ids))) continue bug = bug_watch_updater.importBug(external_debbugs, debbugs, debian, debian_bug) [debian_task] = bug.bugtasks bug_watch_updater.updateBugWatches(external_debbugs, [debian_task.bugwatch]) target = getUtility(ILaunchpadCelebrities).ubuntu if debian_task.sourcepackagename: target = target.getSourcePackage(debian_task.sourcepackagename) getUtility(IBugTaskSet).createTask( bug, getUtility(ILaunchpadCelebrities).bug_watch_updater, target) logger.info("Imported debbugs #%s as Launchpad bug #%s." % (debian_bug, bug.id))
def test_process_one(self): remote_bug = [ {"id": "12345", "iid": 1234, "state": "opened", "labels": []}, ] responses.add( "GET", "https://gitlab.com/api/v4/projects/user%2Frepository/issues?" "iids[]=1234", json=remote_bug, match_querystring=True) bug = self.factory.makeBug() bug_tracker = self.factory.makeBugTracker( base_url="https://gitlab.com/user/repository/issues", bugtrackertype=BugTrackerType.GITLAB) bug.addWatch( bug_tracker, "1234", getUtility(ILaunchpadCelebrities).janitor) self.assertEqual( [("1234", None)], [(watch.remotebug, watch.remotestatus) for watch in bug_tracker.watches]) transaction.commit() logger = BufferLogger() bug_watch_updater = CheckwatchesMaster(transaction, logger=logger) gitlab = get_external_bugtracker(bug_tracker) bug_watch_updater.updateBugWatches(gitlab, bug_tracker.watches) self.assertEqual( "INFO Updating 1 watches for 1 bugs on " "https://gitlab.com/api/v4/projects/user%2Frepository\n", logger.getLogBuffer()) self.assertEqual( [("1234", BugTaskStatus.NEW)], [(watch.remotebug, gitlab.convertRemoteStatus(watch.remotestatus)) for watch in bug_tracker.watches])
def import_debian_bugs(bugs_to_import, logger=None): """Import the specified Debian bugs into Launchpad.""" if logger is None: logger = log debbugs = getUtility(ILaunchpadCelebrities).debbugs external_debbugs = get_external_bugtracker(debbugs) bug_watch_updater = CheckwatchesMaster(transaction, logger) debian = getUtility(ILaunchpadCelebrities).debian for debian_bug in bugs_to_import: existing_bug_ids = [str(bug.id) for bug in debbugs.getBugsWatching(debian_bug)] if len(existing_bug_ids) > 0: logger.warning( "Not importing debbugs #%s, since it's already linked" " from LP bug(s) #%s." % (debian_bug, ", ".join(existing_bug_ids)) ) continue bug = bug_watch_updater.importBug(external_debbugs, debbugs, debian, debian_bug) [debian_task] = bug.bugtasks bug_watch_updater.updateBugWatches(external_debbugs, [debian_task.bugwatch]) target = getUtility(ILaunchpadCelebrities).ubuntu if debian_task.sourcepackagename: target = target.getSourcePackage(debian_task.sourcepackagename) getUtility(IBugTaskSet).createTask(bug, getUtility(ILaunchpadCelebrities).bug_watch_updater, target) logger.info("Imported debbugs #%s as Launchpad bug #%s." % (debian_bug, bug.id))
def _getExternalBugTracker(self, bug_tracker): """Get the IExternalBugTracker for the given bug tracker.""" return get_external_bugtracker(bug_tracker)
def _getExternalBugTrackersAndWatches(self, bug_tracker, bug_watches): """Return an `ExternalBugTracker` instance for `bug_tracker`.""" with self.transaction: num_watches = bug_tracker.watches.count() remotesystem = ( externalbugtracker.get_external_bugtracker(bug_tracker)) # We special-case the Gnome Bugzilla. is_gnome_bugzilla = bug_tracker == ( getUtility(ILaunchpadCelebrities).gnome_bugzilla) # Probe the remote system for additional capabilities. remotesystem_to_use = remotesystem.getExternalBugTrackerToUse() # Try to hint at how many bug watches to check each time. suggest_batch_size(remotesystem_to_use, num_watches) if (is_gnome_bugzilla and remotesystem_to_use.sync_comments): # If there are no products to sync comments for, disable # comment sync and return. if len(self._syncable_gnome_products) == 0: remotesystem_to_use.sync_comments = False return [ (remotesystem_to_use, bug_watches), ] syncable_watches = [] other_watches = [] with self.transaction: reload(bug_watches) remote_bug_ids = [ bug_watch.remotebug for bug_watch in bug_watches] remote_products = ( remotesystem_to_use.getProductsForRemoteBugs( remote_bug_ids)) with self.transaction: reload(bug_watches) for bug_watch in bug_watches: if (remote_products.get(bug_watch.remotebug) in self._syncable_gnome_products): syncable_watches.append(bug_watch) else: other_watches.append(bug_watch) # For bug watches on remote bugs that are against products # in the _syncable_gnome_products list - i.e. ones with which # we want to sync comments - we return a BugzillaAPI # instance with sync_comments=True, otherwise we return a # similar BugzillaAPI instance, but with sync_comments=False. remotesystem_for_syncables = remotesystem_to_use remotesystem_for_others = copy(remotesystem_to_use) remotesystem_for_others.sync_comments = False return [ (remotesystem_for_syncables, syncable_watches), (remotesystem_for_others, other_watches), ] else: return [ (remotesystem_to_use, bug_watches), ]