Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var moodle_add_ci_badges = function($) {
- // Silly protection for development purposes.
- var loggedinuser = $('meta[name=ajs-remote-user]').attr("content");
- var enabled = ['stronk7', 'dobedobedoh', 'jaked', 'jpataleta', 'abgreeve', 'sarjona'];
- 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('src', 'https://ci.moodle.org/buildStatus/icon?job=' + parts[1] + '&build=' + parts[2]);
- badge.appendChild(image);
- anchor.before(badge);
- });
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement