Open Workflow for current Issue

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

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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");
})();