Web API for code.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

34 lines
1.3 KiB

  1. import {constants} from 'http2';
  2. import * as codeCore from '@modal/code-core';
  3. import {HttpError} from '../../packages/fastify-compliant-http-errors';
  4. export interface GitService {
  5. createRepo(options: codeCore.git.CreateRepoData, user?: codeCore.common.User): Promise<codeCore.git.Repo>;
  6. deleteRepo(repoId: codeCore.git.Repo['id'], user?: codeCore.common.User): Promise<void>
  7. }
  8. export class UnableToCreateRepoError extends HttpError(constants.HTTP_STATUS_UNAUTHORIZED, 'Unable to Create Repo') {}
  9. export class UnableToDeleteRepoError extends HttpError(constants.HTTP_STATUS_UNAUTHORIZED, 'Unable to Delete Repo') {}
  10. export class GitServiceImpl implements GitService {
  11. private readonly coreGitService: codeCore.git.GitService;
  12. constructor() {
  13. this.coreGitService = new codeCore.git.GitServiceImpl();
  14. }
  15. async createRepo(options: codeCore.git.CreateRepoData, user?: codeCore.common.User): Promise<codeCore.git.Repo> {
  16. if (user) {
  17. return this.coreGitService.create(options, user);
  18. }
  19. throw new UnableToCreateRepoError('Unauthorized');
  20. }
  21. async deleteRepo(repoId: codeCore.git.Repo['id'], user?: codeCore.common.User): Promise<void> {
  22. if (user) {
  23. await this.coreGitService.delete(repoId, user);
  24. }
  25. throw new UnableToDeleteRepoError('Unauthorized');
  26. }
  27. }