From 93a69d9d6272712c1eceb7c524d3b3147c13118d Mon Sep 17 00:00:00 2001 From: Sundus Yousuf Date: Thu, 26 Apr 2018 08:44:38 -0500 Subject: [PATCH] Update to stash lists. * Adding a new function to show PRs with conflicts on the PR list page. * Removing outdated functinality. --- js/app/content.js | 83 ++++++++++++++++++++++++++++------------------- manifest.json | 4 +-- 2 files changed, 51 insertions(+), 36 deletions(-) diff --git a/js/app/content.js b/js/app/content.js index 4c94f53..485cd99 100644 --- a/js/app/content.js +++ b/js/app/content.js @@ -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(" In Review "); - 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); + }); }); } @@ -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('Possible Merge Conflict'). + 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); @@ -106,5 +120,6 @@ jQuery(document).ready(function() { else if(e.keyCode === 27 /* Esc key */){ cleanDiff(); } return true; }, false); + addPullRequestTools(); }); diff --git a/manifest.json b/manifest.json index c4bbdb6..1561749 100644 --- a/manifest.json +++ b/manifest.json @@ -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",