Last active
November 7, 2019 09:34
-
-
Save plugn/c9aa3b4f4c517afa4d93514df89cc3c0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// JIRA LINKED TASKS UTILITY | |
const getLinked = () => Array.from($$('.link-content')) | |
const getTitle = (block, taskPrefix='RAIS') => ($$('span[title^=' + taskPrefix +']', block)[0] || {}).title | |
const getStatus = block => ($$('li.status span', block)[0] || {}).textContent | |
const getPriority = block => ($$('li.priority img', block)[0] || {}).title | |
const getLinkedTasks = () => ( | |
getLinked().map(block => ({ | |
title: getTitle(block), | |
status: getStatus(block), | |
priority: getPriority(block) | |
})) | |
) | |
const textCorrector = (text) => String(text).replace(/([\wА-я]+)("|')([\wА-я]+)/g, '$1 $2$3') | |
const reverseString = text => String(text).split('').reverse().join('') | |
const truncateString = (text, size = 48) => { | |
const trunc = reverseString(text.length <= size ? text : text.substr(0, size)); | |
return reverseString(trunc.substr(trunc.indexOf(' ') + 1)) | |
} | |
const decorateString = text => truncateString(textCorrector(text), 50) | |
const sortList = list => Array.from(list).sort((a, b) => a.localeCompare(b)) | |
const sortListBy = (list, by) => Array.from(list).sort((a, b) => a[by].localeCompare(b[by])) | |
const printLinkedTasks = () => { | |
const tasks = getLinkedTasks() | |
return sortListBy(tasks, 'title').map(v => decorateString(v.title)).join('\n') | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment