| 1 | import { ApiProperty } from '@nestjs/swagger'; |
| 2 | import { Type } |
| 3 | import { |
| 4 | IsBoolean, |
| 5 | ValidateNested, |
| 6 | IsIn, |
| 7 | IsInt, |
| 8 | IsISO8601, |
| 9 | IsString, |
| 10 | Matches, |
| 11 | } from 'class-validator'; |
| 12 | import { schema } |
| 13 | |
| 14 | import { CreateRepositoryRequestDTO } |
| 15 | |
| 16 | export class StartImportRequestDTO |
| 17 | @ApiProperty({ |
| 18 | description: 'The GitHub repository to import, as `owner/name`.', |
| 19 | example: 'octocat/hello-world', |
| 20 | }) |
| 21 | @Matches(/^[ |
| 22 | message: 'source must be a GitHub repository written as owner/name', |
| 23 | }) |
| 24 | source: string; |
| 25 | } |
| 26 | |
| 27 | export class GitHubImportStatusDTO |
| 28 | @ApiProperty({ |
| 29 | description: 'Whether this instance can import from GitHub at all.', |
| 30 | }) |
| 31 | @IsBoolean() |
| 32 | enabled: boolean; |
| 33 | |
| 34 | @ApiProperty({ |
| 35 | description: |
| 36 | 'Whether the signed-in user has linked a GitHub account to import with.', |
| 37 | }) |
| 38 | @IsBoolean() |
| 39 | connected: boolean; |
| 40 | } |
| 41 | |
| 42 | export class RepositoryImportDTO |
| 43 | @ApiProperty({ |
| 44 | enumName: 'RepositoryImportStatus', |
| 45 | enum: schema.repositoryImportStatus |
| 46 | }) |
| 47 | @IsIn(schema. |
| 48 | status: (typeof |
| 49 | |
| 50 | @ApiProperty({ example |
| 51 | @IsString() |
| 52 | source: string; |
| 53 | |
| 54 | @ApiProperty({ |
| 55 | description: |
| 56 | 'Attempts made so far; a failed attempt is retried automatically a few times before the import fails.', |
| 57 | }) |
| 58 | @IsInt() |
| 59 | attempts: number; |
| 60 | |
| 61 | @ApiProperty({ type |
| 62 | @IsString() |
| 63 | lastError: string |
| 64 | |
| 65 | @ApiProperty() |
| 66 | @IsISO8601() |
| 67 | createdAt: string; |
| 68 | |
| 69 | @ApiProperty() |
| 70 | @IsISO8601() |
| 71 | updatedAt: string; |
| 72 | } |
| 73 | |
| 74 | export class GitHubRepositoryDTO |
| 75 | @ApiProperty({ example |
| 76 | @IsString() |
| 77 | fullName: string; |
| 78 | |
| 79 | @ApiProperty() |
| 80 | @IsBoolean() |
| 81 | private: boolean; |
| 82 | |
| 83 | @ApiProperty({ type |
| 84 | @IsString() |
| 85 | description: string |
| 86 | } |
| 87 | |
| 88 | export class GitHubRepositoriesDTO |
| 89 | @ApiProperty({ type |
| 90 | @ValidateNested({ each |
| 91 | @Type(() => |
| 92 | repositories: GitHubRepositoryDTO |
| 93 | } |