T3: collector 骨架——watch→轉檔→git commit/push(design §4)
Node 單檔服務(非 arcrun workflow,跑客戶端機器):chokidar watch 事件驅動、debounce 合併批次 commit、.md passthrough(非 md 格式誠實丟 NotImplemented 待 T4 Markitdown)、 刪檔→target repo 移除對應檔(deprecated 標記留給 ingest workflow,collector 只管檔案鏡像)。 已驗(雲端 sandbox scratch 環境,非真實客戶環境):node --check 全過;起 scratch watch dir + scratch git repo + bare remote,實測 add/change/delete 三種事件皆正確偵測、debounce 正確 合併成一次 commit、git push 真的送達 remote(git log 驗證)、非 md 格式正確跳過並警告。 端到端待本機/客戶環境驗(README.md 已列):真實 NAS/VM watch、真實 Gitea remote+憑證、 Gitea push webhook 真觸發 ingest、systemd 常駐穩定性。
This commit is contained in:
+41
@@ -0,0 +1,41 @@
|
||||
const { execFileSync } = require('child_process');
|
||||
|
||||
/**
|
||||
* target repo 的 git add/commit/push 封裝(design.md §4:git commit/push 觸發既有
|
||||
* Gitea push webhook → ingest workflow;本模組不打任何 ingest HTTP 端點)。
|
||||
*/
|
||||
class GitSync {
|
||||
constructor(config) {
|
||||
this.repoDir = config.targetRepoDir;
|
||||
this.authorName = config.gitAuthorName;
|
||||
this.authorEmail = config.gitAuthorEmail;
|
||||
}
|
||||
|
||||
_git(args) {
|
||||
return execFileSync('git', args, {
|
||||
cwd: this.repoDir,
|
||||
env: {
|
||||
...process.env,
|
||||
GIT_AUTHOR_NAME: this.authorName,
|
||||
GIT_AUTHOR_EMAIL: this.authorEmail,
|
||||
GIT_COMMITTER_NAME: this.authorName,
|
||||
GIT_COMMITTER_EMAIL: this.authorEmail,
|
||||
},
|
||||
encoding: 'utf8',
|
||||
});
|
||||
}
|
||||
|
||||
/** 一批變更合併成一次 commit + push;無變更則不 commit(冪等,避免空 commit 洗歷史)。 */
|
||||
commitAndPush(summary) {
|
||||
this._git(['add', '-A']);
|
||||
const status = this._git(['status', '--porcelain']);
|
||||
if (!status.trim()) {
|
||||
return { committed: false };
|
||||
}
|
||||
this._git(['commit', '-m', summary]);
|
||||
this._git(['push']);
|
||||
return { committed: true };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { GitSync };
|
||||
Reference in New Issue
Block a user