Skip to content

Commit

Permalink
Add Integration with Pivotal Tracker
Browse files Browse the repository at this point in the history
* Add Labels from pivotal tracker to the pull requests page.
* Add state from pivotal tracker to the pull request page with link.
  • Loading branch information
sundus-y committed May 17, 2018
1 parent 93a69d9 commit 743afc0
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
.DS_Store
Archive.zip
12 changes: 12 additions & 0 deletions css/content.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,15 @@ span.in_review{
background-color: rgba(25, 26, 36, 0.75);
z-index: 101 !important;
}

.merge_conflict_header {
width: 1%;
}

.pivotal_tracker_labels_header {
width: 10%
}

.pivotal_tracker_state_header {
width: 6%
}
109 changes: 99 additions & 10 deletions js/app/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,59 @@ function addDiffTool(){
function addPullRequestTools(){
var pull_requests_page = jQuery("h2:contains('Pull requests')");
if (pull_requests_page.size() == 1) {
markMergeConflicts();
hideBuildStausValue();
addColumnToPullRequestTable('pull-request-merge-conflict-status-column merge_conflict_header','pull-request-merge-conflict-status-value','Merge Conflict',-1);
addColumnToPullRequestTable('pull-request-pivotal-tracker-labels-column pivotal_tracker_labels_header','pull-request-pivotal-tracker-labels-value','PivotalTracker Labels',1);
addColumnToPullRequestTable('pull-request-pivotal-tracker-state-column pivotal_tracker_state_header','pull-request-pivotal-tracker-state-value','PivotalTracker State',2);
var pull_requests = getPullRequests();
pull_requests.forEach(function(pull_request){
markMergeConflicts(pull_request);
if(pull_request.story_number){
addPivotalTrackerColumnValues(pull_request);
}
});
}
}

function getProjectPath(){
return window.location.pathname.match(/\/projects\/(.*)\/pull-requests/)[1];
}

function markMergeConflicts() {
var pull_requests = getPullRequests();
pull_requests.forEach(function(pull_request){
hasMergeConflict(pull_request).done(function(){
applyConflictStyle(pull_request);
function markMergeConflicts(pull_request) {
hasMergeConflict(pull_request).done(function(){
applyConflictStyle(pull_request);
});
}

function addPivotalTrackerColumnValues(pull_request){
getPivotalTrackerData(pull_request).done(function(data){
data.labels.forEach(function(label){
addLabel(pull_request,label.name);
});
addStateWithLink(pull_request,data);
});
}

function addColumnToPullRequestTable(thClass,tdClass,thLabel,insertAfterIndex){
var pr_table = jQuery('table.pull-requests-table');
if(insertAfterIndex === -1){
insertAfterIndex = pr_table.find('thead th').length;
}
var afterElem = pr_table.find('thead tr th:nth-child('+insertAfterIndex+')');
jQuery('<th class="'+thClass+'">'+thLabel+'</th>').insertAfter(afterElem);
pr_table.find('tbody tr').each(function(){
afterElem = jQuery(this).find('td:nth-child('+insertAfterIndex+')');
jQuery('<td class="'+tdClass+'"></td>').insertAfter(afterElem);
});
}

function hideBuildStausValue(){
var build_status_col = jQuery('table.pull-request-table th.build-status-pr-list-col');
if(!build_status_col.is(':visible')){
jQuery('td.build-status-pr-list-col-value').hide();
}
}

function clean(){
var diff = jQuery("span.diff");
var in_review= jQuery("span.in_review");
Expand Down Expand Up @@ -76,11 +112,17 @@ function getPullRequests(){
var prs = jQuery('table.pull-requests-table').find('td.title');
return prs.map(function(i,pr){
var id = jQuery(pr).find('a')[0].href.match(/pull-requests\/(.*)\//)[1];
var story_number = jQuery(pr).find('a').text().match(/^(\d*).*/);
if(story_number){
story_number = story_number[1];
}
return {
id: id,
name: 'Test',
merge_url: '/rest/api/latest/projects/'+getProjectPath()+'/pull-requests/'+id+'/merge',
elem: pr
elem: pr,
story_number: story_number,
pivotal_trakcer_url: 'https://www.pivotaltracker.com/services/v5/stories/' + story_number
}
}).toArray();
}
Expand All @@ -99,13 +141,60 @@ function hasMergeConflict(pull_request){
return hasConflict;
}

function getPivotalTrackerData(pull_request){
var trackerDataReady = jQuery.Deferred();
jQuery.get(pull_request.pivotal_trakcer_url).done(function(data){
trackerDataReady.resolve(data);
}).fail(function(data){
trackerDataReady.reject();
});
return trackerDataReady;
}

function applyConflictStyle(pull_request){
jQuery(pull_request.elem).
closest('tr').
find('.build-status-pr-list-col-value').
append('<span title="Possible Merge Conflict" class="aui-icon aui-icon-small aui-iconfont-warning">Possible Merge Conflict</span>').
css('background-color','#f6c342');
find('.pull-request-merge-conflict-status-value').
append('<span style="background-color: #f6c342;display: inline-grid;padding: 9px;border-radius: 9px;margin-left: 13px;">' +
'<span title="Possible Merge Conflict" class="aui-icon aui-icon-small aui-iconfont-warning">' +
'Possible Merge Conflict' +
'</span>' +
'</span>');

}

function addLabel(pull_request,label){
jQuery(pull_request.elem).
closest('tr').
find('.pull-request-pivotal-tracker-labels-value').
append('<span class="aui-lozenge aui-lozenge-moved">'+label+'</span> ');

}

function addStateWithLink(pull_request,data){
var state_css = '';
switch (data.current_state) {
case 'accepted':
state_css = 'success';
break;
case 'rejected':
state_css = 'error';
break;
case 'delivered':
state_css = 'moved';
break;
case 'finished':
state_css = 'current';
break;
case 'started':
state_css = 'complete';
break;
}
jQuery(pull_request.elem).
closest('tr').
find('.pull-request-pivotal-tracker-state-value').
append('<span class="aui-lozenge aui-lozenge-'+state_css+'">'+data.current_state+'</span> '+
'<a target="_blank" href="'+data.url+'"><span class="aui-icon aui-icon-small aui-iconfont-share">Open PivotalTracker</span></a>');
}

jQuery(document).ready(function() {
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Stash++",
"version": "2.2.0",
"version": "2.3.0",
"manifest_version": 2,
"description": "A Chrome extension to make stash better",
"page_action": {
Expand Down

0 comments on commit 743afc0

Please sign in to comment.