Skip to content

Instantly share code, notes, and snippets.

@plugn
Last active November 7, 2019 09:34
Show Gist options
  • Save plugn/c9aa3b4f4c517afa4d93514df89cc3c0 to your computer and use it in GitHub Desktop.
Save plugn/c9aa3b4f4c517afa4d93514df89cc3c0 to your computer and use it in GitHub Desktop.
// 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