From d1a1b7dc947063aef5f8375a6a1e03246b272c84 Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 18 Aug 2021 17:29:55 +0200 Subject: Implemented caching for certain API endpoints, Added documentation & made backend-fixes --- packages/server/src/git/repository.ts | 36 ++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'packages/server/src/git/repository.ts') diff --git a/packages/server/src/git/repository.ts b/packages/server/src/git/repository.ts index c1410ab..53245be 100644 --- a/packages/server/src/git/repository.ts +++ b/packages/server/src/git/repository.ts @@ -38,7 +38,7 @@ export class Repository { public name: RepositoryName; public git_dir: string; - public branch_name: string; + private _branch: string; /** * @param repository - An instance of a Nodegit repository @@ -52,7 +52,7 @@ export class Repository { }; this.git_dir = dirname(repository.path()); - this.branch_name = branch; + this._branch = branch; } /** @@ -69,23 +69,31 @@ export class Repository { return getFile(this.git_dir, this.name.full, "owner"); } + get branch(): string { + return this._branch; + } + + set branch(branch: string) { + this._branch = branch; + } + /** * Returns the repository's branch * * @returns An instance of a branch */ - public branch(): Promise { - return Branch.lookup(this, this.branch_name); + public getBranch(): Promise { + return Branch.lookup(this, this._branch); } /** * Returns the repository's commits * - * @param [count=20] - The number of commits to get + * @param [amount=20] - The number of commits to get or whether or not to get all commits * @returns An array of commit instances */ - public async commits(count?: number): Promise { - return Commit.getMultiple(this, count); + public async commits(amount?: number | boolean): Promise { + return Commit.getMultiple(this, amount); } /** @@ -118,6 +126,20 @@ export class Repository { .catch(() => false); } + /** + * Returns this repository instance with a different branch + * + * @param branch - The branch to switch to + * @returns An instance of a repository + */ + public async withBranch(branch: string): Promise { + if(!await Branch.lookupExists(this.ng_repository, branch)) { + throw(createError(ErrorWhere.Repository, NotFoundError, "branch")); + } + + return new Repository(this.ng_repository, branch); + } + /** * Returns the repository's branches * -- cgit v1.2.3-18-g5258