2012-10-29 05:04:47 +00:00
|
|
|
import os, os.path, sys, re
|
|
|
|
import json, urllib2
|
|
|
|
from pprint import pprint
|
|
|
|
from urlparse import urlparse
|
|
|
|
import base64
|
|
|
|
import optparse, ast
|
|
|
|
|
|
|
|
class PreemptiveBasicAuthHandler(urllib2.BaseHandler):
|
|
|
|
def __init__(self, password_mgr=None):
|
|
|
|
if password_mgr is None:
|
|
|
|
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
|
|
|
|
self.passwd = password_mgr
|
|
|
|
self.add_password = self.passwd.add_password
|
|
|
|
|
|
|
|
def http_request(self,req):
|
|
|
|
uri = req.get_full_url()
|
|
|
|
user, pw = self.passwd.find_user_password(None,uri)
|
|
|
|
if pw is None: return req
|
|
|
|
raw = "%s:%s" % (user, pw)
|
|
|
|
auth = 'Basic %s' % base64.b64encode(raw).strip()
|
|
|
|
req.add_unredirected_header('Authorization', auth)
|
|
|
|
return req
|
|
|
|
|
|
|
|
def https_request(self,req):
|
|
|
|
return self.http_request(req)
|
|
|
|
|
2013-07-02 22:18:23 +00:00
|
|
|
def read_url(url):
|
2012-10-29 05:04:47 +00:00
|
|
|
handler = PreemptiveBasicAuthHandler()
|
2013-06-10 09:06:43 +00:00
|
|
|
handler.add_password(None, 'jenkins.minecraftforge.net:81', 'console_script', 'fd584bffa72fcac12181f37f80001200')
|
2012-10-29 05:04:47 +00:00
|
|
|
file = urllib2.build_opener(handler).open(url)
|
|
|
|
data = file.read()
|
|
|
|
file.close()
|
2013-07-02 22:18:23 +00:00
|
|
|
return data
|
|
|
|
|
|
|
|
def getBuildInfo(url, current_version=None):
|
|
|
|
data = read_url(url)
|
2013-04-24 17:49:33 +00:00
|
|
|
data = ast.literal_eval(data)['allBuilds']
|
2013-04-28 22:35:14 +00:00
|
|
|
data = sorted(data, key=lambda key: key['number'], reverse=False)
|
|
|
|
|
|
|
|
items = []
|
|
|
|
output = []
|
|
|
|
|
2012-10-29 05:04:47 +00:00
|
|
|
for build in data:
|
2013-03-24 03:25:08 +00:00
|
|
|
build['actions'] = filter(lambda act: act is not None, build['actions'])
|
|
|
|
build['actions'] = filter(lambda act: 'text' in act, build['actions'])
|
2012-10-29 05:04:47 +00:00
|
|
|
build['actions'] = filter(lambda act: not ' ' in act['text'], build['actions'])
|
|
|
|
if len(build['actions']) == 0:
|
2013-04-28 22:35:14 +00:00
|
|
|
build['version'] = current_version
|
|
|
|
current_version = None
|
2012-10-29 05:04:47 +00:00
|
|
|
else:
|
|
|
|
build['version'] = build['actions'][0]['text']
|
|
|
|
build['items'] = build['changeSet']['items']
|
|
|
|
for item in build['items']:
|
|
|
|
item['author'] = item['author']['fullName']
|
2013-04-28 22:35:14 +00:00
|
|
|
if build['result'] != 'SUCCESS':
|
|
|
|
items += build['items']
|
|
|
|
else:
|
|
|
|
build['items'] = items + build['items']
|
|
|
|
items = []
|
|
|
|
output += [build]
|
2012-10-29 05:04:47 +00:00
|
|
|
build.pop('changeSet')
|
|
|
|
build.pop('actions')
|
2013-04-28 22:35:14 +00:00
|
|
|
return sorted(output, key=lambda key: key['number'], reverse=True)
|
2013-07-02 22:18:23 +00:00
|
|
|
|
|
|
|
def add_latest_build(url, builds, current_version=None):
|
|
|
|
data = read_url(url)
|
|
|
|
data = ast.literal_eval(data)
|
|
|
|
number = data['number']
|
|
|
|
|
|
|
|
if builds[0]['number'] == data['number']:
|
|
|
|
return builds
|
|
|
|
|
|
|
|
for item in data['changeSet']['items']:
|
|
|
|
item['author'] = item['author']['fullName']
|
|
|
|
|
|
|
|
build = {
|
|
|
|
'number' : data['number'],
|
|
|
|
'result' : 'SUCCESS', #Currently build should always be success... Else things derp after words
|
|
|
|
'version' : current_version,
|
|
|
|
'items' : data['changeSet']['items']
|
|
|
|
}
|
|
|
|
return [build] + builds
|
2012-10-29 05:04:47 +00:00
|
|
|
|
2012-10-29 06:42:41 +00:00
|
|
|
def make_changelog(job_path, target_build, change_file, current_version=None):
|
2013-04-28 22:35:14 +00:00
|
|
|
builds = getBuildInfo('%s/api/python?tree=allBuilds[result,number,actions[text],changeSet[items[author[fullName],comment]]]&pretty=true' % job_path, current_version)
|
2013-07-02 22:18:23 +00:00
|
|
|
builds = add_latest_build('%s/lastBuild/api/python?pretty=true&tree=number,changeSet[items[author[fullName],comment]]' % job_path, builds, current_version)
|
2012-10-29 05:04:47 +00:00
|
|
|
|
|
|
|
log = [ "Changelog:" ]
|
|
|
|
|
|
|
|
for build in builds:
|
|
|
|
if int(build['number']) > target_build: continue
|
|
|
|
if len(build['items']) == 0: continue
|
|
|
|
log.append('')
|
|
|
|
if build['version'] is None:
|
2013-04-28 22:35:14 +00:00
|
|
|
log.append('Build %s' % build['number'])
|
2012-10-29 05:04:47 +00:00
|
|
|
else:
|
|
|
|
log.append('Build %s' % build['version'])
|
|
|
|
for change in build['items']:
|
|
|
|
comments = filter(lambda cmt: len(cmt) > 0, change['comment'].split('\n'))
|
|
|
|
if len(comments) > 1:
|
|
|
|
log.append('\t' + change['author'])
|
|
|
|
for comment in comments:
|
|
|
|
log.append('\t\t' + comment)
|
|
|
|
elif len(comments) == 1:
|
|
|
|
log.append('\t%s: %s' % (change['author'], comments[0]))
|
|
|
|
|
|
|
|
file = open(change_file, 'wb')
|
|
|
|
for line in log:
|
|
|
|
file.write('%s\n' % line)
|
2013-03-24 03:18:24 +00:00
|
|
|
file.close()
|
2013-04-28 22:35:14 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2013-06-10 09:06:43 +00:00
|
|
|
make_changelog("http://jenkins.minecraftforge.net:81/job/minecraftforge/", 70000, 'changelog.txt', 'pinecone')
|