Skip to content

Commit

Permalink
Update to stash lists.
Browse files Browse the repository at this point in the history
* Adding a new function to show PRs with conflicts on the PR list page.
* Removing outdated functinality.
  • Loading branch information
sundus-y committed Apr 26, 2018
1 parent 31157ac commit 93a69d9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 36 deletions.
83 changes: 49 additions & 34 deletions js/app/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,23 @@ function addDiffTool(){
});
}

function addPullRequestTool(){
function addPullRequestTools(){
var pull_requests_page = jQuery("h2:contains('Pull requests')");
var pull_request_page = jQuery("div.pull-request-content>h3:contains('Activity')");
if (pull_requests_page.size() == 1) {highlight();}
if (pull_request_page.size() == 1) {showInReviewButton();}
if (pull_requests_page.size() == 1) {
markMergeConflicts();
}
}

function highlight() {
var pull_requests = jQuery('table.pull-requests-table').find('td.id');
var project_path = window.location.pathname.match(/\/projects\/(.*)\/pull-requests/)[1];
jQuery.each(pull_requests, function (i, pull_request) {
var pull_request_num = jQuery(pull_request).find('a')[0].innerHTML.match(/#(.*)/)[1];
var activity_url = "https://git.its.uiowa.edu/rest/api/latest/projects/" + project_path +
"/pull-requests/" + pull_request_num + "/activities?start=0&limit=100";
$.ajax({
context: pull_request,
url: activity_url
}).done(function (data) {
var in_review = false;
jQuery.each(data.values.reverse(), function(i,activity){
if (activity.action == "COMMENTED" && (activity.comment.text == "IN REVIEW" || activity.comment.text == "IN_REVIEW")) {
in_review = true;
return;
}
});
if (in_review){
jQuery(this).closest('tr').css('background-color','rgba(230, 255, 98, 0.87)')
}
});
});
function getProjectPath(){
return window.location.pathname.match(/\/projects\/(.*)\/pull-requests/)[1];
}

function showInReviewButton(){
var details_title = jQuery("div.pull-request-content>div>div>h3:contains('Details')");
jQuery(details_title).append(" <span class='in_review'> In Review </span>");
jQuery('span.in_review').click(function(){
jQuery('form.new-comment-form').find('textarea').val('IN REVIEW');
jQuery('form.new-comment-form').find("button:contains('Comment')").click();
function markMergeConflicts() {
var pull_requests = getPullRequests();
pull_requests.forEach(function(pull_request){
hasMergeConflict(pull_request).done(function(){
applyConflictStyle(pull_request);
});
});
}

Expand Down Expand Up @@ -93,11 +72,46 @@ function renderDiff(diff_page){
});
}

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];
return {
id: id,
name: 'Test',
merge_url: '/rest/api/latest/projects/'+getProjectPath()+'/pull-requests/'+id+'/merge',
elem: pr
}
}).toArray();
}

function hasMergeConflict(pull_request){
var hasConflict = jQuery.Deferred();
jQuery.get(pull_request.merge_url).done(function (data) {
if(data.conflicted){
hasConflict.resolve();
} else {
hasConflict.reject();
}
}).fail(function(data){
hasConflict.reject();
});
return hasConflict;
}

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');

}

jQuery(document).ready(function() {
document.body.addEventListener('keydown', function(e){
if(e.keyCode === 18 /* Alt (option) key */){
addDiffTool();
addPullRequestTool();
}
return true;
}, false);
Expand All @@ -106,5 +120,6 @@ jQuery(document).ready(function() {
else if(e.keyCode === 27 /* Esc key */){ cleanDiff(); }
return true;
}, false);
addPullRequestTools();
});

4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "Stash++",
"version": "2.1.0",
"version": "2.2.0",
"manifest_version": 2,
"description": "A Chrome extension to make stash better",
"page_action": {
"default_icon":"img/diff-icon.png",
"default_title":"Stash Pull Request Diff"
"default_title":"Stash Enhancements"
},
"content_scripts": [{
"js": ["js/lib/jquery-2.1.1.min.js",
Expand Down

0 comments on commit 93a69d9

Please sign in to comment.