Skip to content

Instantly share code, notes, and snippets.

@jphastings
Last active August 29, 2015 14:25
Show Gist options
  • Save jphastings/24aa76561413358ee668 to your computer and use it in GitHub Desktop.
Save jphastings/24aa76561413358ee668 to your computer and use it in GitHub Desktop.
Looks for Pivotal Tracker story ids anywhere on github.com. Any string that looks like: "#12345678" will have a link inserted to the corresponding pivotal tracker story. Don't worry, this will not interfere with github issues, until the ten millionth issue.
// --------------------------------------------------------------------
//
// ==UserScript==
// @name Let's Git Pivotal
// @namespace uk.co.deliveroo.labs
// @version 0.4
// @description Looks for Pivotal Tracker story ids anywhere on github.com. Any string that looks like: "#12345678" will have a link inserted to the corresponding pivotal tracker story. Don't worry, this will not interfere with github issues, until the ten millionth issue.
// @include https://github.com/*
// ==/UserScript==
"use strict";
var regex = /#[0-9]{8}/g;
function addPivotalTrackerLinks(element) {
var pivotalMatches = element.innerHTML.match(regex);
var innerHTML = element.innerHTML;
for (var i = 0 ; i < pivotalMatches.length; i++)
innerHTML = insertLink(innerHTML, pivotalMatches[i]);
element.innerHTML = innerHTML;
}
function insertLink (innerHTML, pivotalStory) {
var id = pivotalStory.slice(1);
var link = '<a class="issue-link" href="https://www.pivotaltracker.com/story/show/'+id+'" target="_blank">'+pivotalStory+'</a>';
return innerHTML.replace(pivotalStory, link);
}
addPivotalTrackerLinks(document.body);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment