Skip to content

Commit

Permalink
feat(custom): Add Jira and Gitlab custom scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
izontm committed Jun 7, 2024
1 parent 0f14456 commit d819b95
Show file tree
Hide file tree
Showing 3 changed files with 333 additions and 0 deletions.
142 changes: 142 additions & 0 deletions src/content/_custom_nf_gitlab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
//// START GITLAB
togglbutton.render(
'.issue-details .detail-page-description:not(.toggl)',
{ observe: !0 },
function (t) {
const n = [
[a()]
.filter(Boolean)
.map(function (r) {
return '#' + r;
})
.join(''),
i(t),
]
.filter(Boolean)
.join(' ');
o($('.detail-page-header-actions'), n, !0), o($('.time-tracker'), n);
}
);
togglbutton.render(
'.merge-request > .detail-page-header:not(.toggl)',
{ observe: !0 },
function (t) {
const n = [
[a()]
.filter(Boolean)
.map(function (r) {
return 'MR' + r + '::';
})
.join(''),
i(t),
]
.filter(Boolean)
.join(' ');
o($('.detail-page-header-actions'), n, !0), o($('.time-tracker'), n);
}
);
function o(t, e, n = !1) {
const r = togglbutton.createTimerLink({
className: 'gitlab',
description: e,
tags: l,
taskId: (o, i) => {
return extractTaskId(o, i);
},
projectName: (o, i) => {
return extractProjectName(o, i);
},
});
n ? t.parentElement.insertBefore(r, t) : t.parentElement.appendChild(r, t);
}
function i(t) {
const e = t.querySelector('.title');
return e ? e.textContent.trim() : '';
}
function a() {
const t = window.location.pathname,
e = /-\/(issues|merge_requests)\/(?<id>\d+)/;
return (e.test(t) ? t.match(e) : { groups: { id: '' } }).groups.id;
}
function s() {
const t =
$('.title .project-item-select-holder') ||
$('.breadcrumbs-list li:nth-last-child(3) .breadcrumb-item-text');
return t ? t.textContent.trim() : '';
}
function l() {
const t = document.querySelectorAll('div.labels span[data-qa-label-name]');
if (!t) return [];
const e = [];
for (const n of Object.values(t)) {
const r = n.getAttribute('data-qa-label-name');
e.push(r);
}
return e;
}

////END GITLAB

////START HELPER
const ExtractNFGitlabTogglTaskId = () => {
debugger;
let togglTaskId = null;
let tags = l();
const GITLAB_LABEL_REGEX = /togg(e|)l(::|:)/gim;
const REMOVE_TRALING_LABEL_DESCRIPTION = / .*/;

debugger;
if (Array.isArray(tags)) {
tags.forEach((element) => {
if (element.match(GITLAB_LABEL_REGEX)) {
togglTaskId = element
.replace(GITLAB_LABEL_REGEX, '')
.toUpperCase()
.replace(REMOVE_TRALING_LABEL_DESCRIPTION, '');
return;
}
});
}
return togglTaskId;
};

function extractTaskId(projects, tasks) {
debugger;
let nfTogglTask = ExtractNFGitlabTogglTaskId();
if (nfTogglTask === null) {
return {};
}

const n = Object.keys(tasks).filter((o) =>
tasks[o].name.startsWith(nfTogglTask)
),
s = n.length > 0 ? tasks[n[0]].id : {};
return s;
}

function extractTaskProjectId(nfTogglTask, projects, tasks) {
if (nfTogglTask === null) {
return null;
}

const n = Object.keys(tasks).filter((o) =>
tasks[o].name.startsWith(nfTogglTask)
),
s = n.length > 0 ? tasks[n[0]].project_id : null;
console.log(s);
return s;
}

function extractProjectName(projects, tasks) {
debugger;
let nfTogglTask = ExtractNFGitlabTogglTaskId();
if (nfTogglTask === null) {
return null;
}

let projectID = extractTaskProjectId(nfTogglTask, projects, tasks);
const n = Object.keys(projects).filter((o) => projects[o].id === projectID),
s = n.length > 0 ? projects[n[0]].name : null;
console.log(s);
return s;
}
183 changes: 183 additions & 0 deletions src/content/_custom_nf_jira.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/// START JIRA

togglbutton.render(
'#ghx-detail-view [spacing] h1:not(.toggl)',
{ observe: !0 },
function () {
debugger;
({}).DEBUG && console.info('\u{1F3C3} "Jira 2017 sidebar" rendering');
const n = $('#ghx-detail-view'),
t = createTag('div', 'jira-ghx-toggl-button'),
i = $('[spacing] h1', n),
e = $('[spacing] a', n),
o = $('.bgdPDV');
let r = i.textContent;
e !== null && (r = e.textContent + ' ' + r);
const a = togglbutton.createTimerLink({
className: 'jira2017',
description: r,
buttonType: 'minimal',
taskId: (o, i) => {
return extractTaskId(ExtractNFJiraTogglTaskId(), o, i);
},
projectName: (o, i) => {
return extractProjectName(ExtractNFJiraTogglTaskId(), o, i);
},
});
t.appendChild(a), e.parentNode.appendChild(t);
}
);

togglbutton.render('#title-heading:not(.toggl)', { observe: !0 }, function (n) {
const i = $('[id="title-text"]', n).textContent.trim(),
e = togglbutton.createTimerLink({
className: 'confluence',
description: i,
taskId: (o, i) => {
return extractTaskId(ExtractNFJiraTogglTaskId(), o, i);
},
projectName: (o, i) => {
return extractProjectName(ExtractNFJiraTogglTaskId(), o, i);
},
});
$('#title-text').appendChild(e);
});

//JIRA Issue View
togglbutton.render(
'.issue-header-content:not(.toggl)',
{ observe: !0 },
function (n) {
debugger;
({}).DEBUG && console.info('\u{1F3C3} "Jira 2017 issue page" rendering');
const t = $('#key-val', n),
i = $('#summary-val', n) || '';
let e = $('.bgdPDV'),
o;
i && (o = i.textContent.trim()),
t !== null && (o && (o = ' ' + o), (o = t.textContent + o)),
e === null &&
(e = $(
'[data-test-id="navigation-apps.project-switcher-v2"] button > div:nth-child(2) > div'
)),
e === null && (e = $('#project-name-val'));

const r = togglbutton.createTimerLink({
className: 'jira2017',
description: o,
taskId: (o, i) => {
return extractTaskId(ExtractNFJiraTogglTaskId(), o, i);
},
projectName: (o, i) => {
return extractProjectName(ExtractNFJiraTogglTaskId(), o, i);
},
});
r.style.marginLeft = '8px';
const a =
($('.issue-link') || {}).parentElement ||
($('.aui-nav li') || {}).lastElementChild;
a && a.appendChild(r);
}
);

//JIRA Board Detail
togglbutton.render(
'#ghx-detail-issue:not(.toggl)',
{ observe: !0 },
function (n) {
debugger;
const t = createTag('div', 'ghx-toggl-button'),
i = $('[data-field-id="summary"]', n),
e = $('.ghx-fieldname-issuekey a'),
o = $('.ghx-project', n);
let r = i.textContent;
e !== null && (r = e.textContent + ' ' + r);
const a = togglbutton.createTimerLink({
className: 'jira',
description: r,
taskId: (o, i) => {
return extractTaskId(ExtractNFJiraTogglTaskId(), o, i);
},
projectName: (o, i) => {
return extractProjectName(ExtractNFJiraTogglTaskId(), o, i);
},
});
t.appendChild(a), $('#ghx-detail-head').appendChild(t);
}
);

// JIRA Issue List Issue View
togglbutton.render(
'.issue-header-content:not(.toggl)',
{ observe: !0 },
function (n) {
debugger;
let t;
const i = $('#key-val', n),
e = $('#summary-val', n) || '',
o = $('#project-name-val', n);
e && (t = e.textContent),
i !== null && (t && (t = ' ' + t), (t = i.textContent + t));
const r = togglbutton.createTimerLink({
className: 'jira',
description: t,
taskId: (o, i) => {
return extractTaskId(ExtractNFJiraTogglTaskId(), o, i);
},
projectName: (o, i) => {
return extractProjectName(ExtractNFJiraTogglTaskId(), o, i);
},
}),
a = createTag('ul', 'toolbar-group'),
s = createTag('li', 'toolbar-item');
s.appendChild(r), a.appendChild(s), $('.toolbar-split-left').appendChild(a);
}
);
//// END JIRA

////START HELPER
const ExtractNFJiraTogglTaskId = () => {
let e = '';
const t = document.querySelector('#customfield_10206-val');
let ret =
(t && (e && (e += ' '), (e += t.textContent.trim())),
e.split('-')[0].trim());
return ret.length > 0 ? ret : null;
};

function extractTaskId(nfTogglTask, projects, tasks) {
if (nfTogglTask === null) {
return {};
}
const n = Object.keys(tasks).filter((o) =>
tasks[o].name.startsWith(nfTogglTask)
),
s = n.length > 0 ? tasks[n[0]].id : {};
return s;
}

function extractTaskProjectId(nfTogglTask, projects, tasks) {
debugger;
if (nfTogglTask === null) {
return null;
}
const n = Object.keys(tasks).filter((o) =>
tasks[o].name.startsWith(nfTogglTask)
),
s = n.length > 0 ? tasks[n[0]].project_id : null;
console.log(s);
return s;
}

function extractProjectName(nfTogglTask, projects, tasks) {
if (nfTogglTask === null) {
return null;
}
let projectID = extractTaskProjectId(nfTogglTask, projects, tasks);
const n = Object.keys(projects).filter((o) => projects[o].id === projectID),
s = n.length > 0 ? projects[n[0]].name : null;
console.log(s);
return s;
}

////END HELPER
8 changes: 8 additions & 0 deletions src/custom-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@ export const CustomScripts = {
name: 'Custom Script For XYZ',
file: '_custom_SampleScript.js',
},
'nfJiraScript': {
name: 'Custom Jira Script',
file: '_custom_nf_jira.js',
},
'nfGitlabScript': {
name: 'Custom Gitlab Script',
file: '_custom_nf_gitlab.js',
},
}

0 comments on commit d819b95

Please sign in to comment.