From 09ff261f156a8599d45c1496fe246ded6e035191 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 26 Jul 2021 23:56:53 +0200 Subject: Added backend TSDoc/JSDoc comments & refactored a tiny bit --- packages/server/src/git/commit.ts | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'packages/server/src/git/commit.ts') diff --git a/packages/server/src/git/commit.ts b/packages/server/src/git/commit.ts index 94afda0..c49e5ec 100644 --- a/packages/server/src/git/commit.ts +++ b/packages/server/src/git/commit.ts @@ -16,6 +16,9 @@ type DiffStats = { files_changed: number } +/** + * A representation of a commit + */ export class Commit { private _ng_commit: NodeGitCommit; private _owner: Repository; @@ -25,6 +28,10 @@ export class Commit { public date: number; public message: string; + /** + * @param owner - The repository which the commit is in + * @param commit - An instance of a Nodegit commit + */ constructor(owner: Repository, commit: NodeGitCommit) { this._ng_commit = commit; this._owner = owner; @@ -38,10 +45,20 @@ export class Commit { this.message = commit.message(); } + /** + * Returns the commit's diff + * + * @returns An instance of a diff + */ public async diff(): Promise { return new Diff((await this._ng_commit.getDiff())[0]); } + /** + * Returns the commit's stats + * + * @returns A diff stats instance + */ public async stats(): Promise { const stats = await (await this._ng_commit.getDiff())[0].getStats(); @@ -52,21 +69,46 @@ export class Commit { }; } + /** + * Returns the commit's tree + * + * @returns An instance of a tree + */ public async tree(): Promise { return new Tree(this._owner, await this._ng_commit.getTree()); } + /** + * Lookup a commit + * + * @param repository - The repository which the commit is in + * @param id - The SHA of a commit + * @returns An instance of a commit + */ public static async lookup(repository: Repository, id: string | NodeGitOid): Promise { const commit = await NodeGitCommit.lookup(repository.nodegitRepository, id instanceof NodeGitOid ? id : NodeGitOid.fromString(id)); return new Commit(repository, commit); } + /** + * Returns if an commit exists or not + * + * @param repository - The repository which the commit is in + * @param id - The sha of a commit + * @returns Whether or not the commit exists + */ public static lookupExists(repository: Repository, id: string): Promise { return NodeGitCommit.lookup(repository.nodegitRepository, NodeGitOid.fromString(id)) .then(() => true) .catch(() => false); } + /** + * Returns the master commit of a repository + * + * @param owner - A repository + * @returns An instance of a commit + */ public static async masterCommit(owner: Repository): Promise { return new Commit(owner, await owner.nodegitRepository.getMasterCommit()); } -- cgit v1.2.3-18-g5258