ts-ci/src/tools/octokit-addons/listCommit.ts

51 lines
No EOL
1.1 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { Octokit } from "@octokit/rest";
import { getCommitAsyncIterableFactory } from "./getCommitAsyncIterable";
import type { Commit } from "./getCommitAsyncIterable";
/** Return the list of commit since given sha (excluded)
* ordered from the oldest to the newest */
export function listCommitFactory(
params: { octokit: Octokit }
) {
const { octokit } = params;
const { getCommitAsyncIterable } = getCommitAsyncIterableFactory({ octokit });
async function listCommit(
params: {
owner: string;
repo: string;
branch: string;
sha: string;
}
): Promise<Commit[]> {
const { owner, repo, branch, sha } = params;
const commitAsyncIterable = getCommitAsyncIterable({
owner,
repo,
branch
});
const commits: Commit[]= [];
for await (const commit of commitAsyncIterable) {
if( commit.sha === sha ){
break;
}
commits.push(commit);
}
return commits.reverse();
}
return { listCommit };
}