From 3c4d451b729a8dc15c7ceef03767415a4db123a3 Mon Sep 17 00:00:00 2001 From: Anbraten Date: Thu, 16 Jun 2022 19:24:27 +0200 Subject: [PATCH] Use xterm.js for log outputs (#846) - use xterm - improve error showing - show build erro --- web/package.json | 5 +- web/src/assets/locales/en.json | 6 +- web/src/components/repo/build/BuildLog.vue | 187 +++++++++++++++--- .../components/repo/build/BuildProcList.vue | 38 +++- web/src/compositions/useBuildProc.ts | 49 ----- web/src/views/repo/RepoBranch.vue | 2 +- web/src/views/repo/build/Build.vue | 11 +- web/src/views/repo/build/BuildWrapper.vue | 4 +- web/yarn.lock | 15 ++ 9 files changed, 221 insertions(+), 96 deletions(-) delete mode 100644 web/src/compositions/useBuildProc.ts diff --git a/web/package.json b/web/package.json index e1acc2556..d6b97acc8 100644 --- a/web/package.json +++ b/web/package.json @@ -31,7 +31,10 @@ "pinia": "2.0.0", "vue": "v3.2.20", "vue-i18n": "9", - "vue-router": "4.0.10" + "vue-router": "4.0.10", + "xterm": "4.17.0", + "xterm-addon-fit": "0.5.0", + "xterm-addon-web-links": "0.5.1" }, "devDependencies": { "@iconify/json": "1.1.421", diff --git a/web/src/assets/locales/en.json b/web/src/assets/locales/en.json index 260dea266..46d94c38f 100644 --- a/web/src/assets/locales/en.json +++ b/web/src/assets/locales/en.json @@ -165,12 +165,14 @@ "created": "Created", "tasks": "Tasks", "config": "Config", - "files": "Changed files ({0})", + "files": "Changed files ({files})", "no_files": "No files have been changed.", "execution_error": "Execution error", "no_pipelines": "No pipelines have been started yet.", "step_not_started": "This step hasn't started yet.", - "pipelines_for": "Pipelines for branch \"{0}\"", + "pipelines_for": "Pipelines for branch \"{branch}\"", + "exit_code": "exit code {exitCode}", + "loading": "Loading ...", "actions": { "cancel": "Cancel", diff --git a/web/src/components/repo/build/BuildLog.vue b/web/src/components/repo/build/BuildLog.vue index 18f7394c0..e9ec308db 100644 --- a/web/src/components/repo/build/BuildLog.vue +++ b/web/src/components/repo/build/BuildLog.vue @@ -1,5 +1,5 @@ diff --git a/web/src/components/repo/build/BuildProcList.vue b/web/src/components/repo/build/BuildProcList.vue index 3f53f2278..c8b46d936 100644 --- a/web/src/components/repo/build/BuildProcList.vue +++ b/web/src/components/repo/build/BuildProcList.vue @@ -1,6 +1,19 @@ - + {{ build.commit.slice(0, 10) }} @@ -40,7 +53,9 @@
- {{ proc.name }} +
+ {{ proc.name }} +
diff --git a/web/src/compositions/useBuildProc.ts b/web/src/compositions/useBuildProc.ts deleted file mode 100644 index 3e4920200..000000000 --- a/web/src/compositions/useBuildProc.ts +++ /dev/null @@ -1,49 +0,0 @@ -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(); - const proc = ref(); - 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 (_proc.error) { - logs.value = undefined; - } else if (isProcFinished(_proc)) { - logs.value = await apiClient.getLogs(owner, repo, build, _proc.pid); - } else if (isProcRunning(_proc)) { - // load stream of parent process (which receives all child processes logs) - stream = apiClient.streamLogs(owner, repo, build, _proc.ppid, onLogsUpdate); - } - } - - return { logs, load, unload }; -}; diff --git a/web/src/views/repo/RepoBranch.vue b/web/src/views/repo/RepoBranch.vue index d75058355..520df24d1 100644 --- a/web/src/views/repo/RepoBranch.vue +++ b/web/src/views/repo/RepoBranch.vue @@ -1,6 +1,6 @@ diff --git a/web/src/views/repo/build/Build.vue b/web/src/views/repo/build/Build.vue index ac5bc661b..ba13acd5d 100644 --- a/web/src/views/repo/build/Build.vue +++ b/web/src/views/repo/build/Build.vue @@ -1,12 +1,12 @@