24 lines
592 B
JavaScript
24 lines
592 B
JavaScript
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);
|
|
}
|