Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 91018b08f1 | |||
| 415bd1631f | |||
| c29f2a5f4a | |||
| 58dfe8750c | |||
| e0538abf25 | |||
| 795f85416d | |||
| 5ad13796b1 | |||
| ad953cd309 | |||
| dabb9a1512 | |||
| ff30981278 | |||
| 2ccab9871f | |||
| 9338584db6 | |||
| 64fb04cf36 |
+3
-69
@@ -238,47 +238,6 @@ function buildSyncManifest(featureCode, mappedFiles) {
|
||||
return JSON.stringify(manifest, null, 2);
|
||||
}
|
||||
|
||||
function checkGiteaPullRequestExists(baseBranch, headBranch) {
|
||||
const config = getSyncConfig();
|
||||
const path = '/repos/' + config.owner + '/' + config.repo + '/pulls?state=open';
|
||||
const res = giteaSyncRequest('GET', path, null);
|
||||
if (res.ok && res.data && Array.isArray(res.data)) {
|
||||
const existing = res.data.find(function(pr) {
|
||||
return pr.base && pr.head && pr.base.ref === baseBranch && pr.head.ref === headBranch;
|
||||
});
|
||||
if (existing) {
|
||||
return { ok: true, existed: true, data: existing };
|
||||
}
|
||||
return { ok: true, existed: false };
|
||||
}
|
||||
return { ok: false, existed: false, message: res.message || 'Failed to check existing PRs' };
|
||||
}
|
||||
|
||||
function createGiteaPullRequest(title, body, baseBranch, headBranch) {
|
||||
const config = getSyncConfig();
|
||||
|
||||
const checkRes = checkGiteaPullRequestExists(baseBranch, headBranch);
|
||||
if (checkRes.existed) {
|
||||
return { ok: true, existed: true, data: checkRes.data, message: 'Pull request already exists' };
|
||||
}
|
||||
if (!checkRes.ok) {
|
||||
return checkRes;
|
||||
}
|
||||
|
||||
const path = '/repos/' + config.owner + '/' + config.repo + '/pulls';
|
||||
const payload = {
|
||||
title: title,
|
||||
body: body,
|
||||
base: baseBranch,
|
||||
head: headBranch
|
||||
};
|
||||
const res = giteaSyncRequest('POST', path, payload);
|
||||
if (res.ok) {
|
||||
res.existed = false;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
function ensureGiteaBranch(baseBranch, newBranch) {
|
||||
const config = getSyncConfig();
|
||||
const checkRes = giteaSyncRequest('GET', '/repos/' + config.owner + '/' + config.repo + '/branches/' + newBranch, null);
|
||||
@@ -344,41 +303,16 @@ function syncAppsScriptToGiteaBranch(featureCode) {
|
||||
results.errors++;
|
||||
}
|
||||
|
||||
const prTitle = 'Sync Feature: ' + featureCode;
|
||||
const prBody = 'Automated sync from Google Apps Script for feature: ' + featureCode + '.\n\nFiles synced:\n' + payload.files.map(function(f) { return '- ' + f.repoPath; }).join('\n');
|
||||
const prRes = createGiteaPullRequest(prTitle, prBody, payload.baseBranch, payload.syncBranch);
|
||||
|
||||
let prInfo = null;
|
||||
if (prRes.ok) {
|
||||
prInfo = {
|
||||
url: prRes.data.html_url || '',
|
||||
existed: prRes.existed,
|
||||
number: prRes.data.number
|
||||
};
|
||||
}
|
||||
|
||||
console.log("Sync Summary: " + results.created + " created, " + results.updated + " updated, " + results.errors + " errors.");
|
||||
if (prInfo) {
|
||||
console.log("Pull Request: " + prInfo.url + (prInfo.existed ? " (Existed)" : " (Created)"));
|
||||
} else {
|
||||
console.log("Pull Request Failed: " + prRes.message);
|
||||
}
|
||||
|
||||
return { ok: true, branch: payload.syncBranch, summary: results, pullRequest: prInfo };
|
||||
return { ok: true, branch: payload.syncBranch, summary: results };
|
||||
}
|
||||
|
||||
function runManualSyncToGitea() {
|
||||
const res = syncAppsScriptToGiteaBranch('manual');
|
||||
if (res.ok) {
|
||||
console.log('=== Sync Summary ===');
|
||||
console.log('Branch Sync: ' + res.branch);
|
||||
console.log('Files: ' + res.summary.created + ' created, ' + res.summary.updated + ' updated, ' + res.summary.errors + ' errors.');
|
||||
if (res.pullRequest) {
|
||||
console.log('Pull Request Status: ' + (res.pullRequest.existed ? 'Existing' : 'Created'));
|
||||
console.log('Pull Request URL: ' + res.pullRequest.url);
|
||||
} else {
|
||||
console.log('Pull Request Status: Not available');
|
||||
}
|
||||
console.log('Sync successful to branch: ' + res.branch);
|
||||
console.log(JSON.stringify(res.summary, null, 2));
|
||||
} else {
|
||||
console.error('Sync failed: ' + res.message);
|
||||
}
|
||||
|
||||
@@ -623,18 +623,6 @@ function testSyncSummaryFormat() {
|
||||
assertTrue_('Summary has errors count', mockResults.errors === 0);
|
||||
assertEqual_('Summary details length is correct', mockResults.details.length, 3);
|
||||
|
||||
const mockFinalResult = {
|
||||
ok: true,
|
||||
branch: 'sync/manual',
|
||||
summary: mockResults,
|
||||
pullRequest: { url: 'https://gitea.example.com/pr/1', existed: true }
|
||||
};
|
||||
|
||||
assertTrue_('Final result has branch info', !!mockFinalResult.branch);
|
||||
assertTrue_('Final result has pullRequest info', !!mockFinalResult.pullRequest);
|
||||
assertTrue_('Final result pullRequest has url', !!mockFinalResult.pullRequest.url);
|
||||
assertEqual_('Final result pullRequest existed flag is true', mockFinalResult.pullRequest.existed, true);
|
||||
|
||||
console.log('--- Test Passed: Sync Summary Format ---');
|
||||
}
|
||||
function testGetAppsScriptProjectContentErrorFormat() {
|
||||
@@ -680,50 +668,6 @@ function testScriptIdFallback() {
|
||||
console.log('--- Test Passed: Script ID Fallback ---');
|
||||
}
|
||||
|
||||
function testGiteaPullRequestPayload() {
|
||||
console.log('--- Starting Test: Gitea Pull Request Payload ---');
|
||||
|
||||
const payload = {
|
||||
title: 'Sync Feature: test-feat',
|
||||
body: 'Auto sync',
|
||||
base: 'main',
|
||||
head: 'sync/test-feat'
|
||||
};
|
||||
|
||||
assertEqual_('PR title is set', payload.title, 'Sync Feature: test-feat');
|
||||
assertEqual_('PR base is main', payload.base, 'main');
|
||||
assertEqual_('PR head is correct', payload.head, 'sync/test-feat');
|
||||
|
||||
console.log('--- Test Passed: Gitea Pull Request Payload ---');
|
||||
}
|
||||
|
||||
function testCheckGiteaPullRequestExistsLogic() {
|
||||
console.log('--- Starting Test: Check Gitea PR Exists Logic ---');
|
||||
|
||||
const mockPrs = [
|
||||
{ base: { ref: 'main' }, head: { ref: 'sync/feat-1' } },
|
||||
{ base: { ref: 'main' }, head: { ref: 'sync/feat-2' } }
|
||||
];
|
||||
|
||||
const baseBranch = 'main';
|
||||
const headBranch = 'sync/feat-2';
|
||||
|
||||
const existing = mockPrs.find(function(pr) {
|
||||
return pr.base && pr.head && pr.base.ref === baseBranch && pr.head.ref === headBranch;
|
||||
});
|
||||
|
||||
assertTrue_('Finds existing PR', !!existing);
|
||||
assertEqual_('Matches correct head', existing.head.ref, 'sync/feat-2');
|
||||
|
||||
const notExisting = mockPrs.find(function(pr) {
|
||||
return pr.base && pr.head && pr.base.ref === baseBranch && pr.head.ref === 'sync/feat-3';
|
||||
});
|
||||
|
||||
assertTrue_('Does not find missing PR', !notExisting);
|
||||
|
||||
console.log('--- Test Passed: Check Gitea PR Exists Logic ---');
|
||||
}
|
||||
|
||||
function testEmptyRepoErrorDetection() {
|
||||
console.log('--- Starting Test: Empty Repo Error Detection ---');
|
||||
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"featureCode": "manual",
|
||||
"syncDate": "2026-04-24T22:40:04.295Z",
|
||||
"syncDate": "2026-04-24T17:41:52.985Z",
|
||||
"filesSynced": 12
|
||||
}
|
||||
Reference in New Issue
Block a user