Merge lp:~brendan-donegan/lpltk/lp-file-bug-lpltk into lp:lpltk

Proposed by Brendan Donegan on 2012-09-19
Status: Merged
Merged at revision: 181
Proposed branch: lp:~brendan-donegan/lpltk/lp-file-bug-lpltk
Merge into: lp:lpltk
Diff against target: 74 lines (+50/-1)
3 files modified
AUTHORS (+1/-0)
lpltk/LaunchpadService.py (+5/-1)
scripts/lp-file-bug (+44/-0)
To merge this branch: bzr merge lp:~brendan-donegan/lpltk/lp-file-bug-lpltk
Reviewer Review Type Date Requested Status
Bryce Harrington code 2012-09-19 Approve on 2012-09-19
Review via email: mp+125346@code.launchpad.net

Description of the Change

Add lp-file-bug which is a simple script which takes a bug title, project name (and possibly package name) and gets a description from the users preferred editor, then proceeds to file a bug in Launchpad without any messing around with browsers - finally the bug url is dumped back to the user for later reference.

A small tweak was made to LaunchpadService to support the fact that it should be possible to file a bug *only* on a project, not necessarily a package in a project. This involved checking for the presence of the 'package' parameter and only tacking on '+source/<package>' if it is present. Hopefully this maintains compatibility with existing scripts.

To post a comment you must log in.
Brendan Donegan (brendan-donegan) wrote :

Oh, a question - can I add this to scripts in setup.py?

Bryce Harrington (bryce) wrote :

Looks good, and yes the script can be added to setup.py. I will take care of that for you.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'AUTHORS'
2--- AUTHORS 2011-08-24 20:51:06 +0000
3+++ AUTHORS 2012-09-19 21:20:35 +0000
4@@ -5,3 +5,4 @@
5 Markus Korn <thekorn@gmx.de>
6 Brad Figg <brad.figg@canonical.com>
7 Brian Murray <brian@canonical.com>
8+ Brendan Donegan <brendan.donegan@canonical.com>
9
10=== modified file 'lpltk/LaunchpadService.py'
11--- lpltk/LaunchpadService.py 2012-07-11 02:15:18 +0000
12+++ lpltk/LaunchpadService.py 2012-09-19 21:20:35 +0000
13@@ -249,7 +249,11 @@
14 #
15 def create_bug(self, project, package, title, description, tags=[]):
16 proj = self.projects[project]
17- target = self.launchpad.load(proj.self_link + "/+source/" + package);
18+ target = proj.self_link
19+
20+ if package:
21+ target += "/+source/" + package
22+
23 lp_bug = self.launchpad.bugs.createBug(target=target, title=title, description=description, tags=[])
24 return self.get_bug(lp_bug.id)
25
26
27=== added file 'scripts/lp-file-bug'
28--- scripts/lp-file-bug 1970-01-01 00:00:00 +0000
29+++ scripts/lp-file-bug 2012-09-19 21:20:35 +0000
30@@ -0,0 +1,44 @@
31+#!/usr/bin/python
32+
33+import os
34+import sys
35+
36+from argparse import ArgumentParser
37+from lpltk import LaunchpadService
38+from subprocess import check_call
39+from tempfile import NamedTemporaryFile
40+
41+def main():
42+ parser = ArgumentParser("A script for filing new bugs in Launchpad.")
43+ parser.add_argument("title",
44+ help="The bug title used to describe it.")
45+ parser.add_argument("--project","-p",
46+ help="The project to file the bug against.",
47+ default="ubuntu")
48+ parser.add_argument("--package","-P",
49+ help="The package to file the bug against.")
50+ args = parser.parse_args()
51+
52+ lp = LaunchpadService()
53+
54+ # TODO: Get the description for 'your favourite editor'
55+ editor = os.environ.get('EDITOR','nano')
56+ tempfile = NamedTemporaryFile(delete=False)
57+ try:
58+ check_call([editor,tempfile.name])
59+ except CalledProcessError:
60+ print("Failed to open text editor")
61+ description = tempfile.read()
62+
63+ try:
64+ bug = lp.create_bug(args.project, args.package, title=args.title, description=description)
65+ print(bug.lp_bug.web_link)
66+ except:
67+ print("Unable to file bug in:")
68+ print("\tproject: %s" % args.project)
69+
70+ if args.package:
71+ print("\tpackage: %s" % args.package)
72+
73+if __name__ == "__main__":
74+ sys.exit(main())

Subscribers

People subscribed via source and target branches