Create a macOS Service to open a JIRA ticket from any selected text

[Este artículo esta disponible en español en este enlace.]

There are many occasions in which one receives an email, or text message about a JIRA ticket, mentioning its ID, and it would be very convenient to be able to open it directly from that message. In order to make that possible, you can create a service using Automator if you follow the next steps:

  1. Select some text —for instance, the very JIRA ID you want to search—, and from the Services contextual menu (see screenshot) choose the Create Service option.Screenshot 2020-02-21 12.32.36.png
  2. Automator will open with a new workflow configured to work as a service. You need to make sure that the select the Automatic (text) option keeps selected in the Workflow receives current pop-up, so that you don’t suffer from formatting issues.Screenshot 2020-02-21 12.34.36.png
  3. Next, you need to add — by dragging it from the left panel in the Utilities section— the Run shell script module, and configure it to use Python (/usr/bin/python), and then choose the option as arguments form the Pass input dropdown menu. That allows you to use sys.argv to get the input. Then you have to add the following code —replacing path.to.jira.urlwith the right URL to your JIRA, such as jira.company.com, for instance— in the code box (see below).
  4. After that, you need to add the Display Webpages from the Safari section. That module takes the output of the previous module —which is the URL built by the Python code above— and passes it to Safari as a URL to open.
  5. You can then save the Workflow with a name like Open ticket in JIRA.
import sys # we use sys to get the input to the service
           # in sys.argv
from urllib import quote # to convert high-ASCII and other
                         # into URL-compatible quoting
# get the text from the selection, and URL quote it
text_input = quote("".join(sys.argv[1:]))
# URL for the JIRA QuickSearch
jira_search_base_url = "https://path.to.jira.url/secure/QuickSearch.jspa?searchString={}"

# Output of the workflow done by a print
print(jira_search_base_url.format(text_input))

From that moment on, you can use the contextual  Services > Open ticket in JIRA right from a text selection, and JIRA will do a smart search based on that text: if the selection corresponds to a project ID, it will search all issues in that project; if the selection corresponds to a JIRA ticket ID, the ticket will directly open up; and if what you select is any other kind of text, it will do a search by that text across all JIRA projects.

The final result looks as follows:

Screenshot of the whole Automator workflow

If you want to take it easy, you can download the following service, and then install it in Automator just by uncompressing and under clicking: Open SKA JIRA issue.workflow. You will have to configure it for your own URL, though!

Hope that was useful!

Update 26/02/2020

First of all, I have to thank @flyingfrog for the suggestion to use the smart query URL instead of just building a URL by concatenation. Thanks to that, you can use this on top of a sample JQL (JIRA Query Language) query. If the JQL contains a project clause, that will be correctly interpreted, but the rest is interpreted as text ~"rest of JQL", so you will need to edit a little bit the result, but it can simplify your querying.

Actualización 07/07/2022

Automator no longer shows /usr/bin/python or /usr/bin/python3 among the list of potential shells, but if you installed a Python under /usr/local/bin, say through MacPorts or Homebrew, they will also appear there. In this case, you need to install the requests Python library by typing /usr/local/bin/pip3 install requests in Terminal.app, and in the code above you need to change from urllib import quote so that it reads from requests.utils import quote instead.


Comentarios

Una respuesta a «Create a macOS Service to open a JIRA ticket from any selected text»

To respond on your own website, enter the URL of your response which should contain a link to this post’s permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post’s URL again. (Find out more about Webmentions.)

Descubre más desde Memoria de Acceso Aleatorio

Suscríbete ahora para seguir leyendo y obtener acceso al archivo completo.

Seguir leyendo