@@ -7,7 +7,7 @@ const microApp = require('@micro-app/core');
77const chalk = require ( 'chalk' ) . default ;
88const logger = microApp . logger ;
99
10- module . exports = args => {
10+ module . exports = isHook => {
1111 const microAppConfig = microApp . self ( ) ;
1212 if ( ! microAppConfig ) return ;
1313
@@ -24,10 +24,28 @@ module.exports = args => {
2424 }
2525 const gitPath = gitURL . replace ( / ^ g i t \+ / ig, '' ) . split ( '#' ) [ 0 ] ;
2626 const gitBranch = deployCfg . branch || gitURL . split ( '#' ) [ 1 ] || 'master' ;
27+ const gitMessage = deployCfg . message && ` | ${ deployCfg . message } ` || '' ;
2728
28- const currBranch = ( ( shelljs . exec ( 'git rev-parse --abbrev-ref HEAD' , { silent : true } ) || { } ) . stdout || '' ) . trim ( ) ;
29- const commitHash = ( ( shelljs . exec ( `git rev-parse origin/${ currBranch } ` , { silent : true } ) || { } ) . stdout || '' ) . trim ( ) ;
30- // const commitHash = ((shelljs.exec('git rev-parse --verify HEAD', { silent: true }) || {}).stdout || '').trim();
29+ const gitUser = deployCfg . user || { } ;
30+ if ( ! gitUser . name || typeof gitUser . name !== 'string' ) {
31+ gitUser . name = ( ( shelljs . exec ( 'git config user.name' , { silent : true } ) || { } ) . stdout || '' ) . trim ( ) ;
32+ }
33+ if ( ! gitUser . email || typeof gitUser . email !== 'string' ) {
34+ gitUser . email = ( ( shelljs . exec ( 'git config user.email' , { silent : true } ) || { } ) . stdout || '' ) . trim ( ) ;
35+ }
36+
37+ let commitHash = '' ;
38+ if ( isHook ) {
39+ commitHash = ( ( shelljs . exec ( 'git rev-parse --verify HEAD' , { silent : true } ) || { } ) . stdout || '' ) . trim ( ) ;
40+ } else {
41+ const currBranch = ( ( shelljs . exec ( 'git rev-parse --abbrev-ref HEAD' , { silent : true } ) || { } ) . stdout || '' ) . trim ( ) ;
42+ commitHash = ( ( shelljs . exec ( `git rev-parse origin/${ currBranch } ` , { silent : true } ) || { } ) . stdout || '' ) . trim ( ) ;
43+ }
44+
45+ if ( ! commitHash || typeof commitHash !== 'string' ) {
46+ logger . logo ( `${ chalk . yellow ( 'Not Found commit Hash!' ) } ` ) ;
47+ return ;
48+ }
3149
3250 const gitRoot = path . resolve ( microAppConfig . root , '.git' ) ;
3351 if ( fs . statSync ( gitRoot ) . isDirectory ( ) ) {
@@ -41,6 +59,8 @@ module.exports = args => {
4159 logger . logo ( `Deploy: ${ chalk . blueBright ( gitPath ) } ` ) ;
4260 logger . logo ( `Branch: ${ chalk . blueBright ( gitBranch ) } ` ) ;
4361 logger . logo ( `Hash: ${ chalk . blueBright ( commitHash ) } ` ) ;
62+ logger . logo ( `Name: ${ chalk . blueBright ( gitUser . name ) } ` ) ;
63+ logger . logo ( `Email: ${ chalk . blueBright ( gitUser . email ) } ` ) ;
4464 const result = shelljs . exec ( execStr , { silent : true } ) ;
4565 if ( result . code ) {
4666 logger . logo ( `${ result . code } : ${ chalk . yellow ( result . stderr . trim ( ) . split ( '\n' ) . reverse ( ) [ 0 ] ) } ` ) ;
@@ -70,8 +90,15 @@ module.exports = args => {
7090 }
7191 fs . writeFileSync ( path . resolve ( deployDir , 'package.json' ) , JSON . stringify ( pkg , null , 4 ) , 'utf8' ) ;
7292
93+ // git config
94+ if ( gitUser . name && typeof gitUser . name === 'string' ) {
95+ shelljs . exec ( `git config user.name ${ gitUser . name } ` , { silent : true , cwd : deployDir } ) ;
96+ }
97+ if ( gitUser . email && typeof gitUser . email === 'string' ) {
98+ shelljs . exec ( `git config user.email ${ gitUser . email } ` , { silent : true , cwd : deployDir } ) ;
99+ }
73100 // commit + push
74- const { code } = shelljs . exec ( `git commit -a -m "auto deploy ${ MICRO_APP_CONFIG_NAME } "` , { cwd : deployDir } ) ;
101+ const { code } = shelljs . exec ( `git commit -a -m ":package: auto deploy ${ MICRO_APP_CONFIG_NAME } - ${ commitHash . substr ( 0 , 8 ) } ${ gitMessage } "` , { cwd : deployDir } ) ;
75102 if ( code === 0 ) {
76103 const { code } = shelljs . exec ( 'git push' , { cwd : deployDir } ) ;
77104 if ( code === 0 ) {
0 commit comments