mirror of
https://github.com/garronej/ts-ci.git
synced 2025-11-30 21:43:05 +00:00
Follow up from https://github.com/garronej/github_actions_toolkit
This commit is contained in:
commit
5297ab00ab
54 changed files with 18162 additions and 0 deletions
51
src/tools/octokit-addons/listCommit.ts
Normal file
51
src/tools/octokit-addons/listCommit.ts
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
|
||||
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 };
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue