Skip to content

Commit 7f6440e

Browse files
author
Amelia Wattenbeger
committed
switch back to git
1 parent d8acf17 commit 7f6440e

File tree

2 files changed

+73
-46
lines changed

2 files changed

+73
-46
lines changed

index.js

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19515,28 +19515,52 @@ var getSortOrder = (item, cachedOrders, i = 0) => {
1951519515
var main = async () => {
1951619516
core.info("[INFO] Usage https://github.com/githubocto/repo-visualizer#readme");
1951719517
core.startGroup("Configuration");
19518-
const myToken = core.getInput("github_token");
19519-
const octokit = import_github.default.getOctokit(myToken);
19520-
const context = import_github.default.context;
19521-
const repo = context.repo;
19518+
const username = "repo-visualizer";
19519+
await (0, import_exec.exec)("git", ["config", "user.name", username]);
19520+
await (0, import_exec.exec)("git", [
19521+
"config",
19522+
"user.email",
19523+
19524+
]);
1952219525
core.endGroup();
1952319526
const data = await processDir(`./`);
1952419527
const componentCodeString = import_server.default.renderToStaticMarkup(/* @__PURE__ */ import_react3.default.createElement(Tree, {
1952519528
data
1952619529
}));
1952719530
const outputFile = core.getInput("output_file") || "./diagram.svg";
19528-
await octokit.repo.updateFile({
19529-
owner: repo.owner.login,
19530-
repo: repo.name,
19531-
path: outputFile,
19532-
content: componentCodeString,
19533-
sha: context.sha,
19534-
message: "Repo visualizer: updated diagram",
19535-
branch: context.branch
19536-
});
19531+
await import_fs2.default.writeFileSync(outputFile, componentCodeString);
19532+
await (0, import_exec.exec)("git", ["add", outputFile]);
19533+
const diff = await execWithOutput("git", ["status", "--porcelain", outputFile]);
19534+
core.info(`diff: ${diff}`);
19535+
if (!diff) {
19536+
core.info("[INFO] No changes to the repo detected, exiting");
19537+
return;
19538+
}
19539+
(0, import_exec.exec)("git", ["commit", "-m", "Repo visualizer: updated diagram"]);
19540+
await (0, import_exec.exec)("git", ["push"]);
1953719541
console.log("All set!");
1953819542
};
1953919543
main();
19544+
function execWithOutput(command, args) {
19545+
return new Promise((resolve, reject) => {
19546+
try {
19547+
(0, import_exec.exec)(command, args, {
19548+
listeners: {
19549+
stdout: function(res) {
19550+
core.info(res.toString());
19551+
resolve(res.toString());
19552+
},
19553+
stderr: function(res) {
19554+
core.info(res.toString());
19555+
reject(res.toString());
19556+
}
19557+
}
19558+
});
19559+
} catch (e) {
19560+
reject(e);
19561+
}
19562+
});
19563+
}
1954019564
/*
1954119565
object-assign
1954219566
(c) Sindre Sorhus

src/index.jsx

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ const main = async () => {
1212
core.info('[INFO] Usage https://github.com/githubocto/repo-visualizer#readme')
1313

1414
core.startGroup('Configuration')
15-
const myToken = core.getInput('github_token');
16-
const octokit = github.getOctokit(myToken)
17-
const context = github.context;
18-
const repo = context.repo;
19-
20-
// const username = 'repo-visualizer'
21-
// await exec('git', ['config', 'user.name', username])
22-
// await exec('git', [
23-
// 'config',
24-
// 'user.email',
25-
// // `${username}@users.noreply.github.com`,
26-
27-
// ])
15+
// const myToken = core.getInput('github_token');
16+
// const octokit = github.getOctokit(myToken)
17+
// const context = github.context;
18+
// const repo = context.repo;
19+
20+
const username = 'repo-visualizer'
21+
await exec('git', ['config', 'user.name', username])
22+
await exec('git', [
23+
'config',
24+
'user.email',
25+
// `${username}@users.noreply.github.com`,
26+
27+
])
2828

2929
core.endGroup()
3030

@@ -35,31 +35,34 @@ const main = async () => {
3535

3636
const outputFile = core.getInput("output_file") || "./diagram.svg"
3737

38-
// await fs.writeFileSync(outputFile, componentCodeString)
38+
//
39+
40+
await fs.writeFileSync(outputFile, componentCodeString)
3941

4042

4143
// add outputFile to git
4244
// await execWithOutput('git', ['add', outputFile])
4345

44-
await octokit.repo.updateFile({
45-
owner: repo.owner.login,
46-
repo: repo.name,
47-
path: outputFile,
48-
content: componentCodeString,
49-
sha: context.sha,
50-
message: 'Repo visualizer: updated diagram',
51-
branch: context.branch
52-
})
53-
// await exec('git', ['add', outputFile])
54-
// const diff = await execWithOutput('git', ['status', '--porcelain', outputFile])
55-
// core.info(`diff: ${diff}`)
56-
// if (!diff) {
57-
// core.info('[INFO] No changes to the repo detected, exiting')
58-
// return
59-
// }
60-
61-
// exec('git', ['commit', '-m', "Repo visualizer: updated diagram"])
62-
// await exec('git', ['push'])
46+
// await octokit.rest.git.createCommit
47+
// repo.updateFile({
48+
// owner: repo.owner.login,
49+
// repo: repo.name,
50+
// path: outputFile,
51+
// content: componentCodeString,
52+
// sha: context.sha,
53+
// message: 'Repo visualizer: updated diagram',
54+
// branch: context.branch
55+
// })
56+
await exec('git', ['add', outputFile])
57+
const diff = await execWithOutput('git', ['status', '--porcelain', outputFile])
58+
core.info(`diff: ${diff}`)
59+
if (!diff) {
60+
core.info('[INFO] No changes to the repo detected, exiting')
61+
return
62+
}
63+
64+
exec('git', ['commit', '-m', "Repo visualizer: updated diagram"])
65+
await exec('git', ['push'])
6366

6467
console.log("All set!")
6568
}

0 commit comments

Comments
 (0)