fix(git): bot commit 改用 comment token (PAT) 推送以重新觸發 workflow

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jeffery
2026-06-26 14:41:41 +08:00
co-authored by Claude Opus 4.8
parent ef8a0d61c8
commit fc10ab7266
2 changed files with 26 additions and 5 deletions
+12
View File
@@ -4,6 +4,7 @@ import fs from 'fs';
import os from 'os';
import path from 'path';
import { commitAndPush, cloneRepo, verifyRemoteAccess, BOT_COMMIT_MARKER, getHeadCommitMessage, isBotAutoCommit } from '../git.js';
import { GITEA_TOKEN, GITEA_COMMENT_TOKEN } from '../config.js';
// --- helpers ---
function makeTmpWorkspace() {
@@ -74,6 +75,17 @@ describe('commitAndPush', () => {
assert.ok(commitCall.args.some(arg => arg.includes('[failure]')), 'expected commit message to include failure outcome');
});
it('pushes with the comment-token (PAT) so the bot commit can re-trigger the workflow', async () => {
const spawn = makeSpawn();
await commitAndPush(workspace, path.join(workspace, 'repo'), spawn, sourceRoot);
// push 必須帶「優先 PAT」的 tokenGitea 才會為 bot commit 重新發出 synchronize 事件。
const expectedToken = GITEA_COMMENT_TOKEN || GITEA_TOKEN;
const pushCall = spawn.calls.find(c => c.args[0] === 'push');
assert.ok(pushCall, 'expected git push to run');
assert.equal(pushCall.opts?.env?.GIT_TOKEN, expectedToken, 'push must use GITEA_COMMENT_TOKEN (fallback GITEA_TOKEN)');
});
it('uses GIT_ASKPASS env for network operations (fetch, push, clone)', async () => {
const spawn = makeSpawn();
await commitAndPush(workspace, path.join(workspace, 'repo'), spawn, sourceRoot);