mirror of
https://github.com/garronej/ts-ci.git
synced 2025-11-30 21:43:05 +00:00
51 lines
1.1 KiB
TypeScript
51 lines
1.1 KiB
TypeScript
|
|
|
|||
|
|
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 };
|
|||
|
|
|
|||
|
|
}
|