-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcommit.ts
More file actions
34 lines (30 loc) · 785 Bytes
/
commit.ts
File metadata and controls
34 lines (30 loc) · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import Resource from "./resource";
import { Repo } from "./repo";
import { Tree } from "./tree";
export class Commit extends Resource {
sha: string;
constructor(
readonly repo: Repo,
readonly tree: Tree,
readonly message: string,
readonly parents: string[]
) {
super();
}
async save(): Promise<void> {
// Save the tree first
await this.tree.save();
// Save the commit
// Via: POST https://api.github.com/repos/$GITHUB_REPOSITORY/git/commits
const response = await this.github.post(
`/repos/${this.repo.nameWithOwner}/git/commits`,
{
message: this.message,
tree: this.tree.sha,
parents: this.parents,
},
);
this.sha = response.data.sha;
this.debug(`Commit: ${this.sha}`);
}
}