예제 #1
0
    def getRemoteStatus(self, bug_id):
        """Return the remote status for the given bug id.

        Raise BugNotFound if the bug can't be found.
        Raise InvalidBugId if the bug id has an unexpected format.
        """
        try:
            bug_id = int(bug_id)
        except ValueError:
            raise InvalidBugId("bug_id must be convertable an integer: %s" %
                               str(bug_id))

        try:
            remote_bug = self.bugs[bug_id]
        except KeyError:
            raise BugNotFound(bug_id)

        # If the bug has a valid resolution as well as a status then we return
        # that, since it's more informative than the status field on its own.
        if ('resolution' in remote_bug
                and remote_bug['resolution'] not in ['', '--', None]):
            return remote_bug['resolution']
        else:
            try:
                return remote_bug['status']
            except KeyError:
                # Some Trac instances don't include the bug status in their
                # CSV exports. In those cases we raise a error.
                raise UnknownRemoteStatusError('Status not exported.')
예제 #2
0
    def getCommentIds(self, remote_bug_id):
        """See `ISupportsCommentImport`."""
        actual_bug_id = self._getActualBugId(remote_bug_id)

        # Check that the bug exists, first.
        if actual_bug_id not in self._bugs:
            raise BugNotFound(remote_bug_id)

        # Get only the remote comment IDs and store them in the
        # 'comments' field of the bug.
        request_params = {
            'bug_ids': [actual_bug_id],
            'include_fields': ['id'],
        }
        bug_comments_dict = self.xmlrpc_proxy.Launchpad.comments(
            request_params)

        # We need to convert actual_bug_id to a string due to a quirk
        # with XML-RPC (see bug 248662).
        bug_comments = bug_comments_dict['bugs'][str(actual_bug_id)]

        # We also need to convert each comment ID to a string, since
        # that's what CheckwatchesMaster.importBugComments() expects (see
        # bug 248938).
        return [str(comment['id']) for comment in bug_comments]
예제 #3
0
 def getCommentIds(self, remote_bug_id):
     """See `ISupportsCommentImport`."""
     try:
         bug = self.bugs[int(remote_bug_id)]
     except KeyError:
         raise BugNotFound(remote_bug_id)
     else:
         return [comment_id for comment_id in bug['comments']]
예제 #4
0
 def getRemoteStatus(self, bug_id):
     """See ExternalBugTracker."""
     if not bug_id.isdigit():
         raise InvalidBugId("Bugzilla (%s) bug number not an integer: %s" %
                            (self.baseurl, bug_id))
     try:
         return self.remote_bug_status[bug_id]
     except KeyError:
         raise BugNotFound(bug_id)
예제 #5
0
    def _getActualBugId(self, bug_id):
        """Return the actual bug id for an alias or id."""
        # See if bug_id is actually an alias.
        actual_bug_id = self._bug_aliases.get(bug_id)

        # bug_id isn't an alias, so try turning it into an int and
        # looking the bug up by ID.
        if actual_bug_id is not None:
            return actual_bug_id
        else:
            try:
                actual_bug_id = int(bug_id)
            except ValueError:
                # If bug_id can't be int()'d then it's likely an alias
                # that doesn't exist, so raise BugNotFound.
                raise BugNotFound(bug_id)

            # Check that the bug does actually exist. That way we're
            # treating integer bug IDs and aliases in the same way.
            if actual_bug_id not in self._bugs:
                raise BugNotFound(bug_id)

            return actual_bug_id
예제 #6
0
    def setLaunchpadBugId(self, remote_bug, launchpad_bug_id,
                          launchpad_bug_url):
        """Set the Launchpad bug ID for a given remote bug.

        :raises BugNotFound: When `remote_bug` doesn't exist.
        """
        # If the launchpad_bug_id is None, pass 0 to set_launchpad_bug
        # to delete the bug link, since we can't send None over XML-RPC.
        if launchpad_bug_id == None:
            launchpad_bug_id = 0

        try:
            self._server.launchpad.set_launchpad_bug(remote_bug,
                                                     launchpad_bug_id)
        except xmlrpclib.Fault as fault:
            # Deal with "Ticket does not exist" faults. We re-raise
            # anything else, since they're a sign of a bigger problem.
            if fault.faultCode == FAULT_TICKET_NOT_FOUND:
                raise BugNotFound(remote_bug)
            else:
                raise
예제 #7
0
    def getCommentIds(self, remote_bug_id):
        """See `ISupportsCommentImport`."""
        actual_bug_id = self._getActualBugId(remote_bug_id)

        # Check that the bug exists, first.
        if actual_bug_id not in self._bugs:
            raise BugNotFound(remote_bug_id)

        # Get only the remote comment IDs and store them in the
        # 'comments' field of the bug.
        return_dict = self.xmlrpc_proxy.Bug.comments({
            'ids': [actual_bug_id],
            'include_fields': ['id'],
        })

        # We need to convert bug and comment ids to strings (see bugs
        # 248662 amd 248938).
        bug_comments_dict = return_dict['bugs']
        bug_comments = bug_comments_dict[str(actual_bug_id)]['comments']

        return [str(comment['id']) for comment in bug_comments]
예제 #8
0
    def getLaunchpadBugId(self, remote_bug):
        """Return the Launchpad bug for a given remote bug.

        :raises BugNotFound: When `remote_bug` doesn't exist.
        """
        try:
            timestamp, lp_bug_id = self._server.launchpad.get_launchpad_bug(
                remote_bug)
        except xmlrpclib.Fault as fault:
            # Deal with "Ticket does not exist" faults. We re-raise
            # anything else, since they're a sign of a bigger problem.
            if fault.faultCode == FAULT_TICKET_NOT_FOUND:
                raise BugNotFound(remote_bug)
            else:
                raise

        # If the returned bug ID is 0, return None, since a 0 means that
        # no LP bug is linked to the remote bug.
        if lp_bug_id == 0:
            return None
        else:
            return lp_bug_id
예제 #9
0
 def getRemoteProduct(self, remote_bug):
     """See `IExternalBugTracker`."""
     if remote_bug not in self.remote_bug_product:
         raise BugNotFound(remote_bug)
     return self.remote_bug_product[remote_bug]