1
- import fs from 'fs' ;
2
- import path from 'path' ;
1
+ // import fs from 'fs';
2
+ // import path from 'path';
3
3
import signale from 'signale' ;
4
4
import { GitHub } from '@actions/github/lib/github' ;
5
5
import { Context } from '@actions/github/lib/context' ;
6
- import { getCommitMessage , getWorkspace } from './misc' ;
6
+ // import {getCommitMessage, getWorkspace} from './misc';
7
7
import { commit } from './command' ;
8
8
9
9
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
12
12
await updateRef ( await commit ( ) , name , octokit , context ) ;
13
13
} ;
14
14
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
+ // };
22
22
23
23
const existsRef = ( name : string , octokit : GitHub , context : Context ) => {
24
24
return new Promise < boolean > ( resolve => {
@@ -36,20 +36,20 @@ const existsRef = (name: string, octokit: GitHub, context: Context) => {
36
36
37
37
const getRef = ( name : string ) => `refs/heads/${ name } ` ;
38
38
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
+ // };
50
50
51
51
const createRef = async ( name : string , octokit : GitHub , context : Context ) => {
52
- signale . info ( ' Create Ref' ) ;
52
+ signale . info ( ` Create Ref: ${ name } ` ) ;
53
53
await octokit . git . createRef ( {
54
54
owner : context . repo . owner ,
55
55
repo : context . repo . repo ,
@@ -58,46 +58,46 @@ const createRef = async (name: string, octokit: GitHub, context: Context) => {
58
58
} ) ;
59
59
} ;
60
60
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
+ // };
90
90
91
91
const updateRef = async ( commit : string , name : string , octokit : GitHub , context : Context ) => {
92
92
if ( ! await existsRef ( name , octokit , context ) ) {
93
93
await createRef ( name , octokit , context ) ;
94
94
}
95
95
96
- signale . info ( ' Update Ref' ) ;
96
+ signale . info ( ` Update Ref: ${ commit } ` ) ;
97
97
await octokit . git . updateRef ( {
98
98
owner : context . repo . owner ,
99
99
repo : context . repo . repo ,
100
100
ref : getRef ( name ) ,
101
- sha : commit ,
101
+ sha : commit . trim ( ) ,
102
102
} ) ;
103
103
} ;
0 commit comments