GitHub Actions Filter Button

Filter Kata Containers passed or non-required checks.

Verze ze dne 20. 02. 2024. Zobrazit nejnovější verzi.

  1. // ==UserScript==
  2. // @name GitHub Actions Filter Button
  3. // @namespace http://www.nxw.name
  4. // @version 1.0.1
  5. // @description Filter Kata Containers passed or non-required checks.
  6. // @author Xuewei Niu
  7. // @match https://github.com/kata-containers/kata-containers/pull/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=github.com
  9. // @grant none
  10. // @license Apache-2.0
  11. // ==/UserScript==
  12.  
  13. var hidden = false;
  14. var loaded = false;
  15.  
  16. function onFilterButtonClicked() {
  17. hidden = !hidden;
  18. var checks = document.querySelectorAll('div.merge-status-list.hide-closed-list.js-updatable-content-preserve-scroll-position > div');
  19. checks.forEach(function(check) {
  20. console.debug('check item', check);
  21. if (hidden) {
  22. var statusElement = check.querySelector('div:nth-child(3)');
  23. if (!statusElement) {
  24. console.debug(statusElement, 'check status not found');
  25. return;
  26. }
  27. var detailsElement = check.querySelector('div:nth-child(4)');
  28. if (!detailsElement) {
  29. console.debug(detailsElement, 'check details not found');
  30. return;
  31. }
  32.  
  33. var statusText = statusElement.textContent;
  34. var requiredText = detailsElement.textContent;
  35. // 'Successful in' for GHA, 'Build finished' for Jenkins
  36. var successful = statusText.includes('Successful in') || statusText.includes('Build finished');
  37. var required = requiredText.includes('Required');
  38.  
  39. if (successful || !required) {
  40. console.debug('check item is hidden: successful: ' + successful + ', required: ' + required)
  41. check.classList.add('hidden-check');
  42. }
  43. } else {
  44. check.classList.remove('hidden-check');
  45. }
  46. });
  47. }
  48.  
  49. function insertFilterButton() {
  50. var checkSummary = document.querySelector('div.branch-action-item.js-details-container.Details.open div:nth-child(2)');
  51. if (!checkSummary) {
  52. console.log('Failed to find check summary div');
  53. return;
  54. }
  55.  
  56. loaded = true;
  57.  
  58. var filterButton = document.createElement('button');
  59. filterButton.type = 'button';
  60. filterButton.textContent = 'Filter Passed or Non-required Checks';
  61. filterButton.addEventListener('click', onFilterButtonClicked);
  62.  
  63. checkSummary.insertBefore(filterButton, filterButton.nextSibling);
  64. }
  65.  
  66. function insertHiddenCheckCssStyle() {
  67. var styleElement = document.createElement('style');
  68. styleElement.type = 'text/css';
  69. var cssRule = document.createTextNode('.hidden-check { display: none !important }');
  70. styleElement.appendChild(cssRule);
  71. document.head.appendChild(styleElement);
  72. }
  73.  
  74. function loopWithDelay() {
  75. var count = 0;
  76.  
  77. function iterate() {
  78. if (loaded) {
  79. return;
  80. }
  81. // retry 60 times (1 min)
  82. if (count == 60) {
  83. return;
  84. }
  85. console.log("GHA Actions Filter Button Iteration: " + count);
  86. count++;
  87. insertFilterButton();
  88. setTimeout(iterate, 1000);
  89. }
  90.  
  91. iterate();
  92. }
  93.  
  94. (function() {
  95. 'use strict';
  96.  
  97. insertHiddenCheckCssStyle();
  98.  
  99. loopWithDelay();
  100. })();