Skip to content

Instantly share code, notes, and snippets.

@AlbinoDrought
Last active July 16, 2019 22:55
Show Gist options
  • Save AlbinoDrought/fd2631a631fc4be705a0ab8e3c0456be to your computer and use it in GitHub Desktop.
Save AlbinoDrought/fd2631a631fc4be705a0ab8e3c0456be to your computer and use it in GitHub Desktop.
Automatically rip commit details from bitbucket.org and pass them to a gotty script
// ==UserScript==
// @name Run creamy-cream build from bitbucket
// @version 1
// @grant none
// @match *://bitbucket.org/*/*/commits/*
// @match *://bitbucket.org/*/*/pull-requests/*
// @match *://bitbucket.org/*/*/branch/*
// ==/UserScript==
var element = document.createElement('button');
element.type = 'button';
element.innerText = 'Build with creamy-cream';
element.style.position = 'absolute';
element.style.top = 0;
element.style.right = 0;
element.style.zIndex = 6969;
document.body.appendChild(element);
element.onclick = function () {
var repoName = window.location.origin + window.location.pathname.split('/').slice(0, 3).join('/') + '.git';
var branch = '';
var commit = '';
if (window.location.pathname.match(/\/commits\//)) {
branch = document.querySelector('.commit-branches a').innerText;
commit = document.querySelector('.commit-description .changeset-hash').innerText;
} else if (window.location.pathname.match(/\/pull-requests\//)) {
branch = document.querySelector('[data-qa="pr-branches-and-state-styles"] span').innerText;
commit = document.querySelector('[data-qa="commit-hash-wrapper-0"] span').innerText;
} else if (window.location.pathname.match(/\/branch\//)) {
branch = document.querySelector('.app-header--heading').innerText;
commit = document.querySelector('a.hash').innerText;
}
window.open('http://172.16.30.108:6969/?arg=' + encodeURIComponent(repoName) + '&arg=' + encodeURIComponent(branch) + '&arg=' + encodeURIComponent(commit));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment