GitHub - Pull Request - Open external status links externally

Open external links in the "Checks" section in a new tab

Stan na 31-10-2024. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

  1. // ==UserScript==
  2. // @name GitHub - Pull Request - Open external status links externally
  3. // @namespace http://hear.com
  4. // @version 2024-08-31
  5. // @description Open external links in the "Checks" section in a new tab
  6. // @author nate.clark@hear.com
  7. // @match https://github.com/*/*/pull/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=github.com
  9. // @tag productivity
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. const nonGitHubTextKeys = ['sonarqube']
  17. const getRowText = (link) => link.parentNode.parentNode.innerText
  18.  
  19. const isSonarQubeLink = (link) => {
  20. const text = getRowText(link)
  21.  
  22. return text.toLowerCase().indexOf('sonarqube') > -1
  23. }
  24.  
  25. const updateSonarQubeLink = (link) => {
  26. // https://sonarqube.service-production.audibene.net/dashboard?id=ta.opportunity-service&pullRequest=286
  27. // https://github.com/Audibene-GMBH/ta.opportunity-service/pull/286/checks?check_run_id=32341231160
  28. const pathnameParts = window.location.pathname.split('/')
  29. const repo = pathnameParts.at(2)
  30. const pullRequest = pathnameParts.at(4)
  31. const url = new URL('https://sonarqube.service-production.audibene.net/dashboard')
  32.  
  33. url.searchParams.set('id', repo)
  34. url.searchParams.set('pullRequest', pullRequest)
  35.  
  36. link.setAttribute('href', url.href)
  37. }
  38.  
  39. const isNotGitHubLink = (link) => {
  40. const href = link.getAttribute('href')
  41. const text = getRowText(link)
  42. const isNonGitHub = href.startsWith('/') === false || nonGitHubTextKeys.some((key) => text.toLowerCase().indexOf(key.toLowerCase()) > -1)
  43.  
  44. return isNonGitHub
  45. }
  46.  
  47. const makeLinkExternal = (link) => {
  48. link.setAttribute('target', '_blank')
  49. link.innerHTML = `<span>Details</span><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 16 16"><path fill="currentColor" d="M3.75 2h3.5a.75.75 0 0 1 0 1.5h-3.5a.25.25 0 0 0-.25.25v8.5c0 .138.112.25.25.25h8.5a.25.25 0 0 0 .25-.25v-3.5a.75.75 0 0 1 1.5 0v3.5A1.75 1.75 0 0 1 12.25 14h-8.5A1.75 1.75 0 0 1 2 12.25v-8.5C2 2.784 2.784 2 3.75 2m6.854-1h4.146a.25.25 0 0 1 .25.25v4.146a.25.25 0 0 1-.427.177L13.03 4.03L9.28 7.78a.75.75 0 0 1-1.042-.018a.75.75 0 0 1-.018-1.042l3.75-3.75l-1.543-1.543A.25.25 0 0 1 10.604 1"/></svg>`
  50. link.style.display = 'grid'
  51. link.style.alignItems = 'center'
  52. link.style.gap = '0.25rem'
  53. link.style.gridAutoFlow = 'column'
  54.  
  55. if (isSonarQubeLink(link)) {
  56. updateSonarQubeLink(link)
  57. }
  58. }
  59.  
  60. const setLinkTargets = () => {
  61. const links = [...document.querySelectorAll('a.status-actions:not([target])')]
  62. const nonGitHubLinks = links.filter(isNotGitHubLink);
  63.  
  64. nonGitHubLinks.forEach(makeLinkExternal)
  65. }
  66.  
  67. // Because when a build is running, these links are constantly updated/refreshed
  68. setInterval(setLinkTargets, 500)
  69. })();