Skip to content

Commit

Permalink
refactor: 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
LuizyHub authored and flydog98 committed Dec 7, 2023
1 parent 3e192fc commit a5bf91b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
14 changes: 10 additions & 4 deletions packages/backend/src/common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
8 changes: 4 additions & 4 deletions packages/backend/src/containers/containers.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a5bf91b

Please sign in to comment.