Skip to content

Commit 41a86a1

Browse files
authored
Merge pull request #195 from ProverCoderAI/issue-192
chore: add git status to session backup comment
2 parents ea0c2d2 + df905af commit 41a86a1

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

scripts/session-backup-gist.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,29 @@ const execCommand = (command, options = {}) => {
139139
}
140140
};
141141

142+
const getGitStatus = () => {
143+
const status = execCommand("git status");
144+
if (status === null) {
145+
return null;
146+
}
147+
if (!status) {
148+
return "clean";
149+
}
150+
return status;
151+
};
152+
153+
const printGitStatus = (status) => {
154+
console.log("[session-backup] git status:");
155+
if (status === null) {
156+
console.log("[session-backup] (unavailable)");
157+
return;
158+
}
159+
160+
for (const line of status.split("\n")) {
161+
console.log(`[session-backup] ${line}`);
162+
}
163+
};
164+
142165
const ghCommand = (args, ghEnv) => {
143166
const result = spawnSync("gh", args, {
144167
encoding: "utf8",
@@ -423,12 +446,18 @@ const buildSnapshotReadme = ({ backupRepo, source, manifestUrl, summary, session
423446
"",
424447
].join("\n");
425448

426-
const buildCommentBody = ({ source, manifestUrl, readmeUrl, summary }) => {
449+
const buildCommentBody = ({ source, manifestUrl, readmeUrl, summary, gitStatus }) => {
450+
const statusText = gitStatus === null ? "(unavailable)" : gitStatus;
427451
const lines = [
428452
"## AI Session Backup",
429453
`Commit: ${source.commitSha}`,
430454
`Files: ${summary.fileCount} (${formatBytes(summary.totalBytes)})`,
431455
`Links: [README](${readmeUrl}) | [Manifest](${manifestUrl})`,
456+
"",
457+
"`git status`",
458+
"```",
459+
statusText,
460+
"```",
432461
];
433462

434463
lines.push(`<!-- docker-git-session-backup:${source.commitSha}:${source.createdAt} -->`);
@@ -556,6 +585,7 @@ const main = () => {
556585
const manifestUrl = buildBlobUrl(backupRepo.fullName, backupRepo.defaultBranch, `${snapshotRef}/manifest.json`);
557586
const readmeRepoPath = `${snapshotRef}/README.md`;
558587
const readmeUrl = buildBlobUrl(backupRepo.fullName, backupRepo.defaultBranch, readmeRepoPath);
588+
const gitStatus = getGitStatus();
559589

560590
const manifest = buildManifest({
561591
backupRepo,
@@ -589,12 +619,13 @@ const main = () => {
589619
console.log(
590620
`[session-backup] dry-run: ${source.commitSha.slice(0, 12)} (${summary.fileCount} files, ${formatBytes(summary.totalBytes)})`
591621
);
622+
printGitStatus(gitStatus);
592623
log(verbose, `[dry-run] Upload target: ${backupRepo.fullName}:${snapshotRef}`);
593624
log(verbose, `[dry-run] README URL: ${readmeUrl}`);
594625
log(verbose, `[dry-run] Manifest URL: ${manifestUrl}`);
595626
if (args.postComment && prContext !== null) {
596627
log(verbose, `Would post comment to PR #${prContext.prNumber} in ${prContext.repo}:`);
597-
log(verbose, buildCommentBody({ source, manifestUrl, readmeUrl, summary }));
628+
log(verbose, buildCommentBody({ source, manifestUrl, readmeUrl, summary, gitStatus }));
598629
}
599630
return;
600631
}
@@ -611,6 +642,7 @@ const main = () => {
611642
console.log(
612643
`[session-backup] ok: ${source.commitSha.slice(0, 12)} (${summary.fileCount} files, ${formatBytes(summary.totalBytes)})`
613644
);
645+
printGitStatus(gitStatus);
614646
log(verbose, `[session-backup] Uploaded snapshot to ${backupRepo.fullName}:${snapshotRef}`);
615647
log(verbose, `[session-backup] Manifest: ${uploadResult.manifestUrl}`);
616648

@@ -620,6 +652,7 @@ const main = () => {
620652
manifestUrl: uploadResult.manifestUrl,
621653
readmeUrl,
622654
summary,
655+
gitStatus,
623656
});
624657
postPrComment(prContext.repo, prContext.prNumber, comment, verbose, ghEnv);
625658
}

0 commit comments

Comments
 (0)