mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #739120 (Migrate calibre bzr commit plugin to launchpad)
This commit is contained in:
parent
99cd38f8d9
commit
32703cb261
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python2
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
|
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
|
||||||
@ -8,42 +8,20 @@ __docformat__ = 'restructuredtext en'
|
|||||||
Plugin to make the commit command automatically close bugs when the commit
|
Plugin to make the commit command automatically close bugs when the commit
|
||||||
message contains `Fix #number` or `Implement #number`. Also updates the commit
|
message contains `Fix #number` or `Implement #number`. Also updates the commit
|
||||||
message with the summary of the closed bug. It also set the `--fixes` metadata
|
message with the summary of the closed bug. It also set the `--fixes` metadata
|
||||||
appropriately. Currently only works with a Trac bug repository with the XMLRPC
|
appropriately.
|
||||||
plugin enabled.
|
|
||||||
|
|
||||||
To use copy this file into `~/.bazaar/plugins` and add the following to branch.conf
|
|
||||||
in the working tree you want to use it with::
|
|
||||||
|
|
||||||
trac_reponame_url = <url>
|
|
||||||
trac_reponame_username = <username>
|
|
||||||
trac_reponame_password = <password>
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
import os, re, xmlrpclib, subprocess
|
import re, urllib, importlib, sys
|
||||||
from bzrlib.builtins import cmd_commit as _cmd_commit, tree_files
|
from bzrlib.builtins import cmd_commit as _cmd_commit
|
||||||
from bzrlib import branch
|
|
||||||
import bzrlib
|
import bzrlib
|
||||||
|
|
||||||
|
from lxml import html
|
||||||
|
|
||||||
|
SENDMAIL = ('/home/kovid/work/kde', 'pgp_mail')
|
||||||
|
|
||||||
class cmd_commit(_cmd_commit):
|
class cmd_commit(_cmd_commit):
|
||||||
|
|
||||||
@classmethod
|
def expand_bug(self, msg):
|
||||||
def trac_url(self, username, password, url):
|
|
||||||
return url.replace('//', '//%s:%s@'%(username, password))+'/login/xmlrpc'
|
|
||||||
|
|
||||||
def get_trac_summary(self, bug, url):
|
|
||||||
print 'Getting bug summary for bug #%s'%bug,
|
|
||||||
server = xmlrpclib.ServerProxy(url)
|
|
||||||
attributes = server.ticket.get(int(bug))[-1]
|
|
||||||
print attributes['summary']
|
|
||||||
return attributes['summary']
|
|
||||||
|
|
||||||
def expand_bug(self, msg, nick, config, bug_tracker, type='trac'):
|
|
||||||
prefix = '%s_%s_'%(type, nick)
|
|
||||||
username = config.get_user_option(prefix+'username')
|
|
||||||
password = config.get_user_option(prefix+'password')
|
|
||||||
close_bug = config.get_user_option(prefix+'pattern')
|
|
||||||
if close_bug is None:
|
|
||||||
close_bug = r'(Fix|Implement|Fixes|Fixed|Implemented)\s+#(\d+)'
|
close_bug = r'(Fix|Implement|Fixes|Fixed|Implemented)\s+#(\d+)'
|
||||||
close_bug_pat = re.compile(close_bug, re.IGNORECASE)
|
close_bug_pat = re.compile(close_bug, re.IGNORECASE)
|
||||||
match = close_bug_pat.search(msg)
|
match = close_bug_pat.search(msg)
|
||||||
@ -51,71 +29,50 @@ class cmd_commit(_cmd_commit):
|
|||||||
return msg, None, None, None
|
return msg, None, None, None
|
||||||
action, bug = match.group(1), match.group(2)
|
action, bug = match.group(1), match.group(2)
|
||||||
summary = ''
|
summary = ''
|
||||||
if type == 'trac':
|
raw = urllib.urlopen('https://bugs.launchpad.net/calibre/+bug/' +
|
||||||
url = self.trac_url(username, password, bug_tracker)
|
bug).read()
|
||||||
summary = self.get_trac_summary(bug, url)
|
h1 = html.fromstring(raw).xpath('//h1[@id="edit-title"]')[0]
|
||||||
|
summary = html.tostring(h1, method='text', encoding=unicode).strip()
|
||||||
|
print 'Working on bug:', summary
|
||||||
if summary:
|
if summary:
|
||||||
msg = msg.replace('#%s'%bug, '#%s (%s)'%(bug, summary))
|
msg = msg.replace('#%s'%bug, '#%s (%s)'%(bug, summary))
|
||||||
msg = msg.replace('Fixesed', 'Fixed')
|
msg = msg.replace('Fixesed', 'Fixed')
|
||||||
return msg, bug, url, action
|
return msg, bug, action
|
||||||
|
|
||||||
|
|
||||||
def get_bugtracker(self, basedir, type='trac'):
|
|
||||||
config = os.path.join(basedir, '.bzr', 'branch', 'branch.conf')
|
|
||||||
bugtracker, nick = None, None
|
|
||||||
if os.access(config, os.R_OK):
|
|
||||||
for line in open(config).readlines():
|
|
||||||
match = re.search(r'%s_(\S+)_url\s*=\s*(\S+)'%type, line)
|
|
||||||
if match:
|
|
||||||
nick, bugtracker = match.group(1), match.group(2)
|
|
||||||
break
|
|
||||||
return nick, bugtracker
|
|
||||||
|
|
||||||
def expand_message(self, msg, tree):
|
|
||||||
nick, bugtracker = self.get_bugtracker(tree.basedir, type='trac')
|
|
||||||
if not bugtracker:
|
|
||||||
return msg
|
|
||||||
config = branch.Branch.open(tree.basedir).get_config()
|
|
||||||
msg, bug, url, action = self.expand_bug(msg, nick, config, bugtracker)
|
|
||||||
|
|
||||||
return msg, bug, url, action, nick, config
|
|
||||||
|
|
||||||
def run(self, message=None, file=None, verbose=False, selected_list=None,
|
def run(self, message=None, file=None, verbose=False, selected_list=None,
|
||||||
unchanged=False, strict=False, local=False, fixes=None,
|
unchanged=False, strict=False, local=False, fixes=None,
|
||||||
author=None, show_diff=False, exclude=None):
|
author=None, show_diff=False, exclude=None):
|
||||||
nick = config = bug = action = None
|
bug = action = None
|
||||||
if message:
|
if message:
|
||||||
try:
|
message, bug, action = self.expand_bug(message)
|
||||||
message, bug, url, action, nick, config = \
|
|
||||||
self.expand_message(message, tree_files(selected_list)[0])
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if nick and bug and not fixes:
|
if bug and not fixes:
|
||||||
fixes = [nick+':'+bug]
|
fixes = ['lp:'+bug]
|
||||||
|
|
||||||
ret = _cmd_commit.run(self, message=message, file=file, verbose=verbose,
|
ret = _cmd_commit.run(self, message=message, file=file, verbose=verbose,
|
||||||
selected_list=selected_list, unchanged=unchanged,
|
selected_list=selected_list, unchanged=unchanged,
|
||||||
strict=strict, local=local, fixes=fixes,
|
strict=strict, local=local, fixes=fixes,
|
||||||
author=author, show_diff=show_diff, exclude=exclude)
|
author=author, show_diff=show_diff, exclude=exclude)
|
||||||
if message and bug and action and nick and config:
|
if message and bug and action:
|
||||||
self.close_bug(bug, action, url, config)
|
self.close_bug(bug, action)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def close_bug(self, bug, action, url, config):
|
def close_bug(self, bug, action):
|
||||||
print 'Closing bug #%s'% bug
|
print 'Closing bug #%s'% bug
|
||||||
#nick = config.get_nickname()
|
#nick = config.get_nickname()
|
||||||
suffix = config.get_user_option('bug_close_comment')
|
suffix = ('The fix will be in the next release.'
|
||||||
if suffix is None:
|
'calibre is usually released every Friday.')
|
||||||
suffix = 'The fix will be in the next release.'
|
|
||||||
action = action+'ed'
|
action = action+'ed'
|
||||||
msg = '%s in branch %s. %s'%(action, 'lp:calibre', suffix)
|
msg = '%s in branch %s. %s'%(action, 'lp:calibre', suffix)
|
||||||
msg = msg.replace('Fixesed', 'Fixed')
|
msg = msg.replace('Fixesed', 'Fixed')
|
||||||
server = xmlrpclib.ServerProxy(url)
|
msg += '\n\n status fixreleased'
|
||||||
server.ticket.update(int(bug), msg,
|
|
||||||
{'status':'closed', 'resolution':'fixed'},
|
sys.path.insert(0, SENDMAIL[0])
|
||||||
True)
|
|
||||||
subprocess.Popen('/home/kovid/work/kde/mail.py -f --delay 10'.split())
|
sendmail = importlib.import_module(SENDMAIL[1])
|
||||||
|
|
||||||
|
to = bug+'@bugs.launchpad.net'
|
||||||
|
sendmail.sendmail(msg, to, 'Re: calibre bug '+bug)
|
||||||
|
|
||||||
|
|
||||||
bzrlib.commands.register_command(cmd_commit)
|
bzrlib.commands.register_command(cmd_commit)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user