Skip to content

Instantly share code, notes, and snippets.

@dalpert-korewireless
Last active January 4, 2016 22:40
Show Gist options
  • Select an option

  • Save dalpert-korewireless/665030ba20d5dc0bd9e0 to your computer and use it in GitHub Desktop.

Select an option

Save dalpert-korewireless/665030ba20d5dc0bd9e0 to your computer and use it in GitHub Desktop.
Tampermonkey script
// ==UserScript==
// @name TeamCityHelpers Helpers
// @namespace http://blog.spinthemoose.com/
// @version 0.2
// @description Adds some useful capabilities to the Octopus Deploy UI.
// @author David Alpert
// @match http://172.17.1.95:8080/*
// @grant none
// ==/UserScript==
function TeamCityHelpers() {
if (window.jQuery == 'undefined' || window.jQuery('#content') == null) {
window.setTimeout(TeamCityHelpers, 100);
} else {
var $ = jQuery;
function getRepoName(repoLink) {
return (repoLink.length > 0)
? repoLink.first().text().replace('Github [','').replace(']','')
: '';
}
function buildPRUrl(repoName, prNumber) {
return 'https://github.com/RacoWireless/'+repoName+'/pull/'+prNumber;
}
var repoName = getRepoName($('#mainNavigation li.project[data-projectid*="_Github"] a'));
$('.branch a:contains(/merge),span.branchName:contains(/merge)').each(function(idx,el){
//debugger;
if (repoName == '') {
// didn't find repoName globally so let's look in a local header:
repoName = getRepoName($(el).closest('div.build.overview-page').find('div.projectHeader td.projectName a:contains(Github [)'));
}
if (repoName != '') {
var pr = $(el).text().replace('/merge','');
if (pr != '') {
var u = buildPRUrl(repoName,pr);
var linkHtml = '<a class="viewOnGithub" href="'+u+'" style="margin-right:5px;position:relative;top:3px;"><img src="/img/branch.png"/></a>';
var existingIcon = $(el).closest('.branch').prev('img[src="/img/branch.png"]');
if (existingIcon.length > 0) {
existingIcon.replaceWith(linkHtml);
}
else {
$(el).before(linkHtml);
}
}
}
});
if (repoName != '') {
$('div[data-blockid^="branch_"]').each(function(idx,el){
var pr = $(el).find('span.branch a:contains(/merge)').text().replace('/merge','');
if (pr != '') {
var u = buildPRUrl(repoName,pr);
$(el).find('img[src="/img/branch.png"]')
.replaceWith('<a href="'+u+'"><img src="/img/branch.png"/></a>');
}
});
}
}
}
TeamCityHelpers();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment