feat: fetch data for prs that need retest

This commit is contained in:
2018-10-17 15:56:11 -07:00
parent b6b5c27ffc
commit d1cfd7c20b
8 changed files with 164 additions and 4 deletions

23
src/lib/get_commits.mjs Normal file
View File

@@ -0,0 +1,23 @@
function formatCommit(commit) {
return {
sha: commit.sha,
owner: commit.committer.login,
message: commit.commit.message,
};
}
function formatCommits(commits, lastOnly) {
if (lastOnly) return formatCommit(commits.pop());
return commits.map(c => formatCommit(c));
}
export default async function getCommits(repo, id, lastOnly = true) {
const commits = await repo.pulls(id).commits.fetch();
if (commits.lastPage) {
const { items } = await commits.lastPage.fetch();
return formatCommits(items, lastOnly);
}
return formatCommits(commits.items, lastOnly);
}