var moodle_add_ci_badges = function($) { // Silly protection for development purposes. var loggedinuser = document.querySelector('meta[name=ajs-remote-user]').getAttribute('content'); var enabled = ['stronk7', 'dobedobedoh', 'jaked', 'jpataleta', 'abgreeve', 'sarjona', 'tsala', 'sanderbangma', 'timhunt']; if (!enabled.includes(loggedinuser)) { return; } // Look for all the anchors to https://ci.moodle.org/view/Testing/job/DEV.*/d+.* var anchors = document.querySelectorAll('a[href^="https://ci.moodle.org/view/Testing/job/DEV"]'); // Filter out all the anchors having children (they may be already images or whatever). anchors = Array.from(anchors).filter( function(anchor) { return (anchor.children.length === 0); }); // Iterate over the anchors, building the badge element and prepending it to the anchors. anchors.forEach(function(anchor, index) { // Extract important parts (job name and build number) from the anchor (needed to build the badge src). var parts = anchor.href.match(/https:\/\/ci.moodle.org\/view\/Testing\/job\/(DEV[^\/]+)\/(\d+).*/); if (parts.length !== 3) { return; } // Create the linked badge, pointing to the same URL and using the Embeddable Build Status images. var badge = anchor.cloneNode(); var image = document.createElement('img'); image.setAttribute('style', 'vertical-align: middle; height: 1.3em; margin-right: 0.2em;'); image.setAttribute('src', 'https://ci.moodle.org/buildStatus/icon?job=' + parts[1] + '&build=' + parts[2] + '&subject=CI'); badge.appendChild(image); anchor.before(badge); }); }; AJS.toInit(function() { moodle_add_ci_badges(AJS.$); JIRA.bind(JIRA.Events.ISSUE_REFRESHED, function() { moodle_add_ci_badges(AJS.$); }); JIRA.bind(JIRA.Events.NEW_PAGE_ADDED, function() { moodle_add_ci_badges(AJS.$); }); });