mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-06-02 21:49:25 +00:00
58838f225c
Rewrite of the UI using Typescript, Vue3, Windicss and Vite. The design should be close to the current one with some changes: - latest pipeline in a sidebar on the right - secrets and registry as part of the repo-settings (secrets and registry entries shouldn't be used as much so they can be "hidden" under settings IMO) - start page shows list of active repositories with button to enable / add new ones (currently you see all repositories and in most cases you only add new repositories once in a while)
49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
import { ref } from 'vue';
|
|
|
|
import { BuildLog, BuildProc } from '~/lib/api/types';
|
|
import { isProcFinished, isProcRunning } from '~/utils/helpers';
|
|
|
|
import useApiClient from './useApiClient';
|
|
|
|
const apiClient = useApiClient();
|
|
|
|
export default () => {
|
|
const logs = ref<BuildLog[] | undefined>();
|
|
const proc = ref<BuildProc>();
|
|
let stream: EventSource | undefined;
|
|
|
|
function onLogsUpdate(data: BuildLog) {
|
|
if (data.proc === proc.value?.name) {
|
|
logs.value = [...(logs.value || []), data];
|
|
}
|
|
}
|
|
|
|
function unload() {
|
|
if (stream) {
|
|
stream.close();
|
|
}
|
|
}
|
|
|
|
async function load(owner: string, repo: string, build: number, _proc: BuildProc) {
|
|
unload();
|
|
|
|
proc.value = _proc;
|
|
logs.value = [];
|
|
|
|
// we do not have logs for skipped jobs
|
|
if (_proc.state === 'skipped' || _proc.state === 'killed') {
|
|
return;
|
|
}
|
|
|
|
if (isProcFinished(_proc)) {
|
|
logs.value = await apiClient.getLogs(owner, repo, build, _proc.pid);
|
|
}
|
|
|
|
if (isProcRunning(_proc)) {
|
|
stream = apiClient.streamLogs(owner, repo, build, _proc.pid, onLogsUpdate);
|
|
}
|
|
}
|
|
|
|
return { logs, load, unload };
|
|
};
|