@@ -11,23 +11,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
1111 return ( mod && mod . __esModule ) ? mod : { "default" : mod } ;
1212} ;
1313Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
14- // import fs from 'fs' ;
15- // import path from ' path' ;
14+ const fs_1 = __importDefault ( require ( "fs" ) ) ;
15+ const path_1 = __importDefault ( require ( " path" ) ) ;
1616const signale_1 = __importDefault ( require ( "signale" ) ) ;
17- // import {getCommitMessage, getWorkspace} from ' ./misc' ;
18- const command_1 = require ( " ./command" ) ;
17+ const misc_1 = require ( " ./misc" ) ;
18+ // import {commit} from ' ./command' ;
1919exports . push = ( files , name , octokit , context ) => __awaiter ( this , void 0 , void 0 , function * ( ) {
20- // const commit = await createCommit(files, octokit, context);
21- // await updateRef(commit.data.sha, name, octokit, context);
22- yield updateRef ( yield command_1 . commit ( ) , name , octokit , context ) ;
20+ const commit = yield createCommit ( files , octokit , context ) ;
21+ yield updateRef ( commit . data . sha , name , octokit , context ) ;
22+ // await updateRef(await commit(), name, octokit, context);
23+ } ) ;
24+ const getCommit = ( octokit , context ) => __awaiter ( this , void 0 , void 0 , function * ( ) {
25+ return yield octokit . git . getCommit ( {
26+ owner : context . repo . owner ,
27+ repo : context . repo . repo ,
28+ commit_sha : context . sha ,
29+ } ) ;
2330} ) ;
24- // const getCommit = async (octokit: GitHub, context: Context) => {
25- // return await octokit.git.getCommit({
26- // owner: context.repo.owner,
27- // repo: context.repo.repo,
28- // commit_sha: context.sha,
29- // });
30- // };
3131const existsRef = ( name , octokit , context ) => {
3232 return new Promise ( resolve => {
3333 octokit . git . getRef ( {
@@ -42,17 +42,17 @@ const existsRef = (name, octokit, context) => {
4242 } ) ;
4343} ;
4444const getRef = ( name ) => `refs/heads/${ name } ` ;
45- // const createBlob = async (filePath: string , octokit: GitHub , context: Context ) => {
46- // const file = path. resolve(getWorkspace(), filePath);
47- // const isExists = fs .existsSync(file);
48- // const blob = await octokit.git.createBlob({
49- // owner: context.repo.owner,
50- // repo: context.repo.repo,
51- // content: isExists ? Buffer.from(fs .readFileSync(file)).toString('base64') : '',
52- // encoding: 'base64',
53- // });
54- // return ({path: filePath, sha: blob.data.sha});
55- // } ;
45+ const createBlob = ( filePath , octokit , context ) => __awaiter ( this , void 0 , void 0 , function * ( ) {
46+ const file = path_1 . default . resolve ( misc_1 . getWorkspace ( ) , filePath ) ;
47+ const isExists = fs_1 . default . existsSync ( file ) ;
48+ const blob = yield octokit . git . createBlob ( {
49+ owner : context . repo . owner ,
50+ repo : context . repo . repo ,
51+ content : isExists ? Buffer . from ( fs_1 . default . readFileSync ( file ) ) . toString ( 'base64' ) : '' ,
52+ encoding : 'base64' ,
53+ } ) ;
54+ return ( { path : filePath , sha : blob . data . sha } ) ;
55+ } ) ;
5656const createRef = ( name , octokit , context ) => __awaiter ( this , void 0 , void 0 , function * ( ) {
5757 signale_1 . default . info ( `Create Ref: ${ name } ` ) ;
5858 yield octokit . git . createRef ( {
@@ -62,35 +62,33 @@ const createRef = (name, octokit, context) => __awaiter(this, void 0, void 0, fu
6262 sha : context . sha ,
6363 } ) ;
6464} ) ;
65- // const filesToBlobs = async (files: object, octokit: GitHub, context: Context) => Object.values(files).map(async file => await createBlob(file, octokit, context));
66- //
67- // const createTree = async (blobs: object, octokit: GitHub, context: Context) => {
68- // signale.info('Create Tree');
69- // return await octokit.git.createTree({
70- // owner: context.repo.owner,
71- // repo: context.repo.repo,
72- // base_tree: (await getCommit(octokit, context)).data.tree.sha,
73- // tree: Object.values(blobs).map(blob => ({
74- // path: blob.path,
75- // type: 'blob',
76- // mode: '100644',
77- // sha: blob.sha,
78- // })),
79- // });
80- // };
81- //
82- // const createCommit = async (files: object, octokit: GitHub, context: Context) => {
83- // const blobs = await filesToBlobs(files, octokit, context);
84- // const tree = await createTree(blobs, octokit, context);
85- // signale.info('Create Commit');
86- // return await octokit.git.createCommit({
87- // owner: context.repo.owner,
88- // repo: context.repo.repo,
89- // tree: tree.data.sha,
90- // parents: [context.sha],
91- // message: getCommitMessage(),
92- // });
93- // };
65+ const filesToBlobs = ( files , octokit , context ) => __awaiter ( this , void 0 , void 0 , function * ( ) { return Object . values ( files ) . map ( ( file ) => __awaiter ( this , void 0 , void 0 , function * ( ) { return yield createBlob ( file , octokit , context ) ; } ) ) ; } ) ;
66+ const createTree = ( blobs , octokit , context ) => __awaiter ( this , void 0 , void 0 , function * ( ) {
67+ signale_1 . default . info ( 'Create Tree' ) ;
68+ return yield octokit . git . createTree ( {
69+ owner : context . repo . owner ,
70+ repo : context . repo . repo ,
71+ base_tree : ( yield getCommit ( octokit , context ) ) . data . tree . sha ,
72+ tree : Object . values ( blobs ) . map ( blob => ( {
73+ path : blob . path ,
74+ type : 'blob' ,
75+ mode : '100644' ,
76+ sha : blob . sha ,
77+ } ) ) ,
78+ } ) ;
79+ } ) ;
80+ const createCommit = ( files , octokit , context ) => __awaiter ( this , void 0 , void 0 , function * ( ) {
81+ const blobs = yield filesToBlobs ( files , octokit , context ) ;
82+ const tree = yield createTree ( blobs , octokit , context ) ;
83+ signale_1 . default . info ( 'Create Commit' ) ;
84+ return yield octokit . git . createCommit ( {
85+ owner : context . repo . owner ,
86+ repo : context . repo . repo ,
87+ tree : tree . data . sha ,
88+ parents : [ context . sha ] ,
89+ message : misc_1 . getCommitMessage ( ) ,
90+ } ) ;
91+ } ) ;
9492const updateRef = ( commit , name , octokit , context ) => __awaiter ( this , void 0 , void 0 , function * ( ) {
9593 if ( ! ( yield existsRef ( name , octokit , context ) ) ) {
9694 yield createRef ( name , octokit , context ) ;
0 commit comments