From ba86b5ac932bd9f929ad4712f2301ce6114c34e8 Mon Sep 17 00:00:00 2001 From: qiansc Date: Tue, 27 Oct 2026 20:15:14 +0800 Subject: [PATCH] fix: render settings for repositories without explicit branches --- scripts/repo-settings.test.mjs | 23 +++++++++++++++++++++++ web/assets/repo-page.js | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 scripts/repo-settings.test.mjs diff --git a/scripts/repo-settings.test.mjs b/scripts/repo-settings.test.mjs new file mode 100644 index 0000000..f7b8624 --- /dev/null +++ b/scripts/repo-settings.test.mjs @@ -0,0 +1,23 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import {readFileSync} from 'node:fs'; +import {createRequire} from 'node:module'; +import vm from 'node:vm'; +const require=createRequire(import.meta.url); +globalThis.App={t:zh=>zh}; +const M=require('../web/assets/management.js'); +const source=readFileSync(new URL('../web/assets/repo-page.js',import.meta.url),'utf8'); +const settings=source.slice(source.indexOf(' function ensureDraft()'),source.indexOf(' function capture()')); +test('settings render for seeded default-branch repositories and preserve explicit branches',()=>{ + for(const branches of [null,undefined,[],['release']]){ + const repo={policy:{branches,default_branch:true,count:1},index_mode:'full'}; + const ctx={repo,M,A:{user:()=>({})},canRepo:()=>true,keep:()=>[1,'commit'],t:zh=>zh,esc:String,btn2:''}; + vm.runInNewContext('let draft;'+settings+'; result={html:settings(),draft};',ctx); + assert.match(ctx.result.html,/id="pgit-timeout"/); + assert.match(ctx.result.html,/value="0" selected/); + assert.equal(ctx.result.draft.defaultBranch,true); + assert.deepEqual(Array.from(ctx.result.draft.branches),branches||[]); + ctx.result.draft.branches.push('another'); + if(branches)assert.ok(!branches.includes('another')); + } +}); diff --git a/web/assets/repo-page.js b/web/assets/repo-page.js index e7f6fdd..8afe748 100644 --- a/web/assets/repo-page.js +++ b/web/assets/repo-page.js @@ -185,7 +185,7 @@ (rest>0?'':''); } - function ensureDraft(){if(!draft)draft={branches:repo.policy.branches.slice(),defaultBranch:!!repo.policy.default_branch,publicRead:repo.public_read!==false,pending:'',kind:repo.policy.days?'days':'count',value:String(repo.policy.days||repo.policy.count),gitTimeout:String(repo.git_timeout_minutes||0),syncInterval:String(repo.sync_interval_minutes||M.DEFAULT_SYNC_INTERVAL_MINUTES),skipGenerated:!repo.index_generated,indexSymlinks:repo.index_symlinks!==false,pathState:{groups:repo.path_groups||[]}};} + function ensureDraft(){if(!draft)draft={branches:(repo.policy.branches||[]).slice(),defaultBranch:!!repo.policy.default_branch,publicRead:repo.public_read!==false,pending:'',kind:repo.policy.days?'days':'count',value:String(repo.policy.days||repo.policy.count),gitTimeout:String(repo.git_timeout_minutes||0),syncInterval:String(repo.sync_interval_minutes||M.DEFAULT_SYNC_INTERVAL_MINUTES),skipGenerated:!repo.index_generated,indexSymlinks:repo.index_symlinks!==false,pathState:{groups:repo.path_groups||[]}};} function settings(){ if(repo.deleted)return '

'+t('仓库已标记删除,无法修改设置。请在「管理」里重试永久删除','This repository is marked for deletion and cannot be edited. Retry permanent deletion from Manage')+'

'; const can=A.user()&&canRepo(), k=keep(repo.policy);