Skip to content

Commit f79bcb8

Browse files
author
Amelia Wattenbeger
committed
push diagram to git
1 parent dd92607 commit f79bcb8

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
},
55
"dependencies": {
66
"@actions/core": "^1.4.0",
7+
"@actions/exec": "^1.1.0",
78
"d3": "^7.0.0",
89
"esbuild": "^0.12.15",
910
"lodash": "^4.17.21",

src/index.jsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { exec } from '@actions/exec'
12
import * as core from '@actions/core'
23
import React from 'react';
34
import ReactDOMServer from 'react-dom/server';
@@ -9,14 +10,52 @@ import { Tree } from "./Tree.tsx"
910
const main = async () => {
1011
core.info('[INFO] Usage https://github.com/githubocto/repo-visualizer#readme')
1112

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+
1224
const data = await processDir(`./`);
1325

1426
const componentCodeString = ReactDOMServer.renderToStaticMarkup(<Tree data={data} />);
1527

1628
const outputFile = core.getInput("output_file") || "./diagram.svg"
1729

1830
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+
1942
console.log("All set!")
2043
}
2144

2245
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+

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.4.0.tgz#cf2e6ee317e314b03886adfeb20e448d50d6e524"
88
integrity sha512-CGx2ilGq5i7zSLgiiGUtBCxhRRxibJYU6Fim0Q1Wg2aQL2LTnF27zbqZOrxfvFQ55eSBW0L8uVStgtKMpa0Qlg==
99

10+
"@actions/exec@^1.1.0":
11+
version "1.1.0"
12+
resolved "https://registry.yarnpkg.com/@actions/exec/-/exec-1.1.0.tgz#53441d968e56d2fec69ad3f15773d4d94e01162c"
13+
integrity sha512-LImpN9AY0J1R1mEYJjVJfSZWU4zYOlEcwSTgPve1rFQqK5AwrEs6uWW5Rv70gbDIQIAUwI86z6B+9mPK4w9Sbg==
14+
dependencies:
15+
"@actions/io" "^1.0.1"
16+
17+
"@actions/io@^1.0.1":
18+
version "1.1.1"
19+
resolved "https://registry.yarnpkg.com/@actions/io/-/io-1.1.1.tgz#4a157406309e212ab27ed3ae30e8c1d641686a66"
20+
integrity sha512-Qi4JoKXjmE0O67wAOH6y0n26QXhMKMFo7GD/4IXNVcrtLjUlGjGuVys6pQgwF3ArfGTQu0XpqaNr0YhED2RaRA==
21+
1022
commander@7:
1123
version "7.2.0"
1224
resolved "https://registry.yarnpkg.com/commander/-/commander-7.2.0.tgz#a36cb57d0b501ce108e4d20559a150a391d97ab7"

0 commit comments

Comments
 (0)