forked from admin/brencher
reformat (#56)
This commit is contained in:
@@ -18,7 +18,7 @@ Generate docker compose file to deploy to docker swarm.
|
||||
|
||||
python ./backend/app.py brencher_local1:docker_swarm_check_by_version noweb
|
||||
|
||||
# Prod recovery
|
||||
# Prod recovery
|
||||
|
||||
uv venv --python 3.12.3 .venv
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ def process_all_jobs(
|
||||
step.progress()
|
||||
if (isinstance(step, GitUnmerge) or (
|
||||
isinstance(step, CachingStep) and isinstance(step.step, GitUnmerge))) and len(
|
||||
env.branches) == 0:
|
||||
env.branches) == 0:
|
||||
# TODO Move to separate job.
|
||||
# If branches list empty, need to find any brunch which includes commit and add pair (branch, commit)
|
||||
# If branches not empty, need to find most priority branch (project specific) and add (branch, HEAD)
|
||||
|
||||
@@ -2,7 +2,6 @@ import logging
|
||||
from typing import Any
|
||||
|
||||
import requests
|
||||
|
||||
from enironment import AbstractStep
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -9,7 +9,6 @@ import docker
|
||||
import yaml
|
||||
from docker import errors as docker_errors
|
||||
from dotenv import dotenv_values
|
||||
|
||||
from enironment import AbstractStep
|
||||
from steps.git import GitClone, HasVersion
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ from typing import List, Dict, Callable, Any, Optional, cast
|
||||
import docker
|
||||
from docker.models.containers import Container
|
||||
from docker.models.images import Image
|
||||
|
||||
from enironment import AbstractStep
|
||||
from steps.git import CheckoutMerged
|
||||
|
||||
@@ -20,6 +19,8 @@ class DockerImageBuildResult:
|
||||
image_name: str
|
||||
image_tag: str
|
||||
full_image: str
|
||||
|
||||
|
||||
# build_logs: List[str]
|
||||
|
||||
|
||||
|
||||
@@ -7,9 +7,8 @@ from dataclasses import dataclass
|
||||
from typing import List, Tuple, Set, Dict, Any, Mapping, runtime_checkable
|
||||
|
||||
import git
|
||||
from git.objects import Commit
|
||||
|
||||
from enironment import AbstractStep
|
||||
from git.objects import Commit
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
+38
-32
@@ -46,6 +46,7 @@ function showStatus(message, isError = false) {
|
||||
statusBar.style.background = isError ? '#f8d7da' : '#e9ecef';
|
||||
statusMessage.style.color = isError ? '#721c24' : '#333';
|
||||
}
|
||||
|
||||
closeStatus.onclick = () => statusBar.classList.add('hidden');
|
||||
|
||||
function checkForPendingChanges() {
|
||||
@@ -61,14 +62,14 @@ function checkForPendingChanges() {
|
||||
|
||||
function filterBranches() {
|
||||
const filterText = branchFilter.value.toLowerCase().trim();
|
||||
filteredBranches = branches.filter(({ envId, branch, commits }) => {
|
||||
filteredBranches = branches.filter(({envId, branch, commits}) => {
|
||||
const selList = selectedBranchesByEnv[envId] || [];
|
||||
const deployedMap = deployedCommitsByEnv[envId] || {};
|
||||
const isSelected = selList.some(([b]) => b === branch);
|
||||
const isDeployed = deployedMap[branch] && deployedMap[branch] !== 'N/A';
|
||||
const isFiltered = !!filterText && branch.toLowerCase().includes(filterText);
|
||||
const isFilteredByCommit = !!filterText && Array.isArray(commits) && commits.some(c => {
|
||||
const shortHash = c.hexsha ? c.hexsha.substring(0,8).toLowerCase() : '';
|
||||
const shortHash = c.hexsha ? c.hexsha.substring(0, 8).toLowerCase() : '';
|
||||
return (c.hexsha && c.hexsha.toLowerCase().includes(filterText)) ||
|
||||
shortHash.includes(filterText) ||
|
||||
(c.message && c.message.toLowerCase().includes(filterText)) ||
|
||||
@@ -86,13 +87,13 @@ function getCommitDropdownOptions(envId, branchName, desiredCommit) {
|
||||
|
||||
if (commits.length) {
|
||||
const head = commits[0];
|
||||
const headShort = head.hexsha ? head.hexsha.substring(0,8) : '';
|
||||
options += `<option value="HEAD" ${desiredCommit === 'HEAD' ? 'selected' : ''}>HEAD (${headShort} - ${(head.author||'').substring(0,25)} - ${head.message ? head.message.substring(0,50) + (head.message.length>50?'...':'') : ''})</option>`;
|
||||
const headShort = head.hexsha ? head.hexsha.substring(0, 8) : '';
|
||||
options += `<option value="HEAD" ${desiredCommit === 'HEAD' ? 'selected' : ''}>HEAD (${headShort} - ${(head.author || '').substring(0, 25)} - ${head.message ? head.message.substring(0, 50) + (head.message.length > 50 ? '...' : '') : ''})</option>`;
|
||||
commits.forEach(c => {
|
||||
const full = c.hexsha;
|
||||
const shortHash = full ? full.substring(0,8) : '';
|
||||
const shortHash = full ? full.substring(0, 8) : '';
|
||||
const isSelected = desiredCommit === full || desiredCommit === shortHash;
|
||||
options += `<option value="${full}" ${isSelected ? 'selected' : ''}>${shortHash} - ${(c.author||'').substring(0,25)} - ${c.message ? c.message.substring(0,50)+(c.message.length>50?'...':'') : ''}</option>`;
|
||||
options += `<option value="${full}" ${isSelected ? 'selected' : ''}>${shortHash} - ${(c.author || '').substring(0, 25)} - ${c.message ? c.message.substring(0, 50) + (c.message.length > 50 ? '...' : '') : ''}</option>`;
|
||||
});
|
||||
} else {
|
||||
options += `<option value="HEAD" ${desiredCommit === 'HEAD' ? 'selected' : ''}>HEAD (no commits)</option>`;
|
||||
@@ -100,7 +101,7 @@ function getCommitDropdownOptions(envId, branchName, desiredCommit) {
|
||||
|
||||
const hasMatch = commits.some(c => {
|
||||
const full = c.hexsha;
|
||||
const shortHash = full ? full.substring(0,8) : '';
|
||||
const shortHash = full ? full.substring(0, 8) : '';
|
||||
return desiredCommit === full || desiredCommit === shortHash || desiredCommit === 'HEAD';
|
||||
});
|
||||
const isCustom = desiredCommit && desiredCommit !== 'HEAD' && !hasMatch;
|
||||
@@ -114,7 +115,7 @@ function branchHasCommit(envId, branchName, commit) {
|
||||
if (!branchObj) return false;
|
||||
return branchObj.commits?.some(c => {
|
||||
const full = c.hexsha;
|
||||
const shortHash = full ? full.substring(0,8) : '';
|
||||
const shortHash = full ? full.substring(0, 8) : '';
|
||||
return commit === full || commit === shortHash;
|
||||
}) || false;
|
||||
}
|
||||
@@ -135,12 +136,12 @@ function renderBranches() {
|
||||
|
||||
// Group by envId for clearer separation
|
||||
const groups = branchesToShow.reduce((acc, b) => {
|
||||
acc[b.envId] = acc[b.envId] || { envName: b.envName, rows: [] };
|
||||
acc[b.envId] = acc[b.envId] || {envName: b.envName, rows: []};
|
||||
acc[b.envId].rows.push(b);
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
branchesList.innerHTML = Object.entries(groups).map(([envId, { envName, rows }]) => {
|
||||
branchesList.innerHTML = Object.entries(groups).map(([envId, {envName, rows}]) => {
|
||||
return `
|
||||
<div class="env-block">
|
||||
<h3 class="env-title">Environment: ${envName || envId}</h3>
|
||||
@@ -154,14 +155,14 @@ function renderBranches() {
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${rows.map(({ envId: eId, branch }) => {
|
||||
const selList = selectedBranchesByEnv[eId] || [];
|
||||
const pair = selList.find(([b]) => b === branch);
|
||||
const desiredCommit = pair ? pair[1] : 'HEAD';
|
||||
const deployedMap = deployedCommitsByEnv[eId] || {};
|
||||
const deployedCommit = deployedMap[branch] || 'N/A';
|
||||
const hasCommit = branchHasCommit(eId, branch, desiredCommit);
|
||||
return `
|
||||
${rows.map(({envId: eId, branch}) => {
|
||||
const selList = selectedBranchesByEnv[eId] || [];
|
||||
const pair = selList.find(([b]) => b === branch);
|
||||
const desiredCommit = pair ? pair[1] : 'HEAD';
|
||||
const deployedMap = deployedCommitsByEnv[eId] || {};
|
||||
const deployedCommit = deployedMap[branch] || 'N/A';
|
||||
const hasCommit = branchHasCommit(eId, branch, desiredCommit);
|
||||
return `
|
||||
<tr class="branch-row" data-env="${eId}" data-branch="${branch}">
|
||||
<td><input type="checkbox" value="${branch}" data-env="${eId}" ${pair ? 'checked' : ''}></td>
|
||||
<td>${branch}</td>
|
||||
@@ -175,7 +176,7 @@ function renderBranches() {
|
||||
</td>
|
||||
<td>${deployedCommit}</td>
|
||||
</tr>`;
|
||||
}).join('')}
|
||||
}).join('')}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>`;
|
||||
@@ -256,11 +257,11 @@ function renderJobs() {
|
||||
}
|
||||
};
|
||||
extractUserLinks(job.status);
|
||||
return userLinks.map(([title, url]) =>
|
||||
return userLinks.map(([title, url]) =>
|
||||
`<a href="${url}" target="_blank" rel="noopener noreferrer">${title}</a>`
|
||||
)
|
||||
)
|
||||
})
|
||||
.join(' | ');
|
||||
.join(' | ');
|
||||
}
|
||||
|
||||
return `
|
||||
@@ -268,7 +269,7 @@ function renderJobs() {
|
||||
<h4>Environment: ${envObj.name || envObj.id || ''}</h4>
|
||||
${linksHtml ? `<div style="float:right">${linksHtml}</div>` : ''}
|
||||
${Array.isArray(jobsArr) && jobsArr.length > 0
|
||||
? jobsArr.map(job => {
|
||||
? jobsArr.map(job => {
|
||||
let statusDisplay = `<pre>` + JSON.stringify(job.status, null, 2) + `</pre>`;
|
||||
statusDisplay = statusDisplay.replace(
|
||||
/(https?:\/\/[^\s"']+)/g,
|
||||
@@ -285,21 +286,21 @@ function renderJobs() {
|
||||
<div class="job-header" style="cursor:pointer;font-weight:bold;"
|
||||
onclick="toggleJobSpoiler('${key}', '${safeId}')">
|
||||
${isError
|
||||
? `<span style="color:#dc3545;font-weight:bold;margin-right:6px;" title="Error">!</span>`
|
||||
: `<span style="color:#28a745;font-weight:bold;margin-right:6px;" title="OK">✔</span>`}
|
||||
? `<span style="color:#dc3545;font-weight:bold;margin-right:6px;" title="Error">!</span>`
|
||||
: `<span style="color:#28a745;font-weight:bold;margin-right:6px;" title="OK">✔</span>`}
|
||||
${envObj.id} - ${job.name}
|
||||
</div>
|
||||
<div id="${safeId}" class="job-spoiler" style="display: ${openByDefault ? 'block' : 'none'}; margin-top:8px;">
|
||||
${statusDisplay}
|
||||
</div>
|
||||
</div>`;
|
||||
}).join('')
|
||||
: '<div class="job-item">No jobs found.</div>'}
|
||||
}).join('')
|
||||
: '<div class="job-item">No jobs found.</div>'}
|
||||
</div>`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
toggleJobSpoiler = function(key, safeId) {
|
||||
toggleJobSpoiler = function (key, safeId) {
|
||||
try {
|
||||
const el = document.getElementById(safeId);
|
||||
if (!el) return;
|
||||
@@ -318,7 +319,7 @@ toggleJobSpoiler = function(key, safeId) {
|
||||
}
|
||||
};
|
||||
refreshBranchesBtn.onclick = () => {
|
||||
wsEnv.emit('update', { id: "" });
|
||||
wsEnv.emit('update', {id: ""});
|
||||
showStatus('Refreshing...');
|
||||
};
|
||||
|
||||
@@ -353,7 +354,12 @@ function setupSocketIO() {
|
||||
branches = Object.entries(data).flatMap(([envId, branchMap]) =>
|
||||
Object.entries(branchMap).map(([branchName, commitList]) => {
|
||||
const envObj = (environmentsRaw.find((e) => e.id === envId) || [null])[0];
|
||||
return { envId, envName: envObj ? (envObj.name || envObj.id) : envId, branch: branchName, commits: commitList };
|
||||
return {
|
||||
envId,
|
||||
envName: envObj ? (envObj.name || envObj.id) : envId,
|
||||
branch: branchName,
|
||||
commits: commitList
|
||||
};
|
||||
})
|
||||
);
|
||||
filterBranches();
|
||||
@@ -398,7 +404,7 @@ function setupSocketIO() {
|
||||
// Rebuild branches list environment names for rows already present
|
||||
branches = branches.map(b => {
|
||||
const envEntry = environmentsRaw.find((e) => (e.id || e.name) === b.envId);
|
||||
return { ...b, envName: envEntry ? (envEntry.name || envEntry.id) : b.envName };
|
||||
return {...b, envName: envEntry ? (envEntry.name || envEntry.id) : b.envName};
|
||||
});
|
||||
|
||||
filterBranches();
|
||||
@@ -417,7 +423,7 @@ function updateEnvironment() {
|
||||
const localSel = [...(selectedBranchesByEnv[envId] || [])].sort();
|
||||
const serverSel = [...(serverSelectedBranchesByEnv[envId] || [])].sort();
|
||||
if (JSON.stringify(localSel) !== JSON.stringify(serverSel)) {
|
||||
wsEnv.emit('update', { id: envId, branches: selectedBranchesByEnv[envId] });
|
||||
wsEnv.emit('update', {id: envId, branches: selectedBranchesByEnv[envId]});
|
||||
// Optimistically sync server state
|
||||
serverSelectedBranchesByEnv[envId] = [...selectedBranchesByEnv[envId]];
|
||||
branchFilter.value = '';
|
||||
|
||||
+13
-1
@@ -5,14 +5,16 @@ body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 900px;
|
||||
margin: 40px auto;
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,0.08);
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
||||
padding: 32px;
|
||||
}
|
||||
|
||||
.primary-button {
|
||||
background: #007bff;
|
||||
color: #fff;
|
||||
@@ -22,9 +24,11 @@ body {
|
||||
cursor: pointer;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.primary-button:hover {
|
||||
background: #0056b3;
|
||||
}
|
||||
|
||||
.refresh-button {
|
||||
background: #28a745;
|
||||
color: #fff;
|
||||
@@ -36,6 +40,7 @@ body {
|
||||
margin-bottom: 16px;
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
.refresh-button:hover {
|
||||
background: #218838;
|
||||
}
|
||||
@@ -51,6 +56,7 @@ body {
|
||||
margin-bottom: 16px;
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
.apply-button:hover {
|
||||
background: #218838;
|
||||
}
|
||||
@@ -66,6 +72,7 @@ body {
|
||||
margin-bottom: 16px;
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
.toggle-button:hover {
|
||||
background: #218838;
|
||||
}
|
||||
@@ -74,14 +81,17 @@ body {
|
||||
text-align: center;
|
||||
margin: 16px 0;
|
||||
}
|
||||
|
||||
.control-bar {
|
||||
text-align: center;
|
||||
margin: 16px 0;
|
||||
}
|
||||
|
||||
.loading {
|
||||
color: #888;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.status-bar {
|
||||
background: #e9ecef;
|
||||
padding: 8px 16px;
|
||||
@@ -90,9 +100,11 @@ body {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.status-bar.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ from typing import Any, Generator
|
||||
import docker
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
from app import App
|
||||
from conftest import EventuallyFn # type: ignore[import-not-found]
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
|
||||
from enironment import wrap_in_cached
|
||||
|
||||
from tests.test_remote_repo import RemoteRepoHelper
|
||||
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ import os
|
||||
|
||||
import git
|
||||
import pytest
|
||||
|
||||
from steps.git import CheckoutAndMergeResult
|
||||
|
||||
from .test_remote_repo import RemoteRepoHelper
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import tempfile
|
||||
from typing import Dict, Tuple, List, Callable
|
||||
|
||||
import git
|
||||
|
||||
from enironment import Environment, AbstractStep
|
||||
from steps.docker import DockerSwarmCheckResult
|
||||
from steps.git import CheckoutAndMergeResult, CheckoutMerged, GitUnmerge, GitClone, HasVersion
|
||||
|
||||
Reference in New Issue
Block a user