aboutsummaryrefslogtreecommitdiff
path: root/packages/server/src/git/commit.ts
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2021-07-26 23:56:53 +0200
committerHampusM <hampus@hampusmat.com>2021-07-26 23:56:53 +0200
commit09ff261f156a8599d45c1496fe246ded6e035191 (patch)
tree306f79709da372b562eca70d356fa25afcde1f95 /packages/server/src/git/commit.ts
parentc575df758b269db8e05c597d5870e948771d4c2b (diff)
Added backend TSDoc/JSDoc comments & refactored a tiny bit
Diffstat (limited to 'packages/server/src/git/commit.ts')
-rw-r--r--packages/server/src/git/commit.ts42
1 files changed, 42 insertions, 0 deletions
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<Diff> {
return new Diff((await this._ng_commit.getDiff())[0]);
}
+ /**
+ * Returns the commit's stats
+ *
+ * @returns A diff stats instance
+ */
public async stats(): Promise<DiffStats> {
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<Tree> {
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<Commit> {
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<boolean> {
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<Commit> {
return new Commit(owner, await owner.nodegitRepository.getMasterCommit());
}