1
+ import { exec } from '@actions/exec'
1
2
import * as core from '@actions/core'
2
3
import React from 'react' ;
3
4
import ReactDOMServer from 'react-dom/server' ;
@@ -9,14 +10,52 @@ import { Tree } from "./Tree.tsx"
9
10
const main = async ( ) => {
10
11
core . info ( '[INFO] Usage https://github.com/githubocto/repo-visualizer#readme' )
11
12
13
+ core . startGroup ( 'Configuration' )
14
+ const username = 'repo-visualizer'
15
+ await exec ( 'git' , [ 'config' , 'user.name' , username ] )
16
+ await exec ( 'git' , [
17
+ 'config' ,
18
+ 'user.email' ,
19
+ // `${username}@users .noreply.github.com`,
20
+
21
+ ] )
22
+ core . endGroup ( )
23
+
12
24
const data = await processDir ( `./` ) ;
13
25
14
26
const componentCodeString = ReactDOMServer . renderToStaticMarkup ( < Tree data = { data } /> ) ;
15
27
16
28
const outputFile = core . getInput ( "output_file" ) || "./diagram.svg"
17
29
18
30
await fs . writeFileSync ( outputFile , componentCodeString )
31
+
32
+ await exec ( 'git' , [ 'add' , outputFile ] )
33
+ const diff = await execWithOutput ( 'git' , [ 'diff' , '--exit-code' , outputFile ] )
34
+ if ( ! diff ) {
35
+ core . info ( '[INFO] No changes to the repo detected, exiting' )
36
+ return
37
+ }
38
+
39
+ exec ( 'git' , [ 'commit' , '-m' , "Repo visualizer: updated diagram" ] )
40
+ await exec ( 'git' , [ 'push' ] )
41
+
19
42
console . log ( "All set!" )
20
43
}
21
44
22
45
main ( )
46
+
47
+ function execWithOutput ( command , options ) {
48
+ return new Promise ( function ( resolve , reject ) {
49
+ exec ( command , {
50
+ listeners : {
51
+ stdout : function ( data ) {
52
+ resolve ( stdout )
53
+ } ,
54
+ stderr : function ( data ) {
55
+ reject ( stderr )
56
+ }
57
+ }
58
+ } , options )
59
+ } )
60
+ }
61
+
0 commit comments