Skip to content

Instantly share code, notes, and snippets.

@saulodias
Last active December 2, 2022 13:56
Show Gist options
  • Save saulodias/8aa61543cdca7a8101ef63c717a2aa42 to your computer and use it in GitHub Desktop.
Save saulodias/8aa61543cdca7a8101ef63c717a2aa42 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Azure Devops Git Helper
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Adds a button beside a work item number that copies a suggested branch name for the item to the clipboard.
// @author Saulo Dias
// @match https://dev.azure.com/*/_workitems/edit/*
// @match https://*.visualstudio.com/*/_workitems/edit/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=azure.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
const GIT_FOLDER = {
"Bug": "fixes",
"Fault": "fixes",
"User Story": "features",
}
setTimeout(()=> {
const workItemType = document.querySelector(".work-item-type-icon").getAttribute("aria-label");
const header = document.querySelector(".work-item-form-headerContent");
const workItemControl = header.querySelector(".workitemcontrol");
const workItemNumber = header.innerText;
const title = header.querySelector("input").value;
const gitFolder = GIT_FOLDER[workItemType];
const formattedTitle = title.toLowerCase().replaceAll(" ", "_");
const branchName = `${gitFolder}/${workItemNumber}-${formattedTitle}`;
const button = document.createElement('span');
button.classList.add("bowtie-icon", "bowtie-tfvc-branch");
button.setAttribute("title", "Copy suggested branch name.");
button.setAttribute("style", "padding: .4rem; margin-left: .5rem; cursor: pointer");
button.addEventListener("click", () => {
navigator.clipboard.writeText(branchName);
});
workItemControl.appendChild(button);
}, 3000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment