forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request cms-sw#26 from nclopezo/add-report-merged-pr-script
Added script and html to see the summary of the merged pull requests
- Loading branch information
Showing
2 changed files
with
297 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
#! /usr/bin/env python | ||
|
||
from optparse import OptionParser | ||
from os.path import expanduser | ||
from github import Github | ||
import re | ||
import datetime | ||
import json | ||
|
||
#----------------------------------------------------------------------------------- | ||
#---- Parser Options | ||
#----------------------------------------------------------------------------------- | ||
parser = OptionParser(usage="usage: %prog RELEASE_QUEUES NUM_TAGS START_DATE" | ||
"\n RELEASE_QUEUES a list separated by commas with the release queues from which you want to get the IB tags" | ||
"\n NUM_TAGS the maximum number of tags that you want to see per release queue" | ||
"\n START_DATE Start date from which get the tags") | ||
|
||
(options, args) = parser.parse_args() | ||
|
||
#----------------------------------------------------------------------------------- | ||
#---- Review of arguments | ||
#----------------------------------------------------------------------------------- | ||
|
||
if (len(args)==0): | ||
print 'not enough arguments\n' | ||
parser.print_help() | ||
exit() | ||
|
||
release_queues_param = args[0] | ||
num_tags = int(args[1]) | ||
start_date = args[2] | ||
|
||
release_queues = release_queues_param.split(",") | ||
|
||
print "I will analyze the last %d IB Tags for the following Release Queues" % num_tags | ||
print "Starting from %s" % start_date | ||
|
||
for rq in release_queues: | ||
print rq | ||
|
||
def get_cmssw_official_repo(github): | ||
user = github.get_user() | ||
orgs = user.get_orgs() | ||
for org in orgs: | ||
if (org.login == 'cms-sw'): | ||
repo = org.get_repo('cmssw') | ||
return repo | ||
|
||
def get_commits_comparison(base,head,repo): | ||
comparison = repo.compare(base,head) | ||
commits = comparison.commits | ||
git_commits = [] | ||
for commit in commits: | ||
git_commit = official_cmssw.get_git_commit(commit.sha) | ||
git_commits.append(git_commit) | ||
return git_commits | ||
|
||
def get_list_prs_details_from_comparison(base,head,repo): | ||
print "%s --> %s:" % (base,head) | ||
git_commits = get_commits_comparison(base,head,repo) | ||
prs_details = [] | ||
for git_commit in git_commits: | ||
message = git_commit.message | ||
if 'Merge pull request' in message: | ||
number = re.sub('\n', '', message) | ||
number = re.sub(' from .*', '', number) | ||
number = re.sub('Merge pull request #', '', number) | ||
print number | ||
pull_request = repo.get_pull(int(number)) | ||
#print pull_request.title | ||
#print pull_request.url | ||
#print pull_request.user.login | ||
pr = {} | ||
pr['number'] = number | ||
pr['title'] = pull_request.title | ||
pr['author_login'] = pull_request.user.login | ||
pr['url'] = 'https://github.com/cms-sw/cmssw/pull/%s' % number | ||
print pr | ||
prs_details.append(pr) | ||
print prs_details | ||
return prs_details | ||
|
||
def get_previous_release_name(current_release): | ||
name_parts = current_release.rsplit('_',1) | ||
date_parts = name_parts[1].split("-") | ||
current_year = int(date_parts[0]) | ||
current_month = int(date_parts[1]) | ||
current_day = int(date_parts[2]) | ||
current_hour = int(date_parts[3])/100 | ||
|
||
current_datetime = datetime.datetime(current_year,current_month,current_day,current_hour) | ||
time_delta = datetime.timedelta(hours=12) | ||
previous_datetime = current_datetime - time_delta | ||
previous_release = "%s_%d-%02d-%02d-%02d00" % (name_parts[0],previous_datetime.year,previous_datetime.month,previous_datetime.day,previous_datetime.hour) | ||
return previous_release | ||
|
||
#----------------------------------------------------------------------------------- | ||
#---- Start of execution | ||
#----------------------------------------------------------------------------------- | ||
|
||
github = Github(login_or_token = open(expanduser("~/.github-token")).read().strip()) | ||
|
||
official_cmssw = get_cmssw_official_repo(github) | ||
|
||
#prs_numbers = get_list_prs_details_from_comparison("CMSSW_7_1_X_2014-02-09-1400","CMSSW_7_1_X_2014-02-10-0200",official_cmssw) | ||
|
||
|
||
results = [] | ||
|
||
for rq in release_queues: | ||
print "Analyzing %s from %s:" % (rq,start_date) | ||
current_date = start_date | ||
current_release = "%s_%s"%(rq,current_date) | ||
release_queue_results = {} | ||
release_queue_results['release_name'] = rq | ||
comparisons = [] | ||
for i in range(num_tags): | ||
comparison_info = {} | ||
print "--" | ||
previous_release = get_previous_release_name(current_release) | ||
comparison_info['compared_tags']='%s --> %s' % (previous_release, current_release) | ||
prs_details = get_list_prs_details_from_comparison(previous_release,current_release,official_cmssw) | ||
comparison_info['merged_prs'] = prs_details | ||
current_release=previous_release | ||
comparisons.append(comparison_info) | ||
release_queue_results['comparisons'] = comparisons | ||
results.append(release_queue_results) | ||
print '----------' | ||
print results | ||
|
||
out_json = open("merged_prs_summary.json", "w") | ||
json.dump(results,out_json,indent=4) | ||
out_json.close() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Merged Pull Requests</title> | ||
|
||
<link href="bootstrap/css/bootstrap.css" rel="stylesheet"> | ||
<link href="bootstrap/css/bootstrap-responsive.css" rel="stylesheet"> | ||
<link href="bootstrap/css/docs.css" rel="stylesheet"> | ||
<link href="bootstrap/js/google-code-prettify/prettify.css" rel="stylesheet"> | ||
|
||
</head> | ||
<body> | ||
<script type='text/javascript' src="http://code.jquery.com/jquery-2.1.0.js"></script> | ||
<script type='text/javascript' src="bootstrap/js/bootstrap.js"></script> | ||
|
||
|
||
<div class="container"> | ||
<div class="span3"></div> | ||
<div class="col-md-10" id="results"></div> | ||
</div> | ||
<div class="span3"> | ||
</div> | ||
|
||
<script> | ||
|
||
$(document).ready(function () { | ||
|
||
|
||
|
||
write_pr = function(pr,pr_list_group){ | ||
console.log(pr) | ||
|
||
var list_item = $('<li class="list-group-item"></li>') | ||
var item_link_text = "#".concat(pr.number) | ||
var pr_description = " from ".concat(pr.author_login,": ", pr.title) | ||
|
||
var pr_link_address = pr.url | ||
var pr_link = $("<a></a>").attr("href", pr_link_address) | ||
pr_link.append($("<span></span>").text(item_link_text)) | ||
list_item.append(pr_link) | ||
|
||
list_item.append($("<span></span>").text(pr_description)) | ||
|
||
pr_list_group.append(list_item) | ||
|
||
} | ||
|
||
write_comparison = function(comparison,tab_pane){ | ||
|
||
// if there were not merged prs in this comparison I don't show it | ||
if(comparison.merged_prs.length!=0){ | ||
|
||
var comp_tags = comparison.compared_tags+" " | ||
comp_tags = comp_tags.substring(comp_tags.indexOf(">")+2,comp_tags.length) | ||
|
||
var title_compared_tags = $("<h3></h3>").text(comp_tags) | ||
|
||
var comp_link_address = comparison.compared_tags.replace(" --> ","...") | ||
comp_link_address = "https://github.com/cms-sw/cmssw/compare/".concat(comp_link_address) | ||
var comp_link = $("<a></a>").attr("href", comp_link_address) | ||
comp_link.append($("<span></span>").text("See comparison on GitHub")) | ||
|
||
var see_on_github = $("<small></small>").append(comp_link) | ||
|
||
title_compared_tags.append(see_on_github) | ||
title_compared_tags.append($("<br>")) | ||
title_compared_tags.append($("<br>")) | ||
|
||
tab_pane.append(title_compared_tags) | ||
var pull_requests = comparison.merged_prs | ||
|
||
var pr_list_group = $('<ul class="list-group"></ul>') | ||
|
||
|
||
//write the info for each pull request | ||
for(var i =0; i < pull_requests.length; i++){ | ||
write_pr(pull_requests[i],pr_list_group) | ||
} | ||
|
||
tab_pane.append(pr_list_group) | ||
}else{ | ||
console.log("There were no merged prs between the following tags") | ||
console.log(comparison.compared_tags) | ||
} | ||
} | ||
|
||
f = function(data){ | ||
// create tab panel | ||
var tabs = $('<ul id="myTab" class="nav nav-tabs"></ul>') | ||
|
||
//create nav tabs | ||
for(var i = 0; i < data.length; i++) { | ||
|
||
var release_queue = data[i]; | ||
//add tab | ||
var tab_title = $('<li><a href="#'+release_queue.release_name+'" data-toggle="tab">'+release_queue.release_name+'</a></li>') | ||
tabs.append(tab_title) | ||
|
||
|
||
} | ||
$("#results").append(tabs) | ||
|
||
// create tab panes | ||
var tabs_content = $('<div class="tab-content"></div>') | ||
tabs_content.attr("id","tabs_container") | ||
|
||
for(var i = 0; i < data.length; i++) { | ||
|
||
var release_queue = data[i]; | ||
//the first one is active | ||
if (i==0){ | ||
var tab_pane = $('<div class="tab-pane active" id="'+release_queue.release_name+'"></div>') | ||
}else{ | ||
var tab_pane = $('<div class="tab-pane" id="'+release_queue.release_name+'"></div>') | ||
} | ||
|
||
console.log(release_queue.release_name); | ||
console.log("---") | ||
// write the titles for the release queue | ||
var title_rel_name=$("<h1></h1>").text(release_queue.release_name) | ||
tab_pane.append(title_rel_name) | ||
tab_pane.append($("<hr>")) | ||
tab_pane.append($("<br>")) | ||
var comparisons = release_queue.comparisons | ||
//console.log(comparisons) | ||
|
||
// write the comparisons for the release queue | ||
for(var j =0; j < comparisons.length; j++){ | ||
write_comparison(comparisons[j],tab_pane) | ||
} | ||
|
||
tabs_content.append(tab_pane) | ||
|
||
} | ||
|
||
$("#results").append(tabs_content) | ||
|
||
//Enable tabbable tabs | ||
$('#myTab a').click(function (e) { | ||
e.preventDefault() | ||
console.log(this) | ||
$(this).tab('show') | ||
}) | ||
|
||
|
||
} | ||
|
||
|
||
$.getJSON( "merged_prs_summary.json", f) | ||
|
||
}) | ||
|
||
</script> | ||
</body> | ||
</html> |