Skip to content

Commit fef5099

Browse files
Merge pull request #8 from technote-space/release/v0.0.5
Release/v0.0.5
2 parents 93d8dfe + 5b05af1 commit fef5099

File tree

1 file changed

+53
-53
lines changed

1 file changed

+53
-53
lines changed

src/utils/github.ts

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import fs from 'fs';
2-
import path from 'path';
1+
// import fs from 'fs';
2+
// import path from 'path';
33
import signale from 'signale';
44
import {GitHub} from '@actions/github/lib/github';
55
import {Context} from '@actions/github/lib/context';
6-
import {getCommitMessage, getWorkspace} from './misc';
6+
// import {getCommitMessage, getWorkspace} from './misc';
77
import {commit} from './command';
88

99
export const push = async (files: object, name: string, octokit: GitHub, context: Context) => {
@@ -12,13 +12,13 @@ export const push = async (files: object, name: string, octokit: GitHub, context
1212
await updateRef(await commit(), name, octokit, context);
1313
};
1414

15-
const getCommit = async (octokit: GitHub, context: Context) => {
16-
return await octokit.git.getCommit({
17-
owner: context.repo.owner,
18-
repo: context.repo.repo,
19-
commit_sha: context.sha,
20-
});
21-
};
15+
// const getCommit = async (octokit: GitHub, context: Context) => {
16+
// return await octokit.git.getCommit({
17+
// owner: context.repo.owner,
18+
// repo: context.repo.repo,
19+
// commit_sha: context.sha,
20+
// });
21+
// };
2222

2323
const existsRef = (name: string, octokit: GitHub, context: Context) => {
2424
return new Promise<boolean>(resolve => {
@@ -36,20 +36,20 @@ const existsRef = (name: string, octokit: GitHub, context: Context) => {
3636

3737
const getRef = (name: string) => `refs/heads/${name}`;
3838

39-
const createBlob = async (filePath: string, octokit: GitHub, context: Context) => {
40-
const file = path.resolve(getWorkspace(), filePath);
41-
const isExists = fs.existsSync(file);
42-
const blob = await octokit.git.createBlob({
43-
owner: context.repo.owner,
44-
repo: context.repo.repo,
45-
content: isExists ? Buffer.from(fs.readFileSync(file)).toString('base64') : '',
46-
encoding: 'base64',
47-
});
48-
return ({path: filePath, sha: blob.data.sha});
49-
};
39+
// const createBlob = async (filePath: string, octokit: GitHub, context: Context) => {
40+
// const file = path.resolve(getWorkspace(), filePath);
41+
// const isExists = fs.existsSync(file);
42+
// const blob = await octokit.git.createBlob({
43+
// owner: context.repo.owner,
44+
// repo: context.repo.repo,
45+
// content: isExists ? Buffer.from(fs.readFileSync(file)).toString('base64') : '',
46+
// encoding: 'base64',
47+
// });
48+
// return ({path: filePath, sha: blob.data.sha});
49+
// };
5050

5151
const createRef = async (name: string, octokit: GitHub, context: Context) => {
52-
signale.info('Create Ref');
52+
signale.info(`Create Ref: ${name}`);
5353
await octokit.git.createRef({
5454
owner: context.repo.owner,
5555
repo: context.repo.repo,
@@ -58,46 +58,46 @@ const createRef = async (name: string, octokit: GitHub, context: Context) => {
5858
});
5959
};
6060

61-
const filesToBlobs = async (files: object, octokit: GitHub, context: Context) => Object.values(files).map(async file => await createBlob(file, octokit, context));
62-
63-
const createTree = async (blobs: object, octokit: GitHub, context: Context) => {
64-
signale.info('Create Tree');
65-
return await octokit.git.createTree({
66-
owner: context.repo.owner,
67-
repo: context.repo.repo,
68-
base_tree: (await getCommit(octokit, context)).data.tree.sha,
69-
tree: Object.values(blobs).map(blob => ({
70-
path: blob.path,
71-
type: 'blob',
72-
mode: '100644',
73-
sha: blob.sha,
74-
})),
75-
});
76-
};
77-
78-
const createCommit = async (files: object, octokit: GitHub, context: Context) => {
79-
const blobs = await filesToBlobs(files, octokit, context);
80-
const tree = await createTree(blobs, octokit, context);
81-
signale.info('Create Commit');
82-
return await octokit.git.createCommit({
83-
owner: context.repo.owner,
84-
repo: context.repo.repo,
85-
tree: tree.data.sha,
86-
parents: [context.sha],
87-
message: getCommitMessage(),
88-
});
89-
};
61+
// const filesToBlobs = async (files: object, octokit: GitHub, context: Context) => Object.values(files).map(async file => await createBlob(file, octokit, context));
62+
//
63+
// const createTree = async (blobs: object, octokit: GitHub, context: Context) => {
64+
// signale.info('Create Tree');
65+
// return await octokit.git.createTree({
66+
// owner: context.repo.owner,
67+
// repo: context.repo.repo,
68+
// base_tree: (await getCommit(octokit, context)).data.tree.sha,
69+
// tree: Object.values(blobs).map(blob => ({
70+
// path: blob.path,
71+
// type: 'blob',
72+
// mode: '100644',
73+
// sha: blob.sha,
74+
// })),
75+
// });
76+
// };
77+
//
78+
// const createCommit = async (files: object, octokit: GitHub, context: Context) => {
79+
// const blobs = await filesToBlobs(files, octokit, context);
80+
// const tree = await createTree(blobs, octokit, context);
81+
// signale.info('Create Commit');
82+
// return await octokit.git.createCommit({
83+
// owner: context.repo.owner,
84+
// repo: context.repo.repo,
85+
// tree: tree.data.sha,
86+
// parents: [context.sha],
87+
// message: getCommitMessage(),
88+
// });
89+
// };
9090

9191
const updateRef = async (commit: string, name: string, octokit: GitHub, context: Context) => {
9292
if (!await existsRef(name, octokit, context)) {
9393
await createRef(name, octokit, context);
9494
}
9595

96-
signale.info('Update Ref');
96+
signale.info(`Update Ref: ${commit}`);
9797
await octokit.git.updateRef({
9898
owner: context.repo.owner,
9999
repo: context.repo.repo,
100100
ref: getRef(name),
101-
sha: commit,
101+
sha: commit.trim(),
102102
});
103103
};

0 commit comments

Comments
 (0)