def update_spec(launchpad, project, name, subject, link, topic=None): spec = None if p.is_no_launchpad_blueprints(project): return projects = p.project_to_groups(project) for project in projects: spec = launchpad.projects[project].getSpecification(name=name) if spec: break if not spec: return if spec.whiteboard: wb = spec.whiteboard.strip() else: wb = '' changed = False if topic: topiclink = '%s/#q,topic:%s,n,z' % (link[:link.find('/', 8)], topic) if topiclink not in wb: wb += "\n\n\nGerrit topic: %(link)s" % dict(link=topiclink) changed = True if link not in wb: wb += ("\n\n\nAddressed by: {link}\n" " {subject}\n").format(subject=subject, link=link) changed = True if changed: spec.whiteboard = wb spec.lp_save()
def find_bugs(launchpad, git_log, args): '''Find bugs referenced in the git log and return related tasks. Our regular expression is composed of three major parts: part1: Matches only at start-of-line (required). Optionally matches any word or hyphen separated words. part2: Matches the words 'bug' or 'lp' on a word boundary (required). part3: Matches a whole number (required). The following patterns will be matched properly: bug # 555555 Closes-Bug: 555555 Fixes: bug # 555555 Resolves: bug 555555 Partial-Bug: lp bug # 555555 :returns: an iterable containing Task objects. ''' project = args.project if p.is_no_launchpad_bugs(project): return [] projects = p.project_to_groups(project) part1 = r'^[\t ]*(?P<prefix>[-\w]+)?[\s:]*' part2 = r'(?:\b(?:bug|lp)\b[\s#:]*)+' part3 = r'(?P<bug_number>\d+)\s*?$' regexp = part1 + part2 + part3 matches = re.finditer(regexp, git_log, flags=re.I | re.M) # Extract unique bug tasks and associated prefixes. bugtasks = {} for match in matches: prefix = match.group('prefix') bug_num = match.group('bug_number') if bug_num not in bugtasks: try: lp_bug = launchpad.bugs[bug_num] for lp_task in lp_bug.bug_tasks: if lp_task.bug_target_name in projects: bugtasks[bug_num] = Task(lp_task, prefix) break except KeyError: # Unknown bug. pass return bugtasks.values()
def update_spec(launchpad, project, name, subject, link, topic=None): spec = None if p.is_no_launchpad_blueprints(project): return projects = p.project_to_groups(project) for project in projects: spec = launchpad.projects[project].getSpecification(name=name) if spec: break if not spec: return if spec.whiteboard: wb = spec.whiteboard.strip() else: wb = '' changed = False if topic: topiclink = '%s/#/q/topic:%s' % (link[:link.find('/', 8)], topic) if topiclink not in wb: wb += "\n\n\nGerrit topic: %(link)s" % dict(link=topiclink) changed = True if link not in wb: wb += ("\n\n\nAddressed by: {link}\n" " {subject}\n").format(subject=subject, link=link) changed = True if changed: spec.whiteboard = wb spec.lp_save()