🌉 bridge-app.js: 修复异步入口 + 提取常量

Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com>
Agent-Logs-Url: https://github.com/qinfendebingshuo/guanghulab/sessions/be54ebf1-0ab1-421d-9f24-e7cb76219d38
This commit is contained in:
copilot-swe-agent[bot] 2026-03-21 12:47:41 +00:00
parent a8e23f01f4
commit 01015dde7f
1 changed files with 19 additions and 12 deletions

View File

@ -8,6 +8,8 @@ const path = require('path');
const TOKEN = process.env.MAIN_REPO_TOKEN; const TOKEN = process.env.MAIN_REPO_TOKEN;
const ORG = process.env.GITHUB_ORG || 'qinfendebingshuo'; const ORG = process.env.GITHUB_ORG || 'qinfendebingshuo';
const COMMITTER = { name: '铸渊 (ZhùYuān)', email: 'zhuyuan@guanghulab.com' };
const BULLETIN_PATH = 'bulletins/latest.md';
// ========== 开发者仓库路由表 ========== // ========== 开发者仓库路由表 ==========
const FEDERATION = { const FEDERATION = {
@ -65,7 +67,7 @@ async function pushFile(repo, filePath, content, message) {
const body = { const body = {
message, message,
content: Buffer.from(content).toString('base64'), content: Buffer.from(content).toString('base64'),
committer: { name: '铸渊 (ZhùYuān)', email: 'zhuyuan@guanghulab.com' } committer: COMMITTER
}; };
if (sha) body.sha = sha; if (sha) body.sha = sha;
@ -76,12 +78,11 @@ async function pushFile(repo, filePath, content, message) {
// 1. 推送公告到所有仓库 // 1. 推送公告到所有仓库
async function pushBulletin() { async function pushBulletin() {
const bulletinPath = 'bulletins/latest.md'; if (!fs.existsSync(BULLETIN_PATH)) {
if (!fs.existsSync(bulletinPath)) {
console.log('📭 无 bulletins/latest.md'); console.log('📭 无 bulletins/latest.md');
return; return;
} }
const content = fs.readFileSync(bulletinPath, 'utf8'); const content = fs.readFileSync(BULLETIN_PATH, 'utf8');
const timestamp = new Date().toISOString().split('T')[0]; const timestamp = new Date().toISOString().split('T')[0];
for (const [devId, dev] of Object.entries(FEDERATION)) { for (const [devId, dev] of Object.entries(FEDERATION)) {
@ -189,12 +190,18 @@ async function distributeBroadcasts() {
} }
// ========== 入口 ========== // ========== 入口 ==========
const action = process.argv[2]; async function main() {
switch (action) { const action = process.argv[2];
case 'bulletin': pushBulletin(); break; switch (action) {
case 'init': initRepo(process.argv[3]); break; case 'bulletin': await pushBulletin(); break;
case 'init-all': (async () => { for (const id of Object.keys(FEDERATION)) await initRepo(id); })(); break; case 'init': await initRepo(process.argv[3]); break;
case 'status': collectStatus(); break; case 'init-all':
case 'distribute': distributeBroadcasts(); break; for (const id of Object.keys(FEDERATION)) await initRepo(id);
default: console.log('用法: node bridge-app.js [bulletin|init DEV-XXX|init-all|status|distribute]'); break;
case 'status': await collectStatus(); break;
case 'distribute': await distributeBroadcasts(); break;
default: console.log('用法: node bridge-app.js [bulletin|init DEV-XXX|init-all|status|distribute]');
}
} }
main().catch(e => { console.error('❌ 桥接执行失败:', e.message); process.exit(1); });