GitHub Actions Filter Button

Filter GitHub Actions which is not passed and quired

Mint 2024.02.07.. Lásd a legutóbbi verzió

  1. // ==UserScript==
  2. // @name GitHub Actions Filter Button
  3. // @namespace http://www.nxw.name
  4. // @version 2024-02-07
  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') || statusElement.textContent.includes('Build finished');
  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. // retry 60 times (1 min)
  76. if (count == 60) {
  77. return;
  78. }
  79. console.log("Iteration: " + count);
  80. count++;
  81. insertFilter();
  82. setTimeout(iterate, 1000);
  83. }
  84.  
  85. iterate();
  86. }
  87.  
  88. (function() {
  89. 'use strict';
  90.  
  91. var stateElem = document.querySelector('#partial-discussion-header .State');
  92. if (stateElem) {
  93. if (stateElem.getAttribute('title') !== 'Status: Open') {
  94. console.log('GitHub Actions Filter Button: Exit due to the status of PR is not "open".');
  95. return;
  96. }
  97. } else {
  98. console.log('GitHub Actions Filter Button: Can\'t determine PR\'s status.');
  99. return;
  100. }
  101.  
  102. insertHiddenCheckCssStyle();
  103.  
  104. loopWithDelay();
  105. })();