Advertisement
stronk7

Untitled

Sep 12th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. var moodle_add_ci_badges = function($) {
  2. // Silly protection for development purposes.
  3. var loggedinuser = $('meta[name=ajs-remote-user]').attr("content");
  4. var enabled = ['stronk7', 'dobedobedoh', 'jaked', 'jpataleta', 'abgreeve', 'sarjona'];
  5. if (!enabled.includes(loggedinuser)) {
  6. return;
  7. }
  8.  
  9. // Look for all the anchors to https://ci.moodle.org/view/Testing/job/DEV.*/d+.*
  10. var anchors = document.querySelectorAll('a[href^="https://ci.moodle.org/view/Testing/job/DEV"]');
  11.  
  12. // Filter out all the anchors having children (they may be already images or whatever).
  13. anchors = Array.from(anchors).filter( function(anchor) {
  14. return (anchor.children.length === 0);
  15. });
  16.  
  17. // Iterate over the anchors, building the badge element and prepending it to the anchors.
  18. anchors.forEach(function(anchor, index) {
  19. // Extract important parts (job name and build number) from the anchor (needed to build the badge src).
  20. var parts = anchor.href.match(/https:\/\/ci.moodle.org\/view\/Testing\/job\/(DEV[^\/]+)\/(\d+).*/);
  21. if (parts.length !== 3) {
  22. return;
  23. }
  24.  
  25. // Create the linked badge, pointing to the same URL and using the Embeddable Build Status images.
  26. var badge = anchor.cloneNode();
  27.  
  28. var image = document.createElement('img');
  29. image.setAttribute('src', 'https://ci.moodle.org/buildStatus/icon?job=' + parts[1] + '&build=' + parts[2]);
  30.  
  31. badge.appendChild(image);
  32. anchor.before(badge);
  33. });
  34. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement