[asterisk-commits] Change in repotools[master]: Add web proxy support to commit_msg.py

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Mar 27 20:11:58 CDT 2015


Matt Jordan has submitted this change and it was merged.

Change subject: Add web proxy support to commit_msg.py
......................................................................


Add web proxy support to commit_msg.py

This patch allows the commit_msg.py script to connect to the issue
tracker from behind a web proxy in order to get the data it needs
to create the commit message template.

Change-Id: Ie71ccb85e09cce005847ce9bf70c603fbee3d58a
---
M commit_msg.py
1 file changed, 20 insertions(+), 15 deletions(-)

Approvals:
  Mark Michelson: Looks good to me, but someone else must approve
  Matt Jordan: Looks good to me, approved; Verified
  Jared K. Smith: Looks good to me, but someone else must approve



diff --git a/commit_msg.py b/commit_msg.py
index f9b8849..622f006 100755
--- a/commit_msg.py
+++ b/commit_msg.py
@@ -9,7 +9,7 @@
     - Add patch license number when available via REST
 """
 
-from httplib import HTTPSConnection
+from urllib2 import Request, urlopen, URLError
 from optparse import OptionParser
 import sys, os
 import json
@@ -23,16 +23,18 @@
 if not args:
     print >> sys.stderr, "Requres a JIRA issue number"
     sys.exit(1)
-
-con = HTTPSConnection('issues.asterisk.org')
-con.request("GET", "/jira/rest/api/latest/issue/%s/" % (args[0],))
-res = con.getresponse()
-data = json.loads(res.read())
-
-if res.status != 200:
-    print >> sys.stderr, res.status, res.reason
-    print >> sys.stderr, json.dumps(data, indent=4)
-    sys.exit(1)
+try:
+    req = Request("https://issues.asterisk.org/jira/rest/api/latest/issue/%s" % (args[0],))
+    res = urlopen(req)
+except URLError as e:
+    if hasattr(e, 'reason'):
+        print >> sys.stderr, 'Reason: ', e.reason
+        sys.exit(1)
+    elif hasattr(e, 'code'):
+        print >> sys.stderr, 'Error code: ', e.code
+        sys.exit(1)
+else:
+    data = json.loads(res.read())
 
 print "\nDoes this commit close issue %s? (y/n)" % (args[0],),
 if raw_input()[0] in ['y', 'Y']:
@@ -59,11 +61,14 @@
     for x in data['fields']['attachment']:
         licenseid = 0
         try:
-            con.request("GET", "/jira/rest/api/2/attachment/%s/" % x['id'])
-            res = con.getresponse()
+            req = Request("https://issues.asterisk.org/jira/rest/api/2/attachment/%s/" % x['id'])
+            res = urlopen(req)
             licenseid = json.loads(res.read())['properties']['license']
-        except:
-            '''Supress Exception'''
+        except URLError as e:
+            if hasattr(e, 'reason'):
+                print >> sys.stderr, 'Reason: ', e.reason
+            elif hasattr(e, 'code'):
+                print >> sys.stderr, 'Error code: ', e.code
         if licenseid != 2:
             attachments.append("    %s submitted by %s (license %d)" % (x['filename'], x['author']['name'], licenseid))
 except:

-- 
To view, visit https://gerrit.asterisk.org/13
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie71ccb85e09cce005847ce9bf70c603fbee3d58a
Gerrit-PatchSet: 3
Gerrit-Project: repotools
Gerrit-Branch: master
Gerrit-Owner: Michael L. Young <elgueromexicano at gmail.com>
Gerrit-Reviewer: Jared K. Smith <jaredsmith at jaredsmith.net>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>



More information about the asterisk-commits mailing list