Last active
November 2, 2018 09:02
-
-
Save ideadapt/5f5580a9034c9464c7b1d74299111f30 to your computer and use it in GitHub Desktop.
Bamboo Script File Repo Link - Tampermonkey
This file contains 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 Bamboo Script File Repo Link | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description add link to script file in stash repository | |
// @author [email protected] | |
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.18.2/babel.js | |
// @require https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.16.0/polyfill.js | |
// @include *://*/*/*editBuildTasks.action* | |
// @include *://*/*/*configureEnvironmentTasks.action* | |
// @run-at document-idle | |
// ==/UserScript== | |
/* jshint ignore:start */ | |
var inline_src = (<><![CDATA[ | |
/* jshint ignore:end */ | |
/* jshint esnext: false */ | |
/* jshint esversion: 6 */ | |
// adjust to your needs/setup | |
const stashRestRoot = "https://HOST/stash/rest/api/1.0/"; | |
const filesApi = "projects/IB/repos/bamboo-scripts/files?limit=100"; | |
const repos = [{ | |
url: "https://HOST/stash/projects/IB/repos/bamboo-scripts", | |
name: "Bamboo Scripts" | |
}]; | |
// end of config | |
new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
if(mutation.addedNodes.length > 0){ | |
// resize inline text editor | |
let ace = document.querySelector(".bambooAceResizableContainer"); | |
if(ace){ | |
ace.style.width = "1200px"; | |
ace.style.height= "800px"; | |
} | |
// script link | |
let ctrl = document.querySelector("#panel-editor-config #scriptLocation"); | |
if(ctrl && ctrl.value === 'FILE'){ | |
const scriptFilenameCtrl = document.querySelector("#script"); | |
const path = scriptFilenameCtrl.value; | |
const scriptFilename = path.split('/').pop(); | |
for(let repo of repos){ | |
fetch(stashRestRoot + filesApi, {credentials: "same-origin", method: "GET"}) | |
.then(res => { return res.ok ? res.json() : Promise.reject(res); }) | |
.then(json => { | |
const repoFilepath = json.values.filter(path => path.endsWith(scriptFilename)).pop(); | |
if(repoFilepath){ | |
let href = `${repo.url}/browse/${repoFilepath}`; // ` | |
let link = document.createElement("a"); | |
link.href = href; | |
link.innerText = repo.name; | |
scriptFilenameCtrl.parentElement.appendChild(link); | |
} | |
}); | |
} | |
} | |
} | |
}); | |
}) | |
.observe(document.querySelector("#panel-editor-config"), { attributes: false, childList: true, characterData: false }); | |
/* jshint ignore:start */ | |
]]></>).toString(); | |
var c = Babel.transform(inline_src, { presets: [ "es2015", "es2016" ] }); | |
eval(c.code); | |
/* jshint ignore:end */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment