| 1 | import { |
| 2 | Body, |
| 3 | Controller, |
| 4 | Get, |
| 5 | HttpCode, |
| 6 | HttpStatus, |
| 7 | Param, |
| 8 | Post, |
| 9 | Session, |
| 10 | } from '@nestjs/common'; |
| 11 | import { |
| 12 | ApiBadGatewayResponse, |
| 13 | ApiConflictResponse, |
| 14 | ApiCreatedResponse, |
| 15 | ApiForbiddenResponse, |
| 16 | ApiNoContentResponse, |
| 17 | ApiNotFoundResponse, |
| 18 | ApiOkResponse, |
| 19 | ApiOperation, |
| 20 | ApiTags, |
| 21 | } from '@nestjs/swagger'; |
| 22 | import { OptionalAuth, type |
| 23 | |
| 24 | import { ErrorResponseDTO } |
| 25 | import { CreateRepositoryResponseDTO } |
| 26 | import { |
| 27 | GitHubImportStatusDTO, |
| 28 | GitHubRepositoriesDTO, |
| 29 | RepositoryImportDTO, |
| 30 | StartImportRequestDTO, |
| 31 | } from './dto/import.dto.js'; |
| 32 | import { ImportsService } |
| 33 | |
| 34 | @Controller() |
| 35 | @ApiTags('Imports') |
| 36 | export class ImportsController |
| 37 | constructor(private readonly |
| 38 | |
| 39 | @Get('imports/github' |
| 40 | @ApiOperation({ |
| 41 | summary: 'GitHub import availability', |
| 42 | description: |
| 43 | 'Whether this instance imports from GitHub, and whether the signed-in user has linked the GitHub account an import reads with.', |
| 44 | }) |
| 45 | @ApiOkResponse({ type |
| 46 | githubStatus( |
| 47 | @Session() session |
| 48 | ): Promise<GitHubImportStatusDTO |
| 49 | return this.imports |
| 50 | } |
| 51 | |
| 52 | @Get('imports/github/repositories' |
| 53 | @ApiOperation({ |
| 54 | summary: 'List GitHub repositories to import', |
| 55 | description: |
| 56 | "Repositories the signed-in user's linked GitHub account owns, collaborates on or reaches through an organization, most recently pushed first, capped at 1,000. Public repositories the account merely can read are not listed.", |
| 57 | }) |
| 58 | @ApiOkResponse({ type |
| 59 | @ApiConflictResponse({ type |
| 60 | @ApiBadGatewayResponse({ type |
| 61 | githubRepositories( |
| 62 | @Session() session |
| 63 | ): Promise<GitHubRepositoriesDTO |
| 64 | return this.imports |
| 65 | } |
| 66 | |
| 67 | @Post('imports' |
| 68 | @ApiOperation({ |
| 69 | summary: 'Import a repository from GitHub', |
| 70 | description: |
| 71 | 'Creates the repository, then imports its code, releases, issues and pull requests in the background. Watch progress with `GET /repositories/{username}/{repo}/import`.', |
| 72 | }) |
| 73 | @ApiCreatedResponse({ type |
| 74 | @ApiNotFoundResponse({ type |
| 75 | @ApiConflictResponse({ type |
| 76 | @ApiBadGatewayResponse({ type |
| 77 | start( |
| 78 | @Body() body |
| 79 | @Session() session |
| 80 | ): Promise<CreateRepositoryResponseDTO |
| 81 | return this.imports |
| 82 | } |
| 83 | |
| 84 | @Get('repositories/:username/:repo/import' |
| 85 | @OptionalAuth() |
| 86 | @ApiOperation({ |
| 87 | summary: 'Get import progress', |
| 88 | description: 'How the GitHub import that created this repository is going.', |
| 89 | }) |
| 90 | @ApiOkResponse({ type |
| 91 | @ApiNotFoundResponse({ type |
| 92 | status( |
| 93 | @Param('username' |
| 94 | @Param('repo' |
| 95 | @Session() session |
| 96 | ): Promise<RepositoryImportDTO |
| 97 | return this.imports |
| 98 | username, |
| 99 | repo, |
| 100 | requesterId: session?.user |
| 101 | }); |
| 102 | } |
| 103 | |
| 104 | @Post('repositories/:username/:repo/import/retry' |
| 105 | @HttpCode(HttpStatus. |
| 106 | @ApiOperation({ |
| 107 | summary: 'Retry a failed import', |
| 108 | description: |
| 109 | 'Starts a failed import over with the caller’s GitHub account. Needs admin on the repository.', |
| 110 | }) |
| 111 | @ApiNoContentResponse() |
| 112 | @ApiForbiddenResponse({ type |
| 113 | @ApiNotFoundResponse({ type |
| 114 | @ApiConflictResponse({ type |
| 115 | retry( |
| 116 | @Param('username' |
| 117 | @Param('repo' |
| 118 | @Session() session |
| 119 | ) { |
| 120 | return this.imports |
| 121 | } |
| 122 | } |