-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch-patch
More file actions
executable file
·54 lines (42 loc) · 1.63 KB
/
fetch-patch
File metadata and controls
executable file
·54 lines (42 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/python
import os, sys
import urllib2
import json
import xml.etree.ElementTree as ET
import argparse
parser = argparse.ArgumentParser(description="Download the latest attachment off an Apache JIRA.")
parser.add_argument('jira_number', help="Apache JIRA #, e.g. hdfs-4949 or hadoop-1234. Not case-sensitive.")
args = parser.parse_args()
# Fetch the JIRA's attachments as XML
f = urllib2.urlopen("https://issues.apache.org/jira/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?jqlQuery=issueKey%3D" + args.jira_number + "&tempMax=100&field=attachments")
search_result = f.read()
f.close()
# Parse XML
root = ET.fromstring(search_result)
# Find the newest attachment based on ID (monotonically increasing)
max_id = -1
drilldown = root
for drill in ["channel", "item", "attachments"]:
drilldown = drilldown.find(drill)
if drilldown is None:
print "No attachments for %s, is it a valid JIRA?" % args.jira_number
sys.exit(1)
for attachment in drilldown.findall("attachment"):
name = attachment.get("name")
if name.endswith(".patch") or name.endswith(".txt"):
aid = int(attachment.get("id"))
max_id = max(aid, max_id)
if max_id == -1:
print "No patch attachments found!"
sys.exit(1)
f = urllib2.urlopen("https://issues.apache.org/jira/rest/api/2/attachment/%s" % max_id)
attachment = f.read()
f.close()
attach_meta = json.loads(attachment)
attach_filename = attach_meta["filename"]
attach_content_link = attach_meta["content"]
f = urllib2.urlopen(attach_content_link)
data = f.read()
with open(attach_filename, "wb") as attach:
attach.write(data)
print "Fetched", attach_filename