Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save herejia/daeef8be19f36d34f154f964bc580d0f to your computer and use it in GitHub Desktop.
Save herejia/daeef8be19f36d34f154f964bc580d0f to your computer and use it in GitHub Desktop.
// ==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)
})
@herejia
Copy link
Author

herejia commented Jul 20, 2018

Something that looks like that
capture d ecran de 2018-07-20 09-51-25

Will prompt you with a markdown image to copy from and paste it wherever you want

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment