CodeMatirx MR Title Input Validation

Validate CodeMatirx MR input field content with regex pattern ^(fix|feat|docs|doc|refactor|test|style|ci|chore|revert)(\(.*\))?!?: .+

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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         CodeMatirx MR Title Input Validation
// @license MIT
// @namespace    https://git.woa.com/
// @version      1.0
// @description  Validate CodeMatirx MR input field content with regex pattern ^(fix|feat|docs|doc|refactor|test|style|ci|chore|revert)(\(.*\))?!?: .+
// @author       kerwinpeng
// @match        https://git.woa.com/CodeMatrix/CodeMatrix/merge_requests/new?*
// @match        http://git.woa.com/CodeMatrix/CodeMatrix/merge_requests/new?*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    setTimeout(function() {
        const pattern = /^(fix|feat|docs|doc|refactor|test|style|ci|chore|revert)(\(.*\))?!?: .+/;
        const inputField = document.querySelector('.tg-input__input');
        if(!pattern.test(inputField.value)) {
           inputField.value='feat(qta): '+inputField.value
        }

        inputField.addEventListener('input', (event) => {
            const inputValue = event.target.value.trim();
            //console.log(inputValue)
            const isValid = pattern.test(inputValue);
            if (!isValid) {
                inputField.setCustomValidity('MR标题不符合正则  pattern:'+pattern);
                inputField.reportValidity();
                inputField.value='feat(qta): '+inputField.value
            } else {
                inputField.setCustomValidity('符合标准');
            }
        });
   }, 3000);
})();