Skip to content

Commit 0393749

Browse files
committed
Adding PAC-Jira-crucible review status script
1 parent 04cb952 commit 0393749

2 files changed

Lines changed: 162 additions & 0 deletions

File tree

crucible/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Create a review report based on a PAC markdown release note and Jira and Crucible
2+
3+
The python script creates an ascii review report harvesting data from Crucible based on a report already generated by
4+
PAC (Praqmatic Automated Changelog) and this template: https://github.com/Praqma/Praqmatic-Automated-Changelog/blob/master/templates/default_id_report.md
5+
6+
## Instructions
7+
* Update the script with credentials
8+
* Update the script with server url
9+
* Run the script: `python crucible_review_report.py --pac_md_file <file> [ --listaccum true ]`
10+
11+
## NOTES
12+
* Orignally developed at a customer some time ago, so the instructions are not verified

crucible/crucible_review_report.py

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
import re
2+
import argparse
3+
import requests
4+
import json
5+
from dotmap import DotMap
6+
7+
8+
user='<user_name>'
9+
password='<password>'
10+
11+
crucible_rest_base_url='<url>/rest-service/' #http_base_url
12+
crucible_reviewsForIssue_extension_url='search-v1/reviewsForIssue?jiraKey='
13+
crucible_review_interface_extension_url='reviews-v1/'
14+
15+
headers={'content-type':'application/json', 'accept':'application/json'}
16+
auth=(user,password)
17+
18+
parser = argparse.ArgumentParser()
19+
parser.add_argument("-f", \
20+
"--pac_md_file", \
21+
required=True, \
22+
help="The markdown file produced by PAC tools" )
23+
parser.add_argument("-d", \
24+
"--debug", \
25+
action='store_true', \
26+
default='false', \
27+
help="Print debug information" )
28+
parser.add_argument("-a", \
29+
"--listaccum", \
30+
action='store_true', \
31+
default='false', \
32+
help="Also list the commits for Accumulated .... merges from ready2master. String match based" )
33+
34+
args = parser.parse_args()
35+
36+
pac_md_file=args.pac_md_file
37+
debug=args.debug
38+
listaccum=args.listaccum
39+
40+
41+
review_ok=[]
42+
review_review=[]
43+
review_draft=[]
44+
review_other=[]
45+
46+
def get_issue_ok_list_crucible(issue_id):
47+
reviewsForIssue = crucible_rest_base_url
48+
reviewsForIssue += crucible_reviewsForIssue_extension_url
49+
reviewsForIssue += issue_id
50+
# print reviewsForIssue
51+
r = requests.get(reviewsForIssue, auth=auth, headers=headers)
52+
53+
parsed_json = json.loads(r.text)
54+
55+
# print json.dumps(parsed_json, sort_keys=True, indent=4)
56+
57+
reviewData_list = parsed_json['reviewData']
58+
reviews=[]
59+
for reviewitem in reviewData_list:
60+
permaId = reviewitem['permaId']['id']
61+
reviews.append(permaId)
62+
63+
64+
for review in reviews:
65+
url_str = crucible_rest_base_url
66+
url_str += crucible_review_interface_extension_url
67+
url_str += review
68+
url_str += '/details'
69+
r = requests.get(url_str, auth=auth, headers=headers)
70+
parsed_json = json.loads(r.text)
71+
# print json.dumps(parsed_json, sort_keys=True, indent=4)
72+
73+
jsonmap = DotMap(parsed_json)
74+
review_status = jsonmap.state
75+
if review_status == 'Closed':
76+
for revision, revision2 in jsonmap.reviewItems.items():
77+
string = revision2[0]['expandedRevisions'][0]['revision'][:7]
78+
review_ok.append(string)
79+
elif review_status == 'Review':
80+
for revision, revision2 in jsonmap.reviewItems.items():
81+
string = revision2[0]['expandedRevisions'][0]['revision'][:7]
82+
review_review.append(string)
83+
elif review_status == 'Draft' :
84+
for revision, revision2 in jsonmap.reviewItems.items():
85+
string = revision2[0]['expandedRevisions'][0]['revision'][:7]
86+
review_draft.append(string)
87+
else:
88+
for revision, revision2 in jsonmap.reviewItems.items():
89+
string = revision2[0]['expandedRevisions'][0]['revision'][:7]
90+
string += ':' + review_status
91+
review_other.append(string)
92+
93+
94+
pac_issuenone_regex = re.compile('^## [Unspecified|Nones].*$')
95+
pac_issueid_regex = re.compile('^##\s(SAM-\d+).*$')
96+
pac_issueid_accum_regex = re.compile('^-\s([a-z0-9]{7}):\s(Accumulated commit of the following from branch.*$)')
97+
pac_issueid_real_regex = re.compile('^-\s([a-z0-9]{7}):\s(.*$)')
98+
pac_issueid_stats_regex = re.compile('^##\sStatistics')
99+
100+
with open(pac_md_file) as f:
101+
for line in f:
102+
m = pac_issueid_regex.match(line)
103+
if m:
104+
get_issue_ok_list_crucible(m.group().replace('## ','').split(' ')[0])
105+
continue
106+
107+
#print review_ok
108+
#print review_review
109+
#print review_draft
110+
#print review_other
111+
112+
with open(pac_md_file) as f:
113+
for line in f:
114+
m = pac_issueid_regex.match(line)
115+
if m:
116+
print '\n'
117+
print m.group().replace('## ','').replace(' Unspecified','Unspecified').replace(' Nones', 'Nones')
118+
# Unspecified','Unspecified').replace(' Nones:)
119+
# get_issue(m.group().replace('##',''))
120+
continue
121+
122+
m = pac_issueid_accum_regex.match(line)
123+
if m:
124+
if listaccum == True:
125+
print "( )Accum : " + m.group(1)[0:7] + " " + m.group(2)
126+
continue
127+
128+
m = pac_issueid_real_regex.match(line)
129+
if m:
130+
if m.group(1)[0:7] in review_ok:
131+
print " (+)Real : " + m.group(1)[0:7] + " " + m.group(2)
132+
elif m.group(1)[0:7] in review_review:
133+
print " (r)Real : " + m.group(1)[0:7] + " " + m.group(2)
134+
elif m.group(1)[0:7] in review_draft:
135+
print " (d)Real : " + m.group(1)[0:7] + " " + m.group(2)
136+
else:
137+
print " ( )Real : " + m.group(1)[0:7] + " " + m.group(2)
138+
continue
139+
140+
pac_issueid_stats_regex
141+
m = pac_issuenone_regex.match(line)
142+
if m:
143+
print
144+
print (m.group().replace('## ', '') + ':')
145+
continue
146+
147+
if review_other:
148+
print "For some reason these reviews are in weird state, but refered:"
149+
for review in review_other:
150+
print review

0 commit comments

Comments
 (0)