Created
September 28, 2020 14:44
-
-
Save reggi/b2dd35533ccdd80d99abab83ffcb9bec 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
var reviews = 'https://github.com/pulls/review-requested'; | |
var driverPulls = 'https://github.com/mongodb/node-mongodb-native/pulls/@me'; | |
var bsonPulls = 'https://github.com/mongodb/js-bson/pulls/@me'; | |
var allPulls = 'https://github.com/pulls'; | |
var isReviews = window.location.href === reviews | |
var isPulls = window.location.href === driverPulls || window.location.href === bsonPulls || window.location.href === allPulls | |
var valid = isReviews || isPulls | |
if (!valid) { | |
alert('Not on github'); | |
} | |
var DRAFT = 'Open draft pull request' | |
var PULL = "Open pull request" | |
var elms = document.querySelectorAll(".Box-row--drag-hide") | |
var anchors = [].map.call(elms, (d) = > { | |
const anchor = d.querySelector('.js-issue-row .js-navigation-open') | |
const icon = d.querySelector('.tooltipped.tooltipped-e'); | |
const repo = d.querySelector('.v-align-middle.muted-link.h4.pr-1').innerText.trim(); | |
const label = icon.getAttribute('aria-label') | |
return { | |
isPull: label === PULL, | |
isDraft: label === DRAFT, | |
href: anchor.href, | |
title: anchor.innerText, | |
repo | |
} | |
}); | |
var prefix = ((anchor) = > { | |
if (isReviews) return "Reviewing:"; | |
if (anchor.isPull) return "In Review:"; | |
if (anchor.isDraft) return "Working on:"; | |
}) | |
var getJiraHref = (id) = > { | |
return `https: \ / \ / jira.mongodb.org / browse / $ { | |
id | |
}`; | |
} | |
var getJiraId = (i) = > { | |
const begining = i.match(/^node(\s|-)\d\d\d\d/i)[0].replace(" ", "-").toUpperCase(); | |
if (begining) return begining | |
return i.match(/^node(\s|-)\d\d\d\d/i)[0].replace(" ", "-").toUpperCase(); | |
} | |
var getLink = (href, text) = > { | |
return ` [$ { | |
text | |
}]($ { | |
href | |
})`; | |
} | |
var getJiraLink = (id) = > { | |
return getLink(getJiraHref(id), id); | |
} | |
var getGithubLink = (i) = > { | |
return getLink(i.href, i.title); | |
} | |
var jiraFix = text = > { | |
const explore = pattern = > { | |
const m = text.match(pattern); | |
if (m) { | |
const newText = text.replace(pattern, ''); | |
return { | |
newText, | |
id: `NODE - $ { | |
m[0].replace(/\D+/g, '') | |
}` | |
}; | |
} | |
return null; | |
}; | |
const ending = / \((NODE-\d+)\)$/; | |
const start = /(^NODE-\d+\: )/; | |
const bracket = /^(\[NODE-\d+\]\s)/; | |
const _ending = explore(ending); | |
if (_ending) return _ending; | |
const _start = explore(start); | |
if (_start) return _start; | |
const _bracket = explore(bracket); | |
if (_bracket) return _bracket; | |
return { | |
newText: text, | |
id: null | |
}; | |
}; | |
var getListIterm = (i) = > { | |
const { | |
newText, | |
id | |
} = jiraFix(i.title) | |
const href = i.href | |
const contents = ['*', '[', ']', prefix(i), getGithubLink({ | |
href, | |
title: newText | |
})]; | |
if (id) contents.push(` ($ { | |
getJiraLink(id) | |
})`); | |
return contents.join(' '); | |
} | |
const repos = ['mongodb/js-bson', 'mongodb/node-mongodb-native'] | |
var list = anchors.filter(v = > repos.includes(v.repo)).map(getListIterm) | |
console.log(list.join('\n')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment