GitHub Actions Filter Button

Filter Kata Containers passed or non-required checks.

Fra og med 20.02.2024. Se den nyeste version.

  1. // ==UserScript==
  2. // @name GitHub Actions Filter Button
  3. // @namespace http://www.nxw.name
  4. // @version 1.0.2
  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.  
  15. function onFilterButtonClicked() {
  16. var checks = document.querySelectorAll('div.merge-status-list.hide-closed-list.js-updatable-content-preserve-scroll-position > div');
  17. if (checks.length == 0) {
  18. console.log('stop hiding checks: they aren\'t ready')
  19. return;
  20. }
  21.  
  22. hidden = !hidden;
  23. checks.forEach(function(check) {
  24. console.debug('check item', check);
  25. if (hidden) {
  26. var statusElement = check.querySelector('div:nth-child(3)');
  27. if (!statusElement) {
  28. console.debug(statusElement, 'check status not found');
  29. return;
  30. }
  31. var detailsElement = check.querySelector('div:nth-child(4)');
  32. if (!detailsElement) {
  33. console.debug(detailsElement, 'check details not found');
  34. return;
  35. }
  36.  
  37. var statusText = statusElement.textContent;
  38. var requiredText = detailsElement.textContent;
  39. // 'Successful in' for GHA, 'Build finished' for Jenkins
  40. var successful = statusText.includes('Successful in') || statusText.includes('Build finished');
  41. var required = requiredText.includes('Required');
  42.  
  43. if (successful || !required) {
  44. console.debug('check item is hidden: successful: ' + successful + ', required: ' + required)
  45. check.classList.add('hidden-check');
  46. }
  47. } else {
  48. check.classList.remove('hidden-check');
  49. }
  50. });
  51. }
  52.  
  53. function insertFilterButton() {
  54. var body = document.querySelector('body');
  55. var bodyFirstChild = document.querySelector('body div:nth-child(1)');
  56.  
  57. var filterButton = document.createElement('button');
  58. filterButton.type = 'button';
  59. filterButton.textContent = 'Filter Checks';
  60. filterButton.classList.add('gha-filter-button');
  61. filterButton.addEventListener('click', onFilterButtonClicked);
  62.  
  63. body.insertBefore(filterButton, bodyFirstChild);
  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 }\n.gha-filter-button { position: fixed; bottom: 100px; right: 20px; display: block; z-index: 10000; background-color: #218bff; color: #fff; padding: 5px 16px; border: none; border-radius: 6px;}');
  70. styleElement.appendChild(cssRule);
  71. document.head.appendChild(styleElement);
  72. }
  73.  
  74. (function() {
  75. 'use strict';
  76.  
  77. insertHiddenCheckCssStyle();
  78. insertFilterButton();
  79. })();