Advertisement
stronk7

Untitled

Sep 12th, 2019
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. var moodle_add_ci_badges = function($) {
  2. // Silly protection for development purposes.
  3. var loggedinuser = document.querySelector('meta[name=ajs-remote-user]').getAttribute('content');
  4. var enabled = ['stronk7', 'dobedobedoh', 'jaked', 'jpataleta', 'abgreeve', 'sarjona', 'tsala', 'sanderbangma', 'timhunt'];
  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('style', 'vertical-align: middle; height: 1.3em; margin-right: 0.2em;');
  30. image.setAttribute('src', 'https://ci.moodle.org/buildStatus/icon?job=' +
  31. parts[1] + '&build=' + parts[2] + '&subject=CI');
  32.  
  33. badge.appendChild(image);
  34. anchor.before(badge);
  35. });
  36. };
  37.  
  38. AJS.toInit(function() {
  39. moodle_add_ci_badges(AJS.$);
  40. JIRA.bind(JIRA.Events.ISSUE_REFRESHED, function() {
  41. moodle_add_ci_badges(AJS.$);
  42. });
  43. JIRA.bind(JIRA.Events.NEW_PAGE_ADDED, function() {
  44. moodle_add_ci_badges(AJS.$);
  45. });
  46. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement