forked from cms-sw/cms-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release-notes
executable file
·221 lines (170 loc) · 7.44 KB
/
release-notes
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/usr/bin/env python
from optparse import OptionParser
from os.path import exists,expanduser
from commands import getstatusoutput
from github import Github
import json
import urllib2
from sys import exit
import re
#---------------------------------------------------------
# pyGithub
#--------------------------------------------------------
#
# get an official repository from the cms-sw organization
#
def get_official_repo( github , repository_name ):
user = github.get_user()
orgs = user.get_orgs()
for org in orgs:
if (org.login == 'cms-sw'):
repo = org.get_repo( repository_name )
return repo
#
# given a line from git log, it gets the pr number
#
def get_pr_number( git_log_line ):
print git_log_line
if 'cms-sw/cmsdist' in git_log_line:
pr_number = git_log_line.split( '- cms-sw/cmsdist#' )[1].split( ' ' )[0]
else:
pr_number = git_log_line.split( '- #' )[1].split( ' ' )[0]
return pr_number
#
# it looks for the description of the pull requests listed in the release notes
# returns the release notes with the description of each pull request
#
def fill_notes_description( notes ):
new_notes = ''
for log_line in notes.splitlines():
pr_number = get_pr_number( log_line )
if 'cms-sw/cmsdist' in log_line:
title = CMSDIST_REPO.get_pull( int(pr_number) ).title
else:
title = CMSSW_REPO.get_pull( int(pr_number) ).title
log_line = log_line.replace( 'DESC' , title )
new_notes += log_line + '\n'
return new_notes
#
#defines the categories for each pr in the release notes
#
def add_categories_notes( notes , token ):
new_notes = ""
for note in notes.splitlines():
note = note.decode('ascii','ignore')
pr_number = note.split(' ')[1].replace('#','')
request = urllib2.Request("https://api.github.com/repos/cms-sw/cmssw/issues/%s/labels" % pr_number,
headers={"Authorization" : "token " + token})
labels = json.loads(urllib2.urlopen(request).read())
categories = [ l['name'].split('-')[0] for l in labels if not re.match( 'tests|orp|pending-signatures|comparison|fully|new-package' , l['name'] ) ]
if len(categories) == 0:
print "no categories for:"
print pr_number
for cat in categories:
note += " `%s` " % cat
new_notes += note + "\n"
return new_notes
def format(s, **kwds):
print kwds
return s % kwds
#
# gets release notes for cmssw
#
def get_cmssw_notes( previous_release , this_release ):
if not exists("cmssw.git"):
error, out = getstatusoutput("git clone --bare --reference /afs/cern.ch/cms/git-cmssw-mirror/cmssw.git git@github.com:cms-sw/cmssw.git")
if error:
parser.error("Error while checking out the repository:\n" + out)
error, out = getstatusoutput("GIT_DIR=cmssw.git git fetch --all --tags")
if error:
parser.error("Error while updating the repository:\n" + out)
error, notes = getstatusoutput(format("GIT_DIR=cmssw.git"
" git log --first-parent --merges --pretty='%%s: DESC' %(previous)s..%(release)s | "
"grep 'pull request' |"
"sed -e's/Merge pull request /- /;s|/[^:]*||;s/from /from @/'",
previous=previous_release,
release=this_release))
if error:
print "Error while getting release notes."
print notes
exit(1)
return fill_notes_description( notes )
#
# gets the changes in cmsdist, production architecture is the production architecture of the release
#
def get_cmsdist_notes( prev_cmsdist_tag , curr_cmsdist_tag ):
if not exists("cmsdist.git"):
error, out = getstatusoutput("git clone --bare git@github.com:cms-sw/cmsdist.git")
if error:
parser.error("Error while checking out the cmsdist repository:\n" + out)
error, out = getstatusoutput("GIT_DIR=cmssw.git git fetch --all --tags")
if error:
parser.error("Error while updating the repository:\n" + out)
error, notes = getstatusoutput(format("GIT_DIR=cmsdist.git"
" git log --first-parent --merges --pretty='%%s: DESC' %(prev_tag)s..%(curr_tag)s | "
"grep 'pull request' |"
"sed -e's/Merge pull request /- /;s|/[^:]*||;s/from /from @/'",
prev_tag=prev_cmsdist_tag,
curr_tag=curr_cmsdist_tag))
if error:
print "Error while getting release notes."
print notes
exit(1)
notes = notes.replace( '#' , 'cms-sw/cmsdist#' )
return fill_notes_description( notes )
#
# returns the comparison url to include in the notes
#
def get_comparison_url( previous_tag , current_tag , repo ):
return COMPARISON_URL % ( repo , previous_tag , current_tag )
#--------------------------------------------------------------------------------
# Start of Execution
#--------------------------------------------------------------------------------
COMPARISON_URL = 'https://github.com/cms-sw/%s/compare/%s...%s'
if __name__ == "__main__":
parser = OptionParser(usage="%(progname) <previous-release> <this-release> <previous-cmsdist-tag> <this-cmsdist-tag>")
parser.add_option("-n", "--dry-run", help="Only print out release notes. Do not execute.",
dest="dryRun", default=False, action="store_true")
opts, args = parser.parse_args()
if len(args) != 4:
parser.error("Wrong number or arguments")
prev_release = args[0]
curr_release = args[1]
prev_cmsdist_tag = args[2]
curr_cmsdist_tag = args[3]
#---------------------------------
# pyGithub intialization
#---------------------------------
TOKEN = open(expanduser("~/.github-token")).read().strip()
github = Github( login_or_token = TOKEN )
CMSSW_REPO = get_official_repo( github , 'cmssw' )
CMSDIST_REPO = get_official_repo( github , 'cmsdist' )
cmssw_notes = get_cmssw_notes( prev_release , curr_release)
cmsdist_notes = get_cmsdist_notes( prev_cmsdist_tag , curr_cmsdist_tag )
token = open(expanduser("~/.github-token")).read().strip()
cmssw_notes = add_categories_notes(cmssw_notes,token)
request = urllib2.Request("https://api.github.com/repos/cms-sw/cmssw/releases?per_page=100",
headers={"Authorization" : "token " + token})
releases = json.loads(urllib2.urlopen(request).read())
matchingRelease = [x["id"] for x in releases if x["name"] == curr_release]
if len(matchingRelease) < 1:
print "Release %s not found." % curr_release
exit(1)
releaseId = matchingRelease[0]
url = "https://api.github.com/repos/cms-sw/cmssw/releases/%s" % releaseId
request = urllib2.Request(url, headers={"Authorization" : "token " + token})
request.get_method = lambda: 'PATCH'
print "Modifying release notes for %s at %s" % (curr_release, url)
if opts.dryRun:
print cmssw_notes
print "\n cmsdist: \n"
print cmsdist_notes
print "--dry-run specified, quitting without modifying release."
print 'ALL_OK'
exit(0)
header = "#### Changes since %s:\n%s\n" % \
( prev_release , get_comparison_url( prev_release, curr_release , 'cmssw' ) )
cmsdist_header = "\n#### CMSDIST Changes between Tags %s and %s:\n%s\n" % \
( prev_cmsdist_tag , curr_cmsdist_tag , get_comparison_url( prev_cmsdist_tag, curr_cmsdist_tag , 'cmsdist' ) )
print urllib2.urlopen(request, json.dumps({"body": header + cmssw_notes + cmsdist_header + cmsdist_notes })).read()
print 'ALL_OK'