fix(ui): tolerate unavailable remotes and empty branch lists
Python package / build (3.12.3) (pull_request) Canceled after 0s
Python package / build (3.13) (pull_request) Canceled after 0s
Python package / build (3.14) (pull_request) Canceled after 0s

This commit is contained in:
2026-10-06 17:08:48 +00:00
parent 152d3702cd
commit 2efee3c76c
3 changed files with 64 additions and 27 deletions
+28 -19
View File
@@ -93,29 +93,38 @@ class GitClone(AbstractStep[str]):
else:
repo = git.Repo.init(self.repo_path)
fetched_remotes = 0
for entry in self.remotes:
remote_name = entry["name"]
repository_url = entry["url"]
auth_url = self._get_auth_git_url(repository_url)
if remote_name in repo.remotes:
remote = repo.remotes[remote_name]
if remote.url != auth_url:
remote.set_url(auth_url)
else:
remote = repo.create_remote(remote_name, auth_url)
with repo.config_writer() as config:
config.set_value(
f'remote "{remote_name}"',
'fetch',
f'+refs/heads/*:refs/remotes/{remote_name}/*',
)
if remote_name == "origin" and self.branchNamePrefix != "":
try:
auth_url = self._get_auth_git_url(repository_url)
if remote_name in repo.remotes:
remote = repo.remotes[remote_name]
if remote.url != auth_url:
remote.set_url(auth_url)
else:
remote = repo.create_remote(remote_name, auth_url)
with repo.config_writer() as config:
config.set_value('remote "origin"', "fetch",
f"+refs/heads/{self.branchNamePrefix}/*:refs/remotes/origin/{self.branchNamePrefix}/*")
result = remote.fetch(prune=True)
if not result or any(fetch_info.flags & fetch_info.ERROR for fetch_info in result):
raise BaseException(f"Failed to fetch updates for {remote_name}")
config.set_value(
f'remote "{remote_name}"',
'fetch',
f'+refs/heads/*:refs/remotes/{remote_name}/*',
)
if remote_name == "origin" and self.branchNamePrefix != "":
with repo.config_writer() as config:
config.set_value('remote "origin"', "fetch",
f"+refs/heads/{self.branchNamePrefix}/*:refs/remotes/origin/{self.branchNamePrefix}/*")
result = remote.fetch(prune=True)
if not result or any(fetch_info.flags & fetch_info.ERROR for fetch_info in result):
raise BaseException(f"Failed to fetch updates for {remote_name}")
fetched_remotes += 1
except BaseException as remote_error:
if "File contains no section headers" in str(remote_error):
raise
logger.warning("Unable to fetch remote %s (%s): %s", remote_name, repository_url, remote_error)
if fetched_remotes == 0:
logger.warning("No configured git remotes are available; keeping the local repository state")
if not os.path.exists(os.path.join(self.repo_path, ".git")):
raise BaseException(f"Failed to clone repositories {self.remotes} to {self.repo_path}")
except BaseException as e:
+15 -8
View File
@@ -195,11 +195,6 @@ function renderBranches() {
checkForPendingChanges();
const branchesToShow = filteredBranches.length > 0 || branchFilter.value.trim() || activeEnvFilters.size > 0 ? filteredBranches : branches;
if (!branchesToShow.length) {
branchesList.innerHTML = '<p class="loading">No branches found.</p>';
return;
}
// Group by envId for clearer separation
const groups = branchesToShow.reduce((acc, b) => {
acc[b.envId] = acc[b.envId] || {envName: b.envName, rows: []};
@@ -207,18 +202,30 @@ function renderBranches() {
return acc;
}, {});
environmentsRaw
.filter(envObj => envObj && (activeEnvFilters.size === 0 || activeEnvFilters.has(envObj.id || envObj.name)))
.forEach(envObj => {
const envId = envObj.id || envObj.name;
if (!groups[envId]) groups[envId] = {envName: envObj.name || envId, rows: []};
});
if (!Object.keys(groups).length) {
branchesList.innerHTML = '<p class="loading">No branches found.</p>';
return;
}
branchesList.innerHTML = Object.entries(groups).map(([envId, {envName, rows}]) => {
const envCols = columnsByEnv[envId] || {};
const colNames = Object.keys(envCols);
return `
<div class="env-block">
<h3 class="env-title">
Environment: ${envName || envId}
Environment: ${escapeHtml(envName || envId)}
<button class="dry-run-btn ${dryRunByEnv[envId] ? 'dry-run-active' : ''}" data-env="${envId}" title="${dryRunByEnv[envId] ? 'Dry run on — click to resume' : 'Running — click to pause (dry run)'}">
${dryRunByEnv[envId] ? '▶' : '⏸'}
</button>
</h3>
<table class="branches-table">
${rows.length ? `<table class="branches-table">
<thead>
<tr>
<th>Deploy</th>
@@ -249,7 +256,7 @@ function renderBranches() {
</tr>`;
}).join('')}
</tbody>
</table>
</table>` : '<p class="loading">No branches found.</p>'}
</div>`;
}).join('');
// Event wiring
+21
View File
@@ -71,6 +71,27 @@ class TestGitIntegration:
shutil.rmtree(github_dir, ignore_errors=True)
shutil.rmtree(gitea_dir, ignore_errors=True)
def test_git_clone_keeps_available_remote_when_another_is_unreachable(self, repo_helper: RemoteRepoHelper) -> None:
repo_helper.create_commit(repo_helper.repo, "master", "master", "README.md", "content", "Initial commit")
clone = GitClone(remotes=[
{"name": "available", "url": repo_helper.remote_dir},
{"name": "unreachable", "url": "/does/not/exist"},
])
clone.env = repo_helper.env
clone.progress()
assert "available/master" in clone.get_branches()
def test_git_clone_keeps_empty_repository_when_all_remotes_are_unreachable(self, repo_helper: RemoteRepoHelper) -> None:
clone = GitClone(url="/does/not/exist")
clone.env = repo_helper.env
repo_path = clone.progress()
assert os.path.isdir(os.path.join(repo_path, ".git"))
assert clone.get_branches() == {}
def test_git_clone_remotes_validation(self) -> None:
# Empty list: rejected (would produce an unusable clone).
with pytest.raises(ValueError, match="At least one repository URL is required"):