Generate Launchpad Bug Links from tags

Parse tags, create buttons for originate-from bug links and JIRA links

  1. // ==UserScript==
  2. // @name Generate Launchpad Bug Links from tags
  3. // @namespace http://anthonywong.net/
  4. // @version 1.4
  5. // @description Parse tags, create buttons for originate-from bug links and JIRA links
  6. // @match https://bugs.launchpad.net/*/+bug/*
  7. // @grant none
  8. // @license GPLv2
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. 'use strict';
  13.  
  14. // Locate the <span id="tag-list"> element
  15. const tagsElement = document.querySelector('#tag-list');
  16.  
  17. if (tagsElement) {
  18. // Extract the tags as text
  19. const tagsText = tagsElement.textContent;
  20.  
  21. // Find all "originate-from-XXXX" patterns
  22. const originateMatches = tagsText.match(/originate-from-(\d+)/g);
  23.  
  24. // Find all "jira-$JIRA_TICKET" patterns
  25. const jiraMatches = tagsText.match(/jira-([a-zA-Z0-9\-]+)/g);
  26.  
  27. // Create a container for the buttons
  28. const buttonContainer = document.createElement("div");
  29. buttonContainer.style.marginTop = "10px";
  30.  
  31. // Process originate-from tags
  32. if (originateMatches) {
  33. originateMatches.forEach((tag) => {
  34. const bugNumber = tag.replace("originate-from-", "");
  35.  
  36. // Create a button
  37. const button = document.createElement("button");
  38. button.textContent = `Go to Bug ${bugNumber}`;
  39. button.style.marginRight = "5px";
  40. button.style.padding = "5px 10px";
  41.  
  42. // Set up the button click event
  43. button.addEventListener("click", () => {
  44. const bugUrl = `https://bugs.launchpad.net/ubuntu/+bug/${bugNumber}`;
  45. window.open(bugUrl, "_blank");
  46. });
  47.  
  48. // Add the button to the container
  49. buttonContainer.appendChild(button);
  50. });
  51. }
  52.  
  53. // Process JIRA tags
  54. if (jiraMatches) {
  55. jiraMatches.forEach((tag) => {
  56. const jiraTicket = tag.replace("jira-", "").toUpperCase();
  57.  
  58. // Create a button
  59. const button = document.createElement("button");
  60. button.textContent = `Go to JIRA ${jiraTicket}`;
  61. button.style.marginRight = "5px";
  62. button.style.padding = "5px 10px";
  63.  
  64. // Set up the button click event
  65. button.addEventListener("click", () => {
  66. const jiraUrl = `https://warthogs.atlassian.net/browse/${jiraTicket}`;
  67. window.open(jiraUrl, "_blank");
  68. });
  69.  
  70. // Add the button to the container
  71. buttonContainer.appendChild(button);
  72. });
  73. }
  74.  
  75. // Append the container below the tags element
  76. if (buttonContainer.childNodes.length > 0) {
  77. tagsElement.parentNode.appendChild(buttonContainer);
  78. }
  79. }
  80. })();