Created
October 17, 2020 00:04
-
-
Save useafterfree/017c6ce13230c641bb3e4c1dc65aab21 to your computer and use it in GitHub Desktop.
This file contains 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
let textNodesUnder = (el) => { | |
var n, a=[], walk=document.createTreeWalker(el, NodeFilter.SHOW_TEXT, null, false); | |
while(n = walk.nextNode() ) a.push(n); | |
return a; | |
} | |
let makeProjectLink = (dev) => `https://github.com/itrvl/itrvl/issues/${dev.replace(/[^0-9]+/mg, '')}`; | |
let makeProjectLinks = (line) => { | |
let projectLinks = line.match(/\[dev-([0-9]+)\]/igm); | |
projectLinks && projectLinks.map((devLink) => { | |
let link = makeProjectLink(devLink); | |
line = line.replace(devLink, `[${devLink}](${link})`); | |
}); | |
return line; | |
}; | |
let rowss = Array.from(document.querySelectorAll('.TimelineItem-body')).filter(a => textNodesUnder(a).length > 1); | |
let elements = ['div.pr-1 code a.link-gray', 'pre', '.avatar-user img', '.issue-link', 'code .link-gray']; | |
let label = ['commitMessage', 'commitDetail', 'authors', 'issue', 'hash']; | |
let outputList = []; | |
rowss.forEach((row, i) => { | |
const output = {}; | |
output.authors = []; | |
const users = []; | |
elements.forEach((lookup, i) => { | |
found = Array.from(row.querySelectorAll(lookup)) | |
if (found.length > 0) { | |
if (i == 0) { | |
output[label[i]] = found[0].outerText; | |
return; | |
} | |
found.forEach((elem) => { | |
if (elem.alt && i == 2) { | |
output[label[i]].push(elem.alt); | |
} else { | |
const texts = textNodesUnder(elem); | |
output[label[i]] = texts | |
.filter(t => t.data.match(/[a-zA-Z#@0-9]/)) | |
.map(t => t.data)[0]; | |
} | |
}); | |
} | |
}); | |
let { commitMessage, commitDetail, authors, issue, hash } = output; | |
// console.log(output); | |
let formatted = ''; //commitDetail ? `\t${commitDetail.replace(/\n/g, '\n\t').replace(/`/g, '\`')}` : ''; | |
let issueText = issue ? ` (${issue})` : ''; | |
let line = makeProjectLinks(`${hash} - ${authors && authors.join(', ')}:${issueText} ${commitMessage && commitMessage.replace(/\($/, '')}${formatted}`); | |
hash && outputList.push(line); | |
}); | |
console.log(outputList.join('\n')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment