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

Michael L. Young (Code Review) asteriskteam at digium.com
Thu Mar 26 16:33:08 CDT 2015


Michael L. Young has uploaded a new change for review.

  https://gerrit.asterisk.org/13

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(-)


  git pull ssh://gerrit.asterisk.org:29418/repotools refs/changes/13/13/1

diff --git a/commit_msg.py b/commit_msg.py
index e342d47..fa7a8a5 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
         attachments.append("    %s submitted by %s (license %d)" % (x['filename'], x['author']['name'], licenseid))
 except:
     attachments = None

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie71ccb85e09cce005847ce9bf70c603fbee3d58a
Gerrit-PatchSet: 1
Gerrit-Project: repotools
Gerrit-Branch: master
Gerrit-Owner: Michael L. Young <elgueromexicano at gmail.com>



More information about the asterisk-dev mailing list