blob: 6026339871a1415f94ff70a732a29853291c7734 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#!/usr/bin/env python
"""
Scan stdin for text matching bug references and insert the bug title into the
output on stdout.
Note that titles for private bugs are not fetched but instead are marked
(Private).
Example use:
% cat standup-notes.txt | lp-bug-ifier.py > standup-notes-expanded.txt
Required pacakages:
python-launchpadlib
Original author: kiko
"""
import os
import sys
import re
from launchpadlib import errors
from launchpadlib.launchpad import Launchpad
bug_re = re.compile(r"[Bb]ug(?:\s|<br\s*/>)*(?:\#|report|number\.?|num\.?|no\.?)?"
"(?:\s|<br\s*/>)*(?P<bugnum>\d+)")
launchpad = Launchpad.login_with(os.path.basename(sys.argv[0]), 'edge')
bugs = launchpad.bugs
def add_summary_to_bug(match):
text = match.group()
bugnum = match.group("bugnum")
try:
bug = bugs[bugnum]
summary = bug.title
except errors.HTTPError:
summary = 'Private'
return "%s (%s)" % (text, summary)
def main():
text = sys.stdin.read()
print bug_re.sub(add_summary_to_bug, text)
if __name__ == '__main__':
main()
|