Last active
June 13, 2016 16:22
-
-
Save goizueta/91357ac523c1da28d4e4ea1027d7005a to your computer and use it in GitHub Desktop.
Get past PRs. Github API only goes back 300 events (comments, commits, pushes, pulls, etc...)
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 GitHubApi = require("github"); | |
var user = "kn9ts"; | |
var pullRequests = []; | |
var github = new GitHubApi({ | |
// optional | |
debug: false, | |
protocol: "https", | |
host: "api.github.com", // should be api.github.com for GitHub | |
pathPrefix: "", // for some GHEs; none for GitHub | |
timeout: 5000, | |
headers: { | |
"user-agent": "Andela" // GitHub is happy with a unique user agent | |
}, | |
followRedirects: false, // default: true; there's currently an issue with non-get redirects, so allow ability to disable follow-redirects | |
includePreview: true // default: false; includes accept headers to allow use of stuff under preview period | |
}); | |
github.authenticate({ | |
type: "oauth", | |
token: "f9d259f8f93c383d30c772fedf5dc36d11ff31f6" | |
}); | |
github.activity.getEventsForUser({ | |
// optional: | |
// headers: { | |
// "cookie": "blahblah" | |
// }, | |
per_page: 100, | |
user: user | |
}, getPrs); | |
function getPrs(err, res) { | |
if (err) { | |
console.log(err); | |
return false; | |
} | |
pullRequests = pullRequests.concat(res); | |
if (github.hasNextPage(res)) { | |
github.getNextPage(res, getPrs) | |
} else { | |
outputPrs(); | |
} | |
} | |
function outputPrs() { | |
var prs = pullRequests.filter(function(entry) { | |
return entry.type === "PullRequestEvent" && entry.payload.action === "closed" && entry.payload.pull_request.merged; | |
}); | |
console.log(user); | |
prs.forEach(function(pr) { | |
console.log(pr.repo.name); | |
console.log(pr.payload.pull_request.html_url); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment