Created
July 20, 2018 07:51
-
-
Save herejia/daeef8be19f36d34f154f964bc580d0f to your computer and use it in GitHub Desktop.
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 Copies build status image from build run | |
// @version 1 | |
// @grant none | |
// @include BITBUCKET_URL/projects/PROJECT_CODE/repos/*/pull-requests/*/overview | |
// ==/UserScript== | |
const JENKINS_JOB_URL = 'https://jenkins.foo.bar' | |
const re = /.+\/(.+)\/pull-requests\/(\d+)\/overview/ | |
window.addEventListener('DOMContentLoaded', () => { | |
const [ _, project, pr ] = location.pathname.match(re); | |
const imageSrc = `${JENKINS_JOB_URL}/${project}/view/change-requests/job/PR-${pr}/lastBuild/badge/icon`; | |
const markdownImage = `Last PR build status : | |
[![Build Status] | |
(${imageSrc})] | |
(${JENKINS_JOB_URL}/${project}/view/change-requests/job/PR-${pr}/lastBuild/) | |
`.replace(/(\r\n|\n|\r)/gm, ''); | |
const button = document.createElement('button'); | |
button.classList.add('aui-button') | |
button.title = 'Copy build image'; | |
button.style.background = `#f5f5f5 url("${imageSrc}") no-repeat center center`; | |
button.style.minWidth = '100px'; | |
button.innerHTML = ' ' | |
button.onclick = () => window.prompt('Hit Ctrl+C to copy build markdown image', markdownImage); | |
document.querySelector('.comment-form-footer .buttons').prepend(button) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Something that looks like that
Will prompt you with a markdown image to copy from and paste it wherever you want