@@ -9,16 +9,29 @@ const {
99 checkIfBranchExists,
1010} = require ( "./index" ) ;
1111
12+ const commitCommand = "commit" ;
13+ const branchCommand = "branch"
14+
1215const appendLineToFile = ( filename , line ) => {
1316 fs . appendFile ( filename , `${ line } \n` , function ( err ) {
1417 if ( err ) throw err ;
1518 console . log ( `Saved data to ${ filename } .` ) ;
1619 } ) ;
1720} ;
1821
22+ const writeResultToGithubOutputFile = ( results ) => {
23+ if ( ! ! process . env . GITHUB_OUTPUT ) {
24+ let line = "" ;
25+ results . forEach ( ( result ) => {
26+ line += `${ result . label } =${ result . value } \n` ;
27+ } ) ;
28+ appendLineToFile ( process . env . GITHUB_OUTPUT , line ) ;
29+ }
30+ } ;
31+
1932yargs
2033 . command (
21- "commit" ,
34+ commitCommand ,
2235 "Create a commit on a branch" ,
2336 ( yargs ) => {
2437 yargs
@@ -92,20 +105,24 @@ yargs
92105 )
93106 . then ( ( response ) => {
94107 console . log ( `Commit created: ${ response . commitUrl } ` ) ;
95- if ( ! ! process . env . GITHUB_OUTPUT ) {
96- appendLineToFile (
97- process . env . GITHUB_OUTPUT ,
98- `commitUrl=${ response . commitUrl } `
99- ) ;
100- }
108+ writeResultToGithubOutputFile ( [
109+ {
110+ label : "command" ,
111+ value : commitCommand ,
112+ } ,
113+ {
114+ label : "commitUrl" ,
115+ value : response . commitUrl ,
116+ } ,
117+ ] ) ;
101118 } )
102119 . catch ( ( error ) => {
103120 console . error ( "Failed to create commit:" , error . message ) ;
104121 } ) ;
105122 }
106123 )
107124 . command (
108- "branch" ,
125+ branchCommand ,
109126 "Check if a branch exists" ,
110127 ( yargs ) => {
111128 yargs
@@ -137,6 +154,16 @@ yargs
137154 console . log (
138155 `Repository ${ owner } /${ repo } has ${ n } branch named '${ branch } '`
139156 ) ;
157+ writeResultToGithubOutputFile ( [
158+ {
159+ label : "command" ,
160+ value : branchCommand ,
161+ } ,
162+ {
163+ label : "hasBranch" ,
164+ value : n . toString ( ) ,
165+ } ,
166+ ] ) ;
140167 } )
141168 . catch ( ( error ) => {
142169 console . error ( "Failed to check if branch exists:" , error . message ) ;
0 commit comments