GitHub Actions Filter Button

Filter GitHub Actions which is not passed and quired

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

  1. // ==UserScript==
  2. // @name GitHub Actions Filter Button
  3. // @namespace http://www.nxw.name
  4. // @version 2024-02-06
  5. // @description Filter GitHub Actions which is not passed and quired
  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 filterButtonOnClick() {
  17. hidden = !hidden;
  18. var checks = document.querySelectorAll('#partial-pull-merging div.merge-status-list.hide-closed-list.js-updatable-content-preserve-scroll-position > div');
  19. checks.forEach(function(check) {
  20. if (hidden) {
  21. var statusElement = check.querySelector('div:nth-child(3)');
  22. if (!statusElement) {
  23. // console.log(check, 'check status not found');
  24. return;
  25. }
  26. var detailsElement = check.querySelector('div:nth-child(4)');
  27. if (!detailsElement) {
  28. return;
  29. }
  30.  
  31. var successful = statusElement.textContent.includes('Successful in');
  32. var required = detailsElement.textContent.includes('Required');
  33.  
  34. if (successful || !required) {
  35. check.classList.add('hidden-check');
  36. }
  37. } else {
  38. check.classList.remove('hidden-check');
  39. }
  40. });
  41. }
  42.  
  43. function insertFilter() {
  44. var hideAllChecks = document.querySelector('#partial-pull-merging div.branch-action-item.js-details-container.Details.open button');
  45. if (!hideAllChecks) {
  46. console.log('Failed to find filter button container');
  47. return;
  48. }
  49.  
  50. loaded = true;
  51.  
  52. var filterButton = document.createElement('button');
  53. filterButton.type = 'button';
  54. filterButton.textContent = 'Filter Not Passed and Required Checks';
  55. filterButton.addEventListener('click', filterButtonOnClick);
  56.  
  57. hideAllChecks.parentNode.insertBefore(filterButton, filterButton.nextSibling);
  58. }
  59.  
  60. function insertHiddenCheckCssStyle() {
  61. var styleElement = document.createElement('style');
  62. styleElement.type = 'text/css';
  63. var cssRule = document.createTextNode('.hidden-check { display: none !important }');
  64. styleElement.appendChild(cssRule);
  65. document.head.appendChild(styleElement);
  66. }
  67.  
  68. function loopWithDelay() {
  69. var count = 0;
  70.  
  71. function iterate() {
  72. if (loaded) {
  73. return;
  74. }
  75. if (count == 10) {
  76. return;
  77. }
  78. console.log("Iteration: " + count);
  79. count++;
  80. insertFilter();
  81. setTimeout(iterate, 1000);
  82. }
  83.  
  84. iterate();
  85. }
  86.  
  87. (function() {
  88. 'use strict';
  89.  
  90. var stateElem = document.querySelector('#partial-discussion-header .State');
  91. if (stateElem) {
  92. if (stateElem.getAttribute('title') !== 'Status: Open') {
  93. console.log('GitHub Actions Filter Button: Exit due to the status of PR is not "open".');
  94. return;
  95. }
  96. } else {
  97. console.log('GitHub Actions Filter Button: Can\'t determine PR\'s status.');
  98. return;
  99. }
  100.  
  101. insertHiddenCheckCssStyle();
  102.  
  103. loopWithDelay();
  104. })();