diff options
author | HampusM <hampus@hampusmat.com> | 2021-08-15 15:03:44 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-08-15 15:03:44 +0200 |
commit | 9736749a779661a95211a91200617a03a1b9a702 (patch) | |
tree | 6bea5e5ec5773aa940e79e7e80c9ebac086eaa10 /packages/server/src/git | |
parent | c32094d0b1fc3aa5160087d71bff36ed1779bc3a (diff) |
Added a count query parameter to the log API endpoint
Diffstat (limited to 'packages/server/src/git')
-rw-r--r-- | packages/server/src/git/commit.ts | 17 | ||||
-rw-r--r-- | packages/server/src/git/repository.ts | 11 |
2 files changed, 20 insertions, 8 deletions
diff --git a/packages/server/src/git/commit.ts b/packages/server/src/git/commit.ts index 6b3c38b..6ef02ef 100644 --- a/packages/server/src/git/commit.ts +++ b/packages/server/src/git/commit.ts @@ -1,4 +1,4 @@ -import { Commit as NodeGitCommit, Oid as NodeGitOid } from "nodegit"; +import { Commit as NodeGitCommit, Oid as NodeGitOid, Revwalk as NodeGitRevwalk } from "nodegit"; import { Author } from "api"; import { Diff } from "./diff"; import { Repository } from "./repository"; @@ -209,4 +209,19 @@ export class Commit { public static async branchCommit(owner: Repository): Promise<Commit> { return new Commit(owner, await owner.ng_repository.getBranchCommit(owner.branch_name)); } + + /** + * Returns a number of commits in a repository + * + * @param owner - The repository which the commits are in + * @param [count=20] - The number of commits to get + * @returns An array of commit instances + */ + public static async getMultiple(owner: Repository, count = 20): Promise<Commit[]> { + const walker = NodeGitRevwalk.create(owner.ng_repository); + + walker.pushRef(`refs/heads/${owner.branch_name}`); + + return Promise.all((await walker.getCommits(count)).map(commit => new Commit(owner, commit))); + } }
\ No newline at end of file diff --git a/packages/server/src/git/repository.ts b/packages/server/src/git/repository.ts index 9e83281..c1410ab 100644 --- a/packages/server/src/git/repository.ts +++ b/packages/server/src/git/repository.ts @@ -1,4 +1,4 @@ -import { Object as NodeGitObject, Oid as NodeGitOid, Repository as NodeGitRepository, Revwalk as NodeGitRevwalk } from "nodegit"; +import { Object as NodeGitObject, Oid as NodeGitOid, Repository as NodeGitRepository } from "nodegit"; import { Request, connect } from "./http"; import { basename, dirname } from "path"; import { getDirectory, getFile } from "./misc"; @@ -81,14 +81,11 @@ export class Repository { /** * Returns the repository's commits * + * @param [count=20] - The number of commits to get * @returns An array of commit instances */ - public async commits(): Promise<Commit[]> { - const walker = NodeGitRevwalk.create(this.ng_repository); - - walker.pushRef(`refs/heads/${this.branch_name}`); - - return Promise.all((await walker.getCommitsUntil(() => true)).map(commit => new Commit(this, commit))); + public async commits(count?: number): Promise<Commit[]> { + return Commit.getMultiple(this, count); } /** |