Updated RH_jira_bz_linker

- Isolated function
- updated namespace
This commit is contained in:
Sagi Dayan 2021-07-08 17:36:07 +03:00
parent 87261d33a0
commit eeb290586b
Signed by: sagi
GPG key ID: FAB96BFC63B46458

View file

@ -1,30 +1,31 @@
// ==UserScript== // ==UserScript==
// @name RedHat jira BZ Linker // @name RedHat jira BZ Linker
// @version 0.0.1 // @version 0.0.1
// @namespace http://arantius.com/misc/greasemonkey/ // @namespace https://git.sagidayan.com/sagi/greasemonkey-scripts
// @author Sagi Dayan // @author Sagi Dayan
// @description Adds BZ links in (RedHat) Jira when needed // @description Adds BZ links in (RedHat) Jira when needed
// @match https://issues.redhat.com/* // @match https://issues.redhat.com/*
// ==/UserScript== // ==/UserScript==
// Constants (function () {
const LOG_TAG = '[BZ-LINKER]'; // Constants
const summaryRegExp = new RegExp(/\[([0-9]+)\]/); const LOG_TAG = '[BZ-LINKER]';
const summaryRegExp = new RegExp(/\[([0-9]+)\]/);
// Entry point - observe DOM changes - and search for unlinked jira tickets // Entry point - observe DOM changes - and search for unlinked jira tickets
var observer = new MutationObserver(update); var observer = new MutationObserver(update);
observer.observe(document.body, { childList: true, characterData: true, subtree: true }); observer.observe(document.body, { childList: true, characterData: true, subtree: true });
// adds a tag prefix to logs for easy filters // adds a tag prefix to logs for easy filters
function log(...args) { function log(...args) {
const msg = args.reduce((msg, data) => { const msg = args.reduce((msg, data) => {
return `${msg} ${data}`; return `${msg} ${data}`;
}, LOG_TAG); }, LOG_TAG);
console.log(msg); console.log(msg);
} }
// When DOM changes - check for new unlinked issues // When DOM changes - check for new unlinked issues
function update() { function update() {
const issues = filterAndInflate([...document.getElementsByClassName("issuerow")]); const issues = filterAndInflate([...document.getElementsByClassName("issuerow")]);
if (issues.length) log(`Found #${issues.length} new unlinked issues. Linking...`); if (issues.length) log(`Found #${issues.length} new unlinked issues. Linking...`);
issues.forEach(issue => { issues.forEach(issue => {
@ -42,9 +43,9 @@ function update() {
} }
issue.touched = true; issue.touched = true;
}); });
} }
// Returns only rows (TR tags) that are not linked and are BZ bugs // Returns only rows (TR tags) that are not linked and are BZ bugs
function filterAndInflate(rows) { function filterAndInflate(rows) {
return rows.filter(r => { return rows.filter(r => {
if (r.tagName === 'TR' && !r.touched) { if (r.tagName === 'TR' && !r.touched) {
const summary = [...r.children].reduce((prev, child) => { const summary = [...r.children].reduce((prev, child) => {
@ -64,4 +65,5 @@ function filterAndInflate(rows) {
} }
return false; return false;
}) })
} }
})();