From 2874294517f5867a2948db08e7ab03db073fb8c2 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 10 Feb 2015 09:36:23 +0000 Subject: Add support for attaching patches on Bugzilla 4.2+ attachment.cgi requires a token field for Bugzilla 4.2 and later. (See https://bugzilla.mozilla.org/show_bug.cgi?id=703983) This token is not the same as the overall bug's token. So from we need to load attachment.cgi as a GET before every POST, which is a bit of a pain. https://bugzilla.gnome.org/show_bug.cgi?id=700502 --- git-bz | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/git-bz b/git-bz index dbdef34..2b29641 100755 --- a/git-bz +++ b/git-bz @@ -1245,9 +1245,25 @@ class Bug(object): print self.get_url() def create_patch(self, description, comment, filename, data, obsoletes=[], status='none'): + # Bugzilla 4.2+ requires you to grab a fresh token from attachment.cgi. + url = "/attachment.cgi?bugid=" + str(self.id) + "&action=enter" + + try: + response = self.server.send_request("GET", url) + except KeyboardInterrupt: + die("Failed to retrieve attachment form: user cancelled") + if response.status != 200: + die("Failed to retrieve attachment form: %d" % response.status) + + token = re.search(r'', + response.read()) + + # Build the new form. fields = {} fields['bugid'] = str(self.id) fields['action'] = 'insert' + if token is not None: + fields['token'] = token.group(1) fields['ispatch'] = '1' fields['attachments.status'] = status fields['description'] = description -- cgit