<commit_before>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)

def getBuildInfo(url):
	handler = PreemptiveBasicAuthHandler()
	handler.add_password(None, '<PASSWORD>', 'console_script', 'd29a4bb55ecdf4f99295c77cc4364fe6')
	file = urllib2.build_opener(handler).open(url)
	data = file.read()
	file.close()
	data = ast.literal_eval(data)['builds']
	data = sorted(data, key=lambda key: key['number'], reverse=True)
	for build in data:
		build['actions'] = filter(lambda act: act is not None, build['actions'])
		build['actions'] = filter(lambda act: 'text' in act, build['actions'])
		build['actions'] = filter(lambda act: not ' ' in act['text'], build['actions'])
		if len(build['actions']) == 0:
			build['version'] = None
		else:
			build['version'] = build['actions'][0]['text']
		build['items'] = build['changeSet']['items']
		for item in build['items']:
			item['author'] = item['author']['fullName']
		build.pop('changeSet')
		build.pop('actions')
	return data
	
def make_changelog(job_path, target_build, change_file, current_version=None):
	builds = getBuildInfo('%s/api/python?tree=builds[number,actions[text],changeSet[items[author[fullName],comment]]]&pretty=true' % job_path)
	
	log = [ "Changelog:" ]
	
	for build in builds:<commit_msg>Attempted a fix for the changelog generation, should print all builds back to 1 now.<commit_after>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)

def getBuildInfo(url):
	handler = PreemptiveBasicAuthHandler()
	handler.add_password(None, 'jenkins.minecraftforge.net', 'console_script', 'd29a4bb55ecdf4f99295c77cc4364fe6')
	file = urllib2.build_opener(handler).open(url)
	data = file.read()
	file.close()
	data = ast.literal_eval(data)['allBuilds']
	data = sorted(data, key=lambda key: key['number'], reverse=True)
	for build in data:
		build['actions'] = filter(lambda act: act is not None, build['actions'])
		build['actions'] = filter(lambda act: 'text' in act, build['actions'])
		build['actions'] = filter(lambda act: not ' ' in act['text'], build['actions'])
		if len(build['actions']) == 0:
			build['version'] = None
		else:
			build['version'] = build['actions'][0]['text']
		build['items'] = build['changeSet']['items']
		for item in build['items']:
			item['author'] = item['author']['fullName']
		build.pop('changeSet')
		build.pop('actions')
	return data
	
def make_changelog(job_path, target_build, change_file, current_version=None):
	builds = getBuildInfo('%s/api/python?tree=allBuilds[number,actions[text],changeSet[items[author[fullName],comment]]]&pretty=true' % job_path)
	
	log = [ "Changelog:" ]
	
	for build in builds:
{'fraction_non_alphanumeric': 0.14697767745171808, 'fraction_numerical': 0.015299724103335842, 'mean_word_length': 6.02112676056338, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5847096', 'n_tokens_mistral': 1461, 'n_tokens_neox': 1383, 'n_words': 305}