def createBug(self, owner, title, description, target, information_type=None, tags=None, security_related=None, private=None): """See `IMaloneApplication`.""" if (information_type is None and (security_related is not None or private is not None)): # Adapt the deprecated args to information_type. information_type = convert_to_information_type( private, security_related) params = CreateBugParams( title=title, comment=description, owner=owner, information_type=information_type, tags=tags, target=target) return getUtility(IBugSet).createBug(params)
def importBug(self, bugnode): assert not self.haveImportedBug(bugnode), ( 'the bug has already been imported') bug_id = int(bugnode.get('id')) self.logger.info('Handling bug %d', bug_id) comments = get_all(bugnode, 'comment') owner = self.getPerson(get_element(bugnode, 'reporter')) datecreated = parse_date(get_value(bugnode, 'datecreated')) title = get_value(bugnode, 'title') private = get_value(bugnode, 'private') == 'True' security_related = get_value(bugnode, 'security_related') == 'True' information_type = convert_to_information_type(private, security_related) if owner is None: owner = self.bug_importer commentnode = comments.pop(0) msg = self.createMessage(commentnode, defaulttitle=title) bug = self.product.createBug( CreateBugParams(msg=msg, datecreated=datecreated, title=title, information_type=information_type, owner=owner)) bugtask = bug.bugtasks[0] self.logger.info('Creating Launchpad bug #%d', bug.id) # Remaining setup for first comment self.createAttachments(bug, msg, commentnode) bug.findCvesInText(msg.text_contents, bug.owner) # Process remaining comments for commentnode in comments: msg = self.createMessage(commentnode, defaulttitle=bug.followup_subject()) bug.linkMessage(msg) self.createAttachments(bug, msg, commentnode) bug.name = get_value(bugnode, 'nickname') description = get_value(bugnode, 'description') if description: bug.description = description for cvenode in get_all(bugnode, 'cves/cve'): cve = getUtility(ICveSet)[get_text(cvenode)] if cve is None: raise BugXMLSyntaxError('Unknown CVE: %s' % get_text(cvenode)) bug.linkCVE(cve, self.bug_importer, check_permissions=False) tags = [] for tagnode in get_all(bugnode, 'tags/tag'): tags.append(get_text(tagnode)) bug.tags = tags # Create bugwatches bugwatchset = getUtility(IBugWatchSet) for watchnode in get_all(bugnode, 'bugwatches/bugwatch'): try: bugtracker, remotebug = bugwatchset.extractBugTrackerAndBug( watchnode.get('href')) except NoBugTrackerFound as exc: self.logger.debug('Registering bug tracker for %s', exc.base_url) bugtracker = getUtility(IBugTrackerSet).ensureBugTracker( exc.base_url, self.bug_importer, exc.bugtracker_type) remotebug = exc.remote_bug bugwatchset.createBugWatch(bug, self.bug_importer, bugtracker, remotebug) for subscribernode in get_all(bugnode, 'subscriptions/subscriber'): person = self.getPerson(subscribernode) if person is not None: bug.subscribe(person, owner) # set up bug task bugtask.datecreated = datecreated bugtask.transitionToImportance( get_enum_value(BugTaskImportance, get_value(bugnode, 'importance')), self.bug_importer) bugtask.transitionToStatus( get_enum_value(BugTaskStatus, get_value(bugnode, 'status')), self.bug_importer) bugtask.transitionToAssignee( self.getPerson(get_element(bugnode, 'assignee'))) bugtask.milestone = self.getMilestone(get_value(bugnode, 'milestone')) # Make a note of the import in the activity log: getUtility(IBugActivitySet).new(bug=bug.id, datechanged=UTC_NOW, person=self.bug_importer, whatchanged='bug', message='Imported external bug #%s' % bug_id) self.handleDuplicate(bug, bug_id, get_value(bugnode, 'duplicateof')) self.bug_id_map[bug_id] = bug.id # clear any pending bug notifications bug.expireNotifications() return bug
def importBug(self, bugnode): assert not self.haveImportedBug(bugnode), ( 'the bug has already been imported') bug_id = int(bugnode.get('id')) self.logger.info('Handling bug %d', bug_id) comments = get_all(bugnode, 'comment') owner = self.getPerson(get_element(bugnode, 'reporter')) datecreated = parse_date(get_value(bugnode, 'datecreated')) title = get_value(bugnode, 'title') private = get_value(bugnode, 'private') == 'True' security_related = get_value(bugnode, 'security_related') == 'True' information_type = convert_to_information_type( private, security_related) if owner is None: owner = self.bug_importer commentnode = comments.pop(0) msg = self.createMessage(commentnode, defaulttitle=title) bug = self.product.createBug(CreateBugParams( msg=msg, datecreated=datecreated, title=title, information_type=information_type, owner=owner)) bugtask = bug.bugtasks[0] self.logger.info('Creating Launchpad bug #%d', bug.id) # Remaining setup for first comment self.createAttachments(bug, msg, commentnode) bug.findCvesInText(msg.text_contents, bug.owner) # Process remaining comments for commentnode in comments: msg = self.createMessage( commentnode, defaulttitle=bug.followup_subject()) bug.linkMessage(msg) self.createAttachments(bug, msg, commentnode) bug.name = get_value(bugnode, 'nickname') description = get_value(bugnode, 'description') if description: bug.description = description for cvenode in get_all(bugnode, 'cves/cve'): cve = getUtility(ICveSet)[get_text(cvenode)] if cve is None: raise BugXMLSyntaxError('Unknown CVE: %s' % get_text(cvenode)) bug.linkCVE(cve, self.bug_importer) tags = [] for tagnode in get_all(bugnode, 'tags/tag'): tags.append(get_text(tagnode)) bug.tags = tags # Create bugwatches bugwatchset = getUtility(IBugWatchSet) for watchnode in get_all(bugnode, 'bugwatches/bugwatch'): try: bugtracker, remotebug = bugwatchset.extractBugTrackerAndBug( watchnode.get('href')) except NoBugTrackerFound as exc: self.logger.debug( 'Registering bug tracker for %s', exc.base_url) bugtracker = getUtility(IBugTrackerSet).ensureBugTracker( exc.base_url, self.bug_importer, exc.bugtracker_type) remotebug = exc.remote_bug bugwatchset.createBugWatch( bug, self.bug_importer, bugtracker, remotebug) for subscribernode in get_all(bugnode, 'subscriptions/subscriber'): person = self.getPerson(subscribernode) if person is not None: bug.subscribe(person, owner) # set up bug task bugtask.datecreated = datecreated bugtask.transitionToImportance( get_enum_value(BugTaskImportance, get_value(bugnode, 'importance')), self.bug_importer) bugtask.transitionToStatus( get_enum_value(BugTaskStatus, get_value(bugnode, 'status')), self.bug_importer) bugtask.transitionToAssignee( self.getPerson(get_element(bugnode, 'assignee'))) bugtask.milestone = self.getMilestone(get_value(bugnode, 'milestone')) # Make a note of the import in the activity log: getUtility(IBugActivitySet).new( bug=bug.id, datechanged=UTC_NOW, person=self.bug_importer, whatchanged='bug', message='Imported external bug #%s' % bug_id) self.handleDuplicate(bug, bug_id, get_value(bugnode, 'duplicateof')) self.bug_id_map[bug_id] = bug.id # clear any pending bug notifications bug.expireNotifications() return bug