Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements #7

Merged
merged 6 commits into from
Feb 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict'

const PR_RE = /\/nodejs\/([^\/]+)\/pull\/([^\/]+)\/?$/
const PR_RE = /^\/nodejs\/([^\/]+)\/pull\/([^\/]+)\/?$/

const b = chrome.extension.getBackgroundPage()
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.url === undefined) return
if (PR_RE.test(changeInfo.url)) {
if (PR_RE.test(new URL(changeInfo.url).pathname)) {
chrome.browserAction.enable()
chrome.browserAction.setIcon({
path: 'icon_good.png'
Expand Down
62 changes: 17 additions & 45 deletions review.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
, REJECTED: 'REJECTED'
}

const PR_RE = /\/nodejs\/([^\/]+)\/pull\/([^\/]+)\/?$/
const PR_RE = /^\/nodejs\/([^\/]+)\/pull\/([^\/]+)\/?$/

const { prUrl, repo } = getPR()
if (!prUrl) {
Expand Down Expand Up @@ -38,6 +38,7 @@
const status = this.reviewers.get(login)
if (status === STATUS.APPROVED) return
this.rejections -= 1
this.approvals += 1
this.reviewers.set(login, STATUS.APPROVED)
}

Expand All @@ -50,6 +51,7 @@
const status = this.reviewers.get(login)
if (status === STATUS.REJECTED) return
this.approvals -= 1
this.rejections += 1
this.reviewers.set(login, STATUS.REJECTED)
}
}
Expand Down Expand Up @@ -120,35 +122,13 @@
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this not used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it wasn't.


function getFixesUrl() {
const op = document.querySelector('.discussion-timeline .comment-body')
const text = op.innerText

var fixes = text.match(FIXES_RE)
if (fixes) {
const tmp = fixes[1]
if (tmp[0] === '#') {
// This is a reference to an issue in the current repository.
// Generate the full url
return `https://github.com/${repo}/issues/${tmp.slice(1)}`
} else {
return `https://github.com/${tmp}`
}
}

return null
}

function getFixesUrlsFromArray(ar) {
return ar.reduce((set, item) => {
const m = item.match(FIX_RE)
if (!m) return set
const fix = m[1]
if (fix[0] === '#') {
set.push(`https://github.com/${repo}/issues/${fix.slice(1)}`)
} else {
set.push(`https://github.com/${fix}`)
}
const url = fix.replace(/^#/, `${repo}#`).replace('#', '/issues/')
set.push(`https://github.com/${url}`)
return set
}, [])
}
Expand Down Expand Up @@ -211,7 +191,7 @@
function formatMeta(meta, collabs) {
const revs = []
for (const name of meta.reviewers.keys()) {
const c = collabs[name]
const c = collabs.get(name)
if (!c) {
console.error('skipping unknown reviewer', name)
continue
Expand All @@ -238,8 +218,7 @@
return `<br>
<p>
${result.join('\n')}
${revs.join('<br>')}
<br>
${revs.join('<br>')}<br>
</p>
`
}
Expand Down Expand Up @@ -372,8 +351,8 @@
const href = a.getAttribute('href')
if (!href) continue
const login = href.slice(1).toLowerCase()
const body = comment.querySelector('.comment-body')
if (body && LGTM_RE.test(body.innerHTML)) {
const paragraphs = comment.querySelectorAll('.comment-body > p')
if (Array.from(paragraphs).some(p => LGTM_RE.test(p.innerHTML))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, what's the reason for this change? I find this a lot more difficult to read than the previous implementation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In nodejs/node#10657, a LGTM embedded in a <blockquote> (and therefore one that does not belong to the author of the comment) was recognized. This piece of code only looks for direct <p> children of .comment-body, and mitigates that issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah cool that makes sense.

revs.push(login)
}
}
Expand All @@ -384,30 +363,23 @@
function getCollaborators(cb) {
// This is more or less taken from
// https://github.com/rvagg/iojs-tools/blob/master/pr-metadata/pr-metadata.js
const RE = '\\* \\[([^\\]]+)\\]\\([^\\)]+\\) -\\s\\*\\*([^\\*]+)\\*\\* ' +
'&lt;([^&]+)&gt;'
const RE = /\* \[(.+?)\]\(.+?\) -\s\*\*(.+?)\*\* &lt;(.+?)&gt;/mg;
const url = 'https://raw.githubusercontent.com/nodejs/node/master/README.md'
fetch(url)
.then((res) => res.text())
.then((body) => {
const collabs = body.match(new RegExp(RE, 'mg'))
if (!collabs) {
const err = new Error('Could not parse collaborators')
return cb(err)
}
const members = new Map
let m

const members = collabs.reduce((set, item) => {
const m = item.match(new RegExp(RE))
set[m[1].toLowerCase()] = {
while (m = RE.exec(body)) {
members.set(m[1].toLowerCase(), {
login: m[1]
, name: m[2]
, email: m[3]
}

return set
}, {})
})
}

if (!Object.keys(members).length) {
if (!members.size) {
throw new Error('Could not find any collaborators')
}

Expand Down