/
arseniy985
/
QuantaAI
Обзор
Документация
Войти
/
arseniy985
/
QuantaAI
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
src/internal/modules/github/services/git-integration.service.ts
100 строк
3 KB
Arseniy
feat: improve git push workflow and workspace metadata
28 янв 2026, 15:33
28 янв 2026, 15:33
48200e6
Код
Авторство
О чём код?
import { inject, injectable } from 'inversify'; import { GitHubRepoService, type EnsureGitHubRepoResult } from './github-repo.service'; import { GitWorkspaceService } from './git-workspace.service'; import type { ProjectGitHub } from '@/internal/models'; import { GitHubTypes } from '../types'; export type GitIntegrationResult = { repo: ProjectGitHub | null; repoCreated: boolean; gitInitialized: boolean; pushed: boolean; errors: string[]; }; @injectable() export class GitIntegrationService { constructor( @inject(GitHubTypes.GitHubRepoService) private repoService: GitHubRepoService, @inject(GitHubTypes.GitWorkspaceService) private workspaceService: GitWorkspaceService, ) {} async ensureGitSetup(projectId: string, nameHint?: string | null): Promise<GitIntegrationResult> { const errors: string[] = []; let repoResult: EnsureGitHubRepoResult | null = null; try { repoResult = await this.repoService.ensureRepoForProject(projectId, nameHint ?? null); if (!repoResult) { errors.push('GitHub credentials unavailable.'); } } catch (error) { errors.push(`GitHub repo creation failed: ${(error as Error).message}`); } const repo = repoResult?.repo ?? null; const authToken = repoResult?.authToken ?? null; const gitResult = await this.workspaceService.ensureWorkspaceRepo( projectId, repo?.cloneUrl ?? null, authToken ? { token: authToken } : null, ); errors.push(...gitResult.errors); return { repo, repoCreated: Boolean(repoResult?.created), gitInitialized: gitResult.initialized, pushed: gitResult.pushed, errors, }; } async pushGitChanges(projectId: string): Promise<GitIntegrationResult> { const errors: string[] = []; let repo = null; try { repo = await this.repoService.getRepoForProject(projectId); if (!repo) { errors.push('GitHub repo not found.'); } } catch (error) { errors.push(`GitHub repo lookup failed: ${(error as Error).message}`); } let authToken: string | null = null; if (repo) { try { const auth = await this.repoService.resolveAuthForProject(projectId); authToken = auth?.token ?? null; if (!authToken) errors.push('GitHub credentials unavailable.'); } catch (error) { errors.push(`GitHub auth failed: ${(error as Error).message}`); } } if (repo && authToken) { const gitResult = await this.workspaceService.pushWorkspace( projectId, repo.cloneUrl ?? null, { token: authToken }, ); errors.push(...gitResult.errors); return { repo, repoCreated: false, gitInitialized: false, pushed: gitResult.pushed, errors, }; } return { repo, repoCreated: false, gitInitialized: false, pushed: false, errors, }; } }