From a5bf91b83838edfcf041c2943187f4c0df267f7f Mon Sep 17 00:00:00 2001 From: luizy Date: Thu, 7 Dec 2023 17:44:51 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EB=B2=84=EA=B7=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#267] --- packages/backend/src/common/util.ts | 14 ++++++++++---- .../backend/src/containers/containers.service.ts | 8 ++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/common/util.ts b/packages/backend/src/common/util.ts index e24d584..d829c89 100644 --- a/packages/backend/src/common/util.ts +++ b/packages/backend/src/common/util.ts @@ -56,9 +56,15 @@ export function isStringArray(obj: unknown): obj is string[] { ); } -export function graphParser(graph: string): string { - const graphParsed = JSON.parse(`[ - ${graph.substring(0, graph.length - 1)} - ]`); +export function graphParser(graph: string) { + const lines = graph.split('\n'); + const graphParsed: object[] = []; + for (let i = 0; i < lines.length; i += 4) { + const id = lines[i]; + const parentId = lines[i + 1]; + const message = lines[i + 2]; + const refs = lines[i + 3]; + graphParsed.push({ id, parentId, message, refs }); + } return graphParsed; } diff --git a/packages/backend/src/containers/containers.service.ts b/packages/backend/src/containers/containers.service.ts index e247570..9df6755 100644 --- a/packages/backend/src/containers/containers.service.ts +++ b/packages/backend/src/containers/containers.service.ts @@ -9,7 +9,7 @@ import { CommandService } from '../command/command.service'; const DOCKER_QUIZZER_COMMAND = 'docker exec -w /home/quizzer/quiz/ -u quizzer'; const RETRY_DELAY = 500; const MAX_RETRY = 3; -const GRAPH_COMMAND = `git log --branches --pretty=format:'{"id":"%H","parentId":"%P","message":"%s","refs":"%D"},' --topo-order`; +const GRAPH_COMMAND = `git log --branches --pretty=format:'%H%n%P%n%s%n%D' --topo-order`; const GRAPH_ESCAPE = '89BDBC3136461-17189F6963D26-9F1BC6D53A3ED'; @Injectable() @@ -42,7 +42,7 @@ export class ContainersService { } private getGitCommand(container: string, command: string): string { - return `git config --global core.editor /editor/output.sh; ${DOCKER_QUIZZER_COMMAND} ${container} /usr/local/bin/restricted-shell ${command}`; + return `${DOCKER_QUIZZER_COMMAND} ${container} sh -c "git config --global core.editor /editor/output.sh; ${command}"`; } async runGitCommand( container: string, @@ -52,7 +52,7 @@ export class ContainersService { this.getGitCommand(container, command), `echo "${GRAPH_ESCAPE}" 1>&2`, `echo "${GRAPH_ESCAPE}"`, - this.getGitCommand(container, GRAPH_COMMAND), + `${DOCKER_QUIZZER_COMMAND} ${container} /usr/local/bin/restricted-shell ${GRAPH_COMMAND}`, ); const graphMessage = stdoutData @@ -105,7 +105,7 @@ export class ContainersService { this.getEditorCommand(container, message, command), `echo "${GRAPH_ESCAPE}" 1>&2`, `echo "${GRAPH_ESCAPE}"`, - this.getGitCommand(container, GRAPH_COMMAND), + `${DOCKER_QUIZZER_COMMAND} ${container} /usr/local/bin/restricted-shell ${GRAPH_COMMAND}`, ); const graphMessage = stdoutData