Created
December 23, 2016 00:49
-
-
Save dvdbng/17d59eef6e7b2cc3f989fb51fc75fa47 to your computer and use it in GitHub Desktop.
Github user script: Show a open PR link when an issue has label "3 - code review"
This file contains hidden or 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 Open PR Link | |
// @namespace ghprlink | |
// @description Show a open PR link when an issue has label "3 - code review" | |
// @include https://github.com/* | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
function addOpenPRLinks(){ | |
if(/open_first_pr=1/.test(location.search)) { | |
let pr = document.querySelector('div[id^=ref-pullrequest] ~ h4 a'); | |
if(pr){ | |
location.href = pr.href; | |
} else { | |
alert('PR not found'); | |
} | |
} | |
let labels = document.querySelectorAll('.labels a[title="Label: 3 - code review"]'); | |
Array.from(labels).forEach(label => { | |
let issueLink = label.parentNode.previousElementSibling; | |
if(issueLink && issueLink.tagName == 'A') { | |
let prLink = document.createElement('a'); | |
prLink.setAttribute('href', issueLink.getAttribute('href') + '?open_first_pr=1'); | |
prLink.className = issueLink.className.replace(/\bh4\b/, 'h5'); | |
prLink.appendChild(document.createTextNode('[open pr]')); | |
issueLink.parentNode.insertBefore(prLink, label.parentNode) | |
} | |
}); | |
} | |
addOpenPRLinks() | |
document.addEventListener('pjax:end', addOpenPRLinks); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment