57 lines
2.0 KiB
JavaScript
57 lines
2.0 KiB
JavaScript
// Repo / CI panel: git state of the current session's folder plus the Gitea CI
|
|||
|
|
// status of its HEAD commit (`devdesk attach --repo <session>`).
|
||
|
|
|
||
|
|
const CI = {
|
||
|
|
success: ['passing', 'lt-status-completed'],
|
||
|
|
failure: ['failed', 'lt-status-failed'],
|
||
|
|
error: ['error', 'lt-status-failed'],
|
||
|
|
pending: ['running', 'lt-status-running'],
|
||
|
|
warning: ['warning', 'lt-status-pending'],
|
||
|
|
};
|
||
|
|
|
||
|
|
function link(href, text) {
|
||
|
|
const a = document.createElement('a');
|
||
|
|
a.href = href;
|
||
|
|
a.target = '_blank';
|
||
|
|
a.rel = 'noopener';
|
||
|
|
a.textContent = text;
|
||
|
|
return a;
|
||
|
|
}
|
||
|
|
|
||
|
|
export function renderRepo(root, repo) {
|
||
|
|
const field = (name) => root.querySelector(`[data-field="${name}"]`);
|
||
|
|
const set = (name, value) => field(name).replaceChildren(value);
|
||
|
|
const note = root.querySelector('.dd-repo-note');
|
||
|
|
|
||
|
|
if (!repo || !repo.git) {
|
||
|
|
root.dataset.state = 'empty';
|
||
|
|
for (const f of ['repo', 'branch', 'dirty', 'prs']) set(f, '—');
|
||
|
|
const ci = field('ci');
|
||
|
|
ci.className = 'lt-status lt-status-pending';
|
||
|
|
ci.textContent = 'no data';
|
||
|
|
note.textContent = repo
|
||
|
|
? `${repo.dir} is not a git repository.`
|
||
|
|
: 'Open a session to see its repository.';
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
root.dataset.state = 'live';
|
||
|
|
set('repo', repo.url ? link(repo.url, repo.repo) : (repo.remote || 'no remote'));
|
||
|
|
const sync = repo.upstream
|
||
|
|
? [repo.ahead ? `↑${repo.ahead}` : '', repo.behind ? `↓${repo.behind}` : ''].filter(Boolean).join(' ') || 'in sync'
|
||
|
|
: 'no upstream';
|
||
|
|
set('branch', `${repo.branch} @ ${repo.sha || '—'} · ${sync}`);
|
||
|
|
set('dirty', repo.dirty ? `${repo.dirty} changed` : 'clean');
|
||
|
|
|
||
|
|
const ci = field('ci');
|
||
|
|
const [label, cls] = repo.ci?.total ? (CI[repo.ci.state] || [repo.ci.state, 'lt-status-pending'])
|
||
|
|
: [repo.ahead ? 'not pushed' : 'no CI', 'lt-status-pending'];
|
||
|
|
ci.className = `lt-status ${cls}`;
|
||
|
|
ci.replaceChildren(repo.ci?.url ? link(repo.ci.url, label) : label);
|
||
|
|
|
||
|
|
set('prs', repo.url && repo.prs != null
|
||
|
|
? link(`${repo.url}/pulls`, `${repo.prs} open`)
|
||
|
|
: '—');
|
||
|
|
note.textContent = repo.repo ? '' : 'Not a Gitea repository; CI status unavailable.';
|
||
|
|
}
|