Last active
March 31, 2017 15:00
-
-
Save jromero/951f803d49a85f1f814fd00a403a918d to your computer and use it in GitHub Desktop.
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
// ==UserScript== | |
// @name BetterStashPullRequestList | |
// @namespace https://gist.github.com/ | |
// @version 0.1 | |
// @description Add filtering and row highlighting | |
// @author You | |
// @match http://YOUR_STASH/projects/PROJECT/repos/REPO/pull-requests | |
// @grant none | |
// ==/UserScript== | |
let username = "javier.romero"; | |
let requiredApprovals = 2; | |
(function() { | |
'use strict'; | |
// add filter buttons | |
AJS.$('.page-panel-content-header').css('float', 'left'); | |
let filters = AJS.$('<div class="aui-buttons"></div>'); | |
let filtersSection = AJS.$('<div style="float: right"><span>Filters: </span></div>'); | |
filtersSection.append(filters); | |
let onlyMineBtn = AJS.$('<button class="aui-button">Only Mine</button>'); | |
onlyMineBtn.on('click', function() { toggleOnlyMine(onlyMineBtn); }); | |
filters.append(onlyMineBtn); | |
let toReviewBtn = AJS.$('<button class="aui-button">To Review</button>'); | |
toReviewBtn.on('click', function() { toggleToReview(toReviewBtn); }); | |
filters.append(toReviewBtn); | |
AJS.$('.aui-page-panel-content').prepend(filtersSection); | |
// auto actions | |
highlightMineApproved(); | |
})(); | |
function toggleOnlyMine(toggleBtn) { | |
let mine = AJS.$('#pull-requests-table tbody tr td.author span.aui-avatar[data-username="' + username + '"]').parents('tr.pull-request-row'); | |
if (toggleBtn.attr("aria-pressed") === "true") { | |
toggleBtn.attr("aria-pressed", "false"); | |
AJS.$('tr.pull-request-row').not(mine).show(); | |
} else { | |
toggleBtn.attr("aria-pressed", "true"); | |
AJS.$('tr.pull-request-row').not(mine).hide(); | |
} | |
} | |
function toggleToReview(toggleBtn) { | |
let toReview = AJS.$('#pull-requests-table tbody tr td.reviewers span.aui-avatar.badge-hidden[data-username="javier.romero"]').parents('tr.pull-request-row'); | |
if (toggleBtn.attr("aria-pressed") === "true") { | |
toggleBtn.attr("aria-pressed", "false"); | |
AJS.$('tr.pull-request-row').not(toReview).show(); | |
} else { | |
toggleBtn.attr("aria-pressed", "true"); | |
AJS.$('tr.pull-request-row').not(toReview).hide(); | |
} | |
} | |
function highlightMineApproved() { | |
AJS.$('#pull-requests-table tbody tr td.author span.aui-avatar[data-username="' + username + '"]').parents('tr.pull-request-row').each(function() { | |
let tr = this; | |
if (AJS.$(this).find('td.reviewers > span.aui-avatar:not(.badge-hidden)').length >= requiredApprovals) { | |
AJS.$(tr).css("background", "#ddffdd"); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment