// ==UserScript==
// @name TFS Changeset History Helper
// @namespace http://jonas.ninja
// @version 1.3.0
// @description Changeset reference utilities
// @author @_jnblog
// @match http://*/tfs/DefaultCollection/*/_versionControl*
// @grant GM_addStyle
// @downloadURL none
// ==/UserScript==
/* jshint -W097 */
/* global GM_addStyle */
/* jshint asi: true, multistr: true */
var $ = unsafeWindow.jQuery;
waitForKeyElements('.history-result', doEverything, false)
waitForKeyElements(".vc-page-title[title^=Changeset]", addChangesetIdCopyUtilities, true)
$(document).on('mouseenter', '.history-result', highlightHistoryResult)
.on('mouseleave', '.history-result', unhighlightHistoryResult)
$(document).on('click', 'input.ijg-copy-changeset-id', clickToCopyId)
$(document).on('click', 'input.ijg-copy-changeset-page-link', clickToCopyPage)
function clickToCopyId(e) {
var historyResult = $(this).closest('.history-result')
var mergedChangesetRegex = / \(merge c\d{5,} to QA\)/gi
if (e.ctrlKey) {
// if CTRL is held down, copy first the task ID, then a commit message. Only useful if you have a clipboard manager like Ditto.
var taskId = historyResult.data('ijgTaskId')
var that = this
copy(this, $(this).next('span.ijg-copy-message'), taskId)
var optMessage = historyResult.find('.change-link').text()
if (optMessage.match(mergedChangesetRegex)) {
// a changeset that's already merged to QA should merge to Release
optMessage = optMessage.replace(mergedChangesetRegex, ' (merge c' + that.value + ' to Release)')
} else {
optMessage = optMessage.replace(/(^t\d{5,})/, '(merge c' + that.value + ' to QA)')
// optMessage += ' (merge c' + that.value + ' to QA)'
}
window.setTimeout(function() {
copy(that, $(that).next('span.ijg-copy-message'), optMessage)
}, 250)
} else {
copy(this, $(this).next('span.ijg-copy-message'))
}
}
function clickToCopyPage(e) {
// if CTRL is held down, copy a commit message
var optMessage
if (e.ctrlKey) {
optMessage = '(merge c' + this.value + ' to QA) ' + $('.vc-change-summary-comment').text()
}
copy(this, $(this).next('span.ijg-copy-message'), optMessage)
}
function doEverything(historyResult) {
historyResult = $(historyResult)
spanifyText(historyResult)
addCopyUtilities(historyResult)
createTaskContainers(historyResult)
//fetchTaskLinks(historyResult)
}
function createTaskContainers(historyResult) {
// makes a positioned div in the right place to hold Task info
var tasks = historyResult.find('.ijg-task-id')
if (tasks.size()) {
// make a container and append rows
var container = $('
')
historyResult.find('.change-link-container').append(container)
tasks.each(function() {
var tasknum = $(this).data('ijgTaskId')
var task = $('