| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
from breezy import ( |
| 20 |
bugtracker, |
| 21 |
config, |
| 22 |
lazy_regex, |
| 23 |
) |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
_bug_id_re = lazy_regex.lazy_compile(r'(?:' |
| 28 |
r'bugs/' |
| 29 |
r'|ticket/' |
| 30 |
r'|show_bug\.cgi\?id=' |
| 31 |
r'|issues/(?:show/)?' |
| 32 |
r'|DispForm.aspx\?ID=' |
| 33 |
r'|default.asp\?' |
| 34 |
r'|issue' |
| 35 |
r'|view.php\?id=' |
| 36 |
r'|aid=' |
| 37 |
r'|task_id=' |
| 38 |
r'|task/' |
| 39 |
r')(\d+)(?:\b|$)') |
| 40 |
|
| 41 |
|
| 42 |
_jira_bug_id_re = lazy_regex.lazy_compile(r'(?:.*/browse/)([A-Z][A-Z0-9_]*-\d+)($)') |
| 43 |
|
| 44 |
|
| 45 |
_unique_bugtrackers = ('lp', 'deb', 'gnome') |
| 46 |
|
| 47 |
_bugtracker_re = lazy_regex.lazy_compile('(bugtracker|trac|bugzilla)_(.+)_url') |
| 48 |
|
| 49 |
|
| 50 |
def get_bug_id(bug_url): |
| 51 |
match = _bug_id_re.search(bug_url) |
| 52 |
if match: |
| 53 |
return match.group(1) |
| 54 |
match = _jira_bug_id_re.search(bug_url) |
| 55 |
if match: |
| 56 |
return match.group(1) |
| 57 |
return None |
| 58 |
|
| 59 |
|
| 60 |
class FakeBranchForBugs(object): |
| 61 |
"""Fake branch required for breezy/bugtracker.py""" |
| 62 |
|
| 63 |
def __init__(self): |
| 64 |
self._config = config.GlobalConfig() |
| 65 |
|
| 66 |
def get_config(self): |
| 67 |
return self._config |
| 68 |
|
| 69 |
|
| 70 |
def bug_urls_to_ids(bug_urls, branch=None): |
| 71 |
"""Convert list of bug URLs to list of bug ids in form tag:id. |
| 72 |
|
| 73 |
@param bug_urls: list of bug URLs from revision property 'bugs'. |
| 74 |
@param branch: current branch object or None. |
| 75 |
""" |
| 76 |
result = [] |
| 77 |
urls_dict = {} |
| 78 |
for i in bug_urls: |
| 79 |
url = i.split(' ')[0] |
| 80 |
n = get_bug_id(url) |
| 81 |
if n: |
| 82 |
urls_dict[url] = n |
| 83 |
if not urls_dict: |
| 84 |
return result |
| 85 |
|
| 86 |
bug_tags = {} |
| 87 |
bug_tags.update(get_unique_bug_tags()) |
| 88 |
bug_tags.update(get_global_bug_tags()) |
| 89 |
if branch is not None: |
| 90 |
bug_tags.update(get_branch_bug_tags(branch)) |
| 91 |
else: |
| 92 |
branch = FakeBranchForBugs() |
| 93 |
|
| 94 |
for k,n in urls_dict.items(): |
| 95 |
for tag in bug_tags: |
| 96 |
url = bugtracker.get_bug_url(tag, branch, n) |
| 97 |
if url == k: |
| 98 |
result.append(tag+':'+n) |
| 99 |
break |
| 100 |
return sorted(result) |
| 101 |
|
| 102 |
|
| 103 |
def get_user_bug_trackers_tags(config_keys): |
| 104 |
"""Return dict of abbreviated bugtrackers tags from user config. |
| 105 |
|
| 106 |
@param config_keys: options names from config which could be |
| 107 |
bugtracker settings. |
| 108 |
|
| 109 |
@return: dict with tags as keys and bugtracker_type as values, |
| 110 |
where bugtracker_type is prefix of tag entry in config_dict. |
| 111 |
Possible prefixes are: bugtracker, trac, bugzilla |
| 112 |
""" |
| 113 |
result = {} |
| 114 |
for key in config_keys: |
| 115 |
m = _bugtracker_re.match(key) |
| 116 |
if m: |
| 117 |
result[m.group(2)] = m.group(1) |
| 118 |
return result |
| 119 |
|
| 120 |
def get_unique_bug_tags(): |
| 121 |
"""Return dict of global unique bugtrackers, e.g. Launchpad.""" |
| 122 |
return dict([(i, 'unique') for i in _unique_bugtrackers]) |
| 123 |
|
| 124 |
def get_global_bug_tags(): |
| 125 |
"""Return bug tags collected from global config bazaar.conf""" |
| 126 |
cfg = config.GlobalConfig() |
| 127 |
keys = list(cfg._get_parser().get('DEFAULT', {}).keys()) |
| 128 |
return get_user_bug_trackers_tags(keys) |
| 129 |
|
| 130 |
def get_branch_bug_tags(branch): |
| 131 |
"""Return bug tags collected from branch configs |
| 132 |
(branch.conf and locations.conf). |
| 133 |
""" |
| 134 |
result = {} |
| 135 |
cfg = branch.get_config() |
| 136 |
loc_cfg = cfg._get_location_config() |
| 137 |
keys = loc_cfg._get_parser().scalars |
| 138 |
result.update(get_user_bug_trackers_tags(keys)) |
| 139 |
br_cfg = cfg._get_branch_data_config() |
| 140 |
keys = br_cfg._get_parser().scalars |
| 141 |
result.update(get_user_bug_trackers_tags(keys)) |
| 142 |
return result |