TMS_Library

util lib for TMS related scripts

2024-02-02 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/486123/1321491/TMS_Library.js

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         TMS_Library
// @namespace    http://tampermonkey.net/
// @version      1.0.0
// @description  util lib for TMS related scripts
// @author       bliushtein
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        GM_xmlhttpRequest
// ==/UserScript==
 
function getConstants() {
    return {
        DESIGN_GAP: "DesignGap",
        CROSS_STREAM_GAP: "CrossStreamGap",
        OVERHEAD_TYPES: ["DesignGap", "CrossStreamGap"],
        DEV_STORY: "DevStory",
        DESIGN_STORY: "DesignChapter",
        BA_COMMUNICATION: "BACommunication",
        CROSS_STREAM_COMMUNICATION: "CrossStreamCommunication",
        DEV_TEST: "DevTest"
    }
}
 
function delay(milliseconds){
    return new Promise(resolve => {
        setTimeout(resolve, milliseconds);
    });
}
function sendRequest(url, method = 'GET', body = null) {
    console.log(url, method, body);
    return new Promise((resolve, reject) => {
        GM_xmlhttpRequest({
            method: method,
            timeout: 5000,
            onerror: reject,
            ontimeout: reject,
            onload: resolve,
            headers: {
                Accept: 'application/json',
                'Content-Type': 'application/json',
                // If a user agent is not passed - a POST request fails with 403 error
                'User-Agent': 'Any',
            },
            data: body,
            url: url,
        });
    }).then(response => {
        if ([200, 201].indexOf(response.status) !== -1) {
            if (response.responseText == null) {
                return {};
            }
            return JSON.parse(response.responseText);
        }
        throw new Error(response.status + ' ' + response.statusText + ' ' + response.responseText);
    });
}
 
async function getIssues(keys, fields = ["timetracking", "components", "issuetype", "labels", "priority", "customfield_10200", "customfield_10201", "customfield_10006", "summary", "status", "issuelinks"]) {
    if (keys.length == 0) {
        return {issues: []};
    }
    return await sendRequest(`https://tms.netcracker.com/rest/api/latest/search?jql=issuekey IN (${keys.join(",")})&fields=${fields.join(",")}`);
}
 
async function getSubtasts(keys, fields = ["timetracking", "components", "issuetype", "labels", "status"]) {
    if (keys.length == 0) {
        return {issues: []};
    }
    return await sendRequest(`https://tms.netcracker.com/rest/api/latest/search?jql=parent IN (${keys.join(",")})&fields=${fields.join(",")}`);
}