Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undocumented/centralize initial pull/small change #63

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions webapp/src/Cache.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* global globalThis */

import { getRepoGit } from '@/RepoGit';
import { LanguageNotSupported } from '@/errors';
import { LyraProjectConfig } from '@/utils/lyraConfig';
import { ProjectStore } from '@/store/ProjectStore';
import { RepoGit } from '@/RepoGit';
import { ServerConfig } from '@/utils/serverConfig';
import { Store } from '@/store/Store';
import YamlTranslationAdapter from '@/utils/adapters/YamlTranslationAdapter';
Expand All @@ -12,8 +12,8 @@ export class Cache {
public static async getLanguage(projectName: string, lang: string) {
const serverProjectConfig =
await ServerConfig.getProjectConfig(projectName);
const repo = await getRepoGit(serverProjectConfig);
const lyraConfig = await repo.getLyraConfig();
const repoGit = await RepoGit.getRepoGit(serverProjectConfig);
const lyraConfig = await repoGit.getLyraConfig();
const lyraProjectConfig = lyraConfig.getProjectConfigByPath(
serverProjectConfig.projectPath,
);
Expand Down
12 changes: 3 additions & 9 deletions webapp/src/RepoGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ export class RepoGit {
this.git = new SimpleGitWrapper(spConfig.repoPath);
}

static async getRepoGit(config: ServerProjectConfig): Promise<RepoGit> {
const key = config.repoPath;
static async getRepoGit(spConfig: ServerProjectConfig): Promise<RepoGit> {
const key = spConfig.repoPath;
if (key in RepoGit.repositories) {
return RepoGit.repositories[key];
}
const { promise, resolve, reject } = Promise.withResolvers<RepoGit>();
RepoGit.repositories[key] = promise;

const repository = new RepoGit(config);
const repository = new RepoGit(spConfig);
repository.checkoutBaseAndPull().then(() => resolve(repository), reject);

return promise;
Expand Down Expand Up @@ -176,9 +176,3 @@ export class RepoGit {
return paths;
}
}

export async function getRepoGit(
config: ServerProjectConfig,
): Promise<RepoGit> {
return RepoGit.getRepoGit(config);
}
6 changes: 3 additions & 3 deletions webapp/src/app/api/messages/[projectName]/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import MessageAdapterFactory from '@/utils/adapters/MessageAdapterFactory';
import { RepoGit } from '@/RepoGit';
import { ServerConfig } from '@/utils/serverConfig';
import { getRepoGit, RepoGit } from '@/RepoGit';
import {
LyraConfigReadingError,
ProjectNameNotFoundError,
Expand All @@ -17,8 +17,8 @@ export async function GET(
const serverProjectConfig =
await ServerConfig.getProjectConfig(projectName);
await RepoGit.cloneIfNotExist(serverProjectConfig);
const repo = await getRepoGit(serverProjectConfig);
const lyraConfig = await repo.getLyraConfig();
const repoGit = await RepoGit.getRepoGit(serverProjectConfig);
const lyraConfig = await repoGit.getLyraConfig();
const projectConfig = lyraConfig.getProjectConfigByPath(
serverProjectConfig.projectPath,
);
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/app/api/pull-request/[projectName]/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getRepoGit } from '@/RepoGit';
import { ProjectNameNotFoundError } from '@/errors';
import { RepoGit } from '@/RepoGit';
import { NextRequest, NextResponse } from 'next/server';
import { ServerConfig, ServerProjectConfig } from '@/utils/serverConfig';

Expand Down Expand Up @@ -37,7 +37,7 @@ export async function POST(

try {
syncLock.set(repoPath, true);
const repoGit = await getRepoGit(serverProjectConfig);
const repoGit = await RepoGit.getRepoGit(serverProjectConfig);
const baseBranch = await repoGit.checkoutBaseAndPull();
const langFilePaths = await repoGit.saveLanguageFiles(
serverProjectConfig.projectPath,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Cache } from '@/Cache';
import { RepoGit } from '@/RepoGit';
import { ServerConfig } from '@/utils/serverConfig';
import { getRepoGit, RepoGit } from '@/RepoGit';
import {
LanguageNotFound,
LanguageNotSupported,
Expand All @@ -23,11 +23,11 @@ export async function PUT(
const { lang, msgId, projectName } = context.params;
const payload = await req.json();
const { text } = payload;
// TODO: include getProjectConfig & readFromDir in a try/catch block and check for error to return a certain 500 error
// TODO: include getProjectConfig() and getLyraConfig() in a try/catch block and check for error to return a certain 500 error
const serverProjectConfig = await ServerConfig.getProjectConfig(projectName);
await RepoGit.cloneIfNotExist(serverProjectConfig);
const repo = await getRepoGit(serverProjectConfig);
const lyraConfig = await repo.getLyraConfig();
const repoGit = await RepoGit.getRepoGit(serverProjectConfig);
const lyraConfig = await repoGit.getLyraConfig();

try {
const projectConfig = lyraConfig.getProjectConfigByPath(
Expand Down
8 changes: 4 additions & 4 deletions webapp/src/utils/adapters/MessageAdapterFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import YamlMessageAdapter from './YamlMessageAdapter';
import { LyraProjectConfig, MessageKind } from '../lyraConfig';

export default class MessageAdapterFactory {
static createAdapter(config: LyraProjectConfig) {
if (config.messageKind == MessageKind.TS) {
return new TsMessageAdapter(config.absMessagesPath);
static createAdapter(lpConfig: LyraProjectConfig) {
if (lpConfig.messageKind == MessageKind.TS) {
return new TsMessageAdapter(lpConfig.absMessagesPath);
} else {
return new YamlMessageAdapter(config.absMessagesPath);
return new YamlMessageAdapter(lpConfig.absMessagesPath);
}
}
}