| 1 | import { Type } from 'class-transformer'; |
| 2 | import { |
| 3 | ArrayMaxSize, |
| 4 | IsBoolean, |
| 5 | IsIn, |
| 6 | IsInt, |
| 7 | IsISO8601, |
| 8 | IsOptional, |
| 9 | IsString, |
| 10 | IsUUID, |
| 11 | Matches, |
| 12 | Min, |
| 13 | ValidateIf, |
| 14 | ValidateNested, |
| 15 | } from 'class-validator'; |
| 16 | |
| 17 | // GitHub logins, and apps acting as `name[bot]`. |
| 18 | const GITHUB_LOGIN = / |
| 19 | |
| 20 | // The importer cuts batches well below the body limit; this only bounds a single request's transaction. |
| 21 | const MAX_BATCH = 500 |
| 22 | |
| 23 | export class ImportAttemptDTO |
| 24 | @IsUUID() |
| 25 | attempt: string; |
| 26 | } |
| 27 | |
| 28 | export class ImportedReleaseDTO |
| 29 | @IsString() |
| 30 | tagName: string; |
| 31 | |
| 32 | @ValidateIf((_ |
| 33 | @IsString() |
| 34 | name: string |
| 35 | |
| 36 | @ValidateIf((_ |
| 37 | @IsString() |
| 38 | body: string |
| 39 | |
| 40 | @IsBoolean() |
| 41 | isDraft: boolean; |
| 42 | |
| 43 | @IsBoolean() |
| 44 | isPrerelease: boolean; |
| 45 | |
| 46 | @IsISO8601() |
| 47 | createdAt: string; |
| 48 | |
| 49 | @ValidateIf((_ |
| 50 | @IsISO8601() |
| 51 | publishedAt: string |
| 52 | } |
| 53 | |
| 54 | export class ImportReleasesRequestDTO |
| 55 | @ValidateNested({ each |
| 56 | @ArrayMaxSize(MAX_BATCH) |
| 57 | @Type(() => |
| 58 | releases: ImportedReleaseDTO |
| 59 | } |
| 60 | |
| 61 | export class ImportedLabelDTO |
| 62 | @IsString() |
| 63 | name: string; |
| 64 | |
| 65 | @Matches(/^[ |
| 66 | color: string; |
| 67 | |
| 68 | @ValidateIf((_ |
| 69 | @IsString() |
| 70 | description: string |
| 71 | } |
| 72 | |
| 73 | export class ImportedPullRequestDTO |
| 74 | @IsIn(['open' |
| 75 | state: 'open |
| 76 | |
| 77 | @IsBoolean() |
| 78 | draft: boolean; |
| 79 | |
| 80 | @IsString() |
| 81 | baseRef: string; |
| 82 | |
| 83 | @IsString() |
| 84 | headRef: string; |
| 85 | |
| 86 | @Matches(/^[ |
| 87 | headSha: string; |
| 88 | |
| 89 | /** The head branch is in this repository and was pushed with it; false for a fork's branch or a deleted one. */ |
| 90 | @IsBoolean() |
| 91 | headInRepository: boolean; |
| 92 | |
| 93 | /** Null when GitHub has none, or the importer could not find it in the pushed history. */ |
| 94 | @ValidateIf((_ |
| 95 | @Matches(/^[ |
| 96 | mergeCommitSha: string |
| 97 | |
| 98 | @ValidateIf((_ |
| 99 | @IsISO8601() |
| 100 | mergedAt: string |
| 101 | } |
| 102 | |
| 103 | export class ImportedIssueDTO |
| 104 | @IsInt() |
| 105 | @Min(1) |
| 106 | number: number; |
| 107 | |
| 108 | @IsString() |
| 109 | title: string; |
| 110 | |
| 111 | @ValidateIf((_ |
| 112 | @IsString() |
| 113 | body: string |
| 114 | |
| 115 | @Matches(GITHUB_LOGIN) |
| 116 | authorLogin: string; |
| 117 | |
| 118 | @IsIn(['open' |
| 119 | state: 'open |
| 120 | |
| 121 | @IsISO8601() |
| 122 | createdAt: string; |
| 123 | |
| 124 | @IsISO8601() |
| 125 | updatedAt: string; |
| 126 | |
| 127 | @ValidateIf((_ |
| 128 | @IsISO8601() |
| 129 | closedAt: string |
| 130 | |
| 131 | @ValidateNested({ each |
| 132 | @Type(() => |
| 133 | labels: ImportedLabelDTO |
| 134 | |
| 135 | @IsOptional() |
| 136 | @ValidateNested() |
| 137 | @Type(() => |
| 138 | pullRequest?: ImportedPullRequestDTO |
| 139 | } |
| 140 | |
| 141 | export class ImportIssuesRequestDTO |
| 142 | @ValidateNested({ each |
| 143 | @ArrayMaxSize(MAX_BATCH) |
| 144 | @Type(() => |
| 145 | issues: ImportedIssueDTO |
| 146 | } |
| 147 | |
| 148 | export class ImportedCommentDTO |
| 149 | @IsInt() |
| 150 | @Min(1) |
| 151 | githubId: number; |
| 152 | |
| 153 | @IsInt() |
| 154 | @Min(1) |
| 155 | issueNumber: number; |
| 156 | |
| 157 | @Matches(GITHUB_LOGIN) |
| 158 | authorLogin: string; |
| 159 | |
| 160 | @IsString() |
| 161 | body: string; |
| 162 | |
| 163 | @IsISO8601() |
| 164 | createdAt: string; |
| 165 | |
| 166 | @IsISO8601() |
| 167 | updatedAt: string; |
| 168 | } |
| 169 | |
| 170 | export class ImportCommentsRequestDTO |
| 171 | @ValidateNested({ each |
| 172 | @ArrayMaxSize(MAX_BATCH) |
| 173 | @Type(() => |
| 174 | comments: ImportedCommentDTO |
| 175 | } |
| 176 | |
| 177 | export class FinishImportRequestDTO |
| 178 | @IsBoolean() |
| 179 | succeeded: boolean; |
| 180 | |
| 181 | @IsOptional() |
| 182 | @IsString() |
| 183 | defaultBranch?: string |
| 184 | |
| 185 | @ValidateIf((dto |
| 186 | @IsString() |
| 187 | error?: string |
| 188 | |
| 189 | @ValidateIf((dto |
| 190 | @IsBoolean() |
| 191 | retryable?: boolean |
| 192 | } |