-
Notifications
You must be signed in to change notification settings - Fork 15
/
buildinfo2tags.py
51 lines (43 loc) · 2.14 KB
/
buildinfo2tags.py
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
import pprint, requests, re, os
import sys
from xml.dom import minidom
from optparse import OptionParser
import json
pp = pprint.PrettyPrinter(indent=4)
# moar output, set = 1
debug=0
usage = "Usage: cat buildinfo.json | %prog [-n NAME] \n\n\
This script will convert a buildinfo.json to CSV list of projects, SHAs, and tags/branches."
parser = OptionParser(usage)
# required
parser.add_option("-n", dest="name", help="symbolic name to use, jbosstools-4.4.0.Final")
(options, args) = parser.parse_args()
if (not options.name):
parser.error("Must to specify ALL commandline flags; use -h for help")
j = json.load(sys.stdin)
if j:
# upstream/*/revision/knownReferences[0]/url = git repo from which build happened, eg., "git://github.com/jbosstools/jbosstools-base.git"
# upstream/*/revision/knownReferences[0]/ref = branch from which build happened, eg., "jbosstools-4.4.x" or "master"
for entry in j['upstream']:
if debug : print("[DEBUG] " + entry)
if type(j['upstream'][entry]) is dict :
if debug : print ("[DEBUG] " + " >> " + j['upstream'][entry]["revision"]["HEAD"])
if debug : print ("[DEBUG] " + " >> " + j['upstream'][entry]["revision"]["knownReferences"][0]["url"]) # github project
if debug : print ("[DEBUG] " + " >> " + j['upstream'][entry]["revision"]["knownReferences"][0]["ref"]) # branch
m = re.search('git@.+:([^.]+)/([^/]+)', j['upstream'][entry]["revision"]["knownReferences"][0]["url"]) # git@ pattern
if m:
org = m.group(1)
repo = m.group(2)
print(org + '/' + repo + ', ' + j['upstream'][entry]['revision']['HEAD'] + ', ' + options.name)
else :
m = re.search('.+/([^/]+)/([^/]+)\.git', j['upstream'][entry]["revision"]["knownReferences"][0]["url"]) # xyz.git pattern
if m:
org = m.group(1)
repo = m.group(2)
print(org + '/' + repo + ', ' + j['upstream'][entry]['revision']['HEAD'] + ', ' + options.name)
else :
print >> sys.stderr, "ERROR: Cannot find org/repo data for " + entry + ":" + j['upstream'][entry]["revision"]["knownReferences"][0]["url"]
else :
print >> sys.stderr, "ERROR: Missing data for " + entry + ":" + j['upstream'][entry]
else:
print ("[ERROR] Could not load json")