Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromswinton/commit

Commit6f45116

Browse files
committed
Create commit
1 parent97a05ff commit6f45116

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

‎index.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Repo } from "./lib/repo";
55
import{Ref}from"./lib/ref";
66
import{getBlobsFromFiles}from"./lib/blob";
77
import{Tree}from"./lib/tree";
8+
import{Commit}from"./lib/commit";
89

910
exportdefaultasyncfunctionrun():Promise<void>{
1011
try{
@@ -36,11 +37,15 @@ export default async function run(): Promise<void> {
3637

3738
// Create a tree
3839
consttree:Tree=newTree(repo,blobs,ref.treeOid);
39-
awaittree.save();
4040

41-
// TODO
4241
// Create commit
43-
// Via: POST https://api.github.com/repos/$GITHUB_REPOSITORY/git/commits
42+
constcommit:Commit=newCommit(repo,tree,commitMessage,[
43+
ref.commitOid,
44+
]);
45+
awaitcommit.save();
46+
47+
// Set commit sha output
48+
core.setOutput("commit-sha",commit.sha);
4449

4550
// TODO
4651
// Update ref

‎lib/commit.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
importResourcefrom"./resource";
2+
import{Repo}from"./repo";
3+
import{Tree}from"./tree";
4+
5+
exportclassCommitextendsResource{
6+
sha:string;
7+
constructor(
8+
readonlyrepo:Repo,
9+
readonlytree:Tree,
10+
readonlymessage:string,
11+
readonlyparents:string[]
12+
){
13+
super();
14+
}
15+
16+
asyncsave():Promise<void>{
17+
// Save the tree first
18+
awaitthis.tree.save();
19+
20+
// Save the commit
21+
// Via: POST https://api.github.com/repos/$GITHUB_REPOSITORY/git/commits
22+
constresponse=awaitthis.github.post(
23+
`/repos/${this.repo.nameWithOwner}/git/commits`,
24+
{
25+
message:this.message,
26+
tree:this.tree.sha,
27+
parents:this.parents,
28+
}
29+
);
30+
31+
this.sha=response.data.sha;
32+
this.debug(`Commit:${this.sha}`);
33+
}
34+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp