Open Workflow for current Issue

Looks up the workflow for the currently opened Issue and opens it in a new tab

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ć!)

// ==UserScript==
// @name         Open Workflow for current Issue
// @namespace    http://schuppentier.org/
// @version      0.2
// @description  Looks up the workflow for the currently opened Issue and opens it in a new tab
// @author       Dennis Stengele
// @match        https://*.atlassian.net/browse/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=atlassian.net
// @grant        none
// @run-at       context-menu
// @license      MIT
// ==/UserScript==

/* jshint esversion: 11 */

(async function() {
    'use strict';

    let issuekey = location.pathname.split("/").pop(); // This SHOULD be done with JIRA.Issue.getIssueKey(), but this seems to always return null in Cloud.
    let projectKey = issuekey.split("-")[0];
    let baseUrl = location.origin;

    let issueTypeId = await fetch(`${baseUrl}/rest/api/3/issue/${issuekey}`).then(
        response => { return response.json(); }
    ).then(
        json => { return json.fields.issuetype.id; }
    );

    let projectId = await fetch(`${baseUrl}/rest/api/3/project/${projectKey}`).then(
        response => { return response.json(); }
    ).then(
        json => { return json.id; }
    );

    let workflowName = await fetch(`${baseUrl}/rest/api/3/workflowscheme/project?${new URLSearchParams({ projectId: projectId })}`).then(
        response => { return response.json(); }
    ).then(
        json => { return json.values[0].workflowScheme.issueTypeMappings[issueTypeId] ?? json.values[0].workflowScheme.defaultWorkflow; }
    );

    let encodedWorkflowName = encodeURIComponent(workflowName);

    window.open(`${baseUrl}/secure/admin/workflows/ViewWorkflowSteps.jspa?workflowMode=live&workflowName=${encodedWorkflowName}`, "_blank");
})();