| 1 | import { schema } from '@ghost/db'; |
| 2 | import { ApiProperty, ApiPropertyOptional |
| 3 | import { Type } |
| 4 | import { |
| 5 | ArrayMaxSize, |
| 6 | IsArray, |
| 7 | IsIn, |
| 8 | IsInt, |
| 9 | IsISO8601, |
| 10 | IsOptional, |
| 11 | IsString, |
| 12 | MaxLength, |
| 13 | Min, |
| 14 | MinLength, |
| 15 | ValidateIf, |
| 16 | ValidateNested, |
| 17 | } from 'class-validator'; |
| 18 | |
| 19 | type ReviewState |
| 20 | type DiffSide |
| 21 | |
| 22 | export class ReviewCommentRequestDTO |
| 23 | @ApiProperty({ example |
| 24 | @IsString() |
| 25 | @MinLength(1) |
| 26 | path: string; |
| 27 | |
| 28 | @ApiProperty({ |
| 29 | enumName: 'DiffSide', |
| 30 | enum: schema.diffSide |
| 31 | description: |
| 32 | '`deletions` is the base side of the diff, `additions` the head side.', |
| 33 | }) |
| 34 | @IsIn(schema. |
| 35 | side: DiffSide |
| 36 | |
| 37 | @ApiProperty({ |
| 38 | description: |
| 39 | 'Line number on that side of the diff; the last line of a range.', |
| 40 | }) |
| 41 | @IsInt() |
| 42 | @Min(1) |
| 43 | line: number; |
| 44 | |
| 45 | @ApiPropertyOptional({ |
| 46 | enumName: 'DiffSide', |
| 47 | enum: schema.diffSide |
| 48 | description: 'Side of the first line of a range. Defaults to `side`.', |
| 49 | }) |
| 50 | @IsIn(schema. |
| 51 | @IsOptional() |
| 52 | startSide?: DiffSide |
| 53 | |
| 54 | @ApiPropertyOptional({ |
| 55 | description: 'First line of a range, for a comment on several lines.', |
| 56 | }) |
| 57 | @IsInt() |
| 58 | @Min(1) |
| 59 | @IsOptional() |
| 60 | startLine?: number |
| 61 | |
| 62 | @ApiProperty() |
| 63 | @IsString() |
| 64 | @MinLength(1) |
| 65 | @MaxLength(20000) |
| 66 | body: string; |
| 67 | } |
| 68 | |
| 69 | export class CreateReviewRequestDTO |
| 70 | @ApiProperty({ |
| 71 | enumName: 'PullRequestReviewState', |
| 72 | enum: schema.pullRequestReviewState |
| 73 | description: |
| 74 | 'Submits your pending review, if you have one, together with any comments given here.', |
| 75 | }) |
| 76 | @IsIn(schema. |
| 77 | state: ReviewState |
| 78 | |
| 79 | @ApiPropertyOptional() |
| 80 | @IsString() |
| 81 | @IsOptional() |
| 82 | @MaxLength(20000) |
| 83 | body?: string |
| 84 | |
| 85 | @ApiPropertyOptional({ type |
| 86 | @IsArray() |
| 87 | @IsOptional() |
| 88 | @ArrayMaxSize(100) |
| 89 | @ValidateNested({ each |
| 90 | @Type(() => |
| 91 | comments?: ReviewCommentRequestDTO |
| 92 | } |
| 93 | |
| 94 | export class ReviewCommentBodyDTO |
| 95 | @ApiProperty() |
| 96 | @IsString() |
| 97 | @MinLength(1) |
| 98 | @MaxLength(20000) |
| 99 | body: string; |
| 100 | } |
| 101 | |
| 102 | export class UpdateReviewRequestDTO |
| 103 | @ApiProperty({ |
| 104 | type: String, |
| 105 | nullable: true, |
| 106 | description: '`null` clears the summary.', |
| 107 | }) |
| 108 | @IsString() |
| 109 | @ValidateIf((_ |
| 110 | @MaxLength(20000) |
| 111 | body: string |
| 112 | } |
| 113 | |
| 114 | export class DismissReviewRequestDTO |
| 115 | @ApiProperty({ example |
| 116 | @IsString() |
| 117 | @MinLength(1) |
| 118 | @MaxLength(1000) |
| 119 | message: string; |
| 120 | } |
| 121 | |
| 122 | export class ReviewReplyDTO |
| 123 | @ApiProperty() |
| 124 | @IsString() |
| 125 | id: string; |
| 126 | |
| 127 | @ApiProperty() |
| 128 | @IsString() |
| 129 | body: string; |
| 130 | |
| 131 | @ApiProperty() |
| 132 | @IsString() |
| 133 | authorUsername: string; |
| 134 | |
| 135 | @ApiProperty({ type |
| 136 | @IsString() |
| 137 | @IsOptional() |
| 138 | authorImage: string |
| 139 | |
| 140 | @ApiProperty() |
| 141 | @IsISO8601() |
| 142 | createdAt: string; |
| 143 | |
| 144 | @ApiProperty() |
| 145 | @IsISO8601() |
| 146 | updatedAt: string; |
| 147 | } |
| 148 | |
| 149 | export class ReviewThreadDTO |
| 150 | @ApiProperty() |
| 151 | @IsString() |
| 152 | path: string; |
| 153 | |
| 154 | @ApiProperty({ enumName |
| 155 | @IsIn(schema. |
| 156 | side: DiffSide |
| 157 | |
| 158 | @ApiProperty() |
| 159 | @IsInt() |
| 160 | line: number; |
| 161 | |
| 162 | @ApiProperty({ |
| 163 | enumName: 'DiffSide', |
| 164 | enum: schema.diffSide |
| 165 | nullable: true, |
| 166 | }) |
| 167 | @IsIn(schema. |
| 168 | @IsOptional() |
| 169 | startSide: DiffSide |
| 170 | |
| 171 | @ApiProperty({ |
| 172 | type: Number, |
| 173 | nullable: true, |
| 174 | description: 'First line of a range; null for a single line.', |
| 175 | }) |
| 176 | @IsInt() |
| 177 | @IsOptional() |
| 178 | startLine: number |
| 179 | |
| 180 | @ApiProperty({ |
| 181 | description: |
| 182 | 'Head commit the comment was made on. Once the head moves on, the comment is outdated.', |
| 183 | }) |
| 184 | @IsString() |
| 185 | commitSha: string; |
| 186 | |
| 187 | @ApiProperty({ |
| 188 | type: String, |
| 189 | nullable: true, |
| 190 | description: |
| 191 | 'The rows of the diff the comment points at, as a hunk with its own `@@` header, kept as they were when it was written.', |
| 192 | }) |
| 193 | @IsString() |
| 194 | @IsOptional() |
| 195 | diffHunk: string |
| 196 | |
| 197 | @ApiProperty({ type |
| 198 | @ValidateNested({ each |
| 199 | @Type(() => |
| 200 | replies: ReviewReplyDTO |
| 201 | } |
| 202 | |
| 203 | export class PullRequestReviewDTO |
| 204 | @ApiProperty({ enum |
| 205 | @IsIn(['review' |
| 206 | kind: 'review |
| 207 | |
| 208 | @ApiProperty() |
| 209 | @IsString() |
| 210 | id: string; |
| 211 | |
| 212 | @ApiProperty({ |
| 213 | enumName: 'PullRequestReviewState', |
| 214 | enum: schema.pullRequestReviewState |
| 215 | nullable: true, |
| 216 | description: 'Null while the review is pending.', |
| 217 | }) |
| 218 | @IsIn(schema. |
| 219 | @IsOptional() |
| 220 | state: ReviewState |
| 221 | |
| 222 | @ApiProperty({ type |
| 223 | @IsString() |
| 224 | @IsOptional() |
| 225 | body: string |
| 226 | |
| 227 | @ApiProperty() |
| 228 | @IsString() |
| 229 | authorUsername: string; |
| 230 | |
| 231 | @ApiProperty({ type |
| 232 | @IsString() |
| 233 | @IsOptional() |
| 234 | authorImage: string |
| 235 | |
| 236 | @ApiProperty({ |
| 237 | description: |
| 238 | 'Head commit when the review was submitted, or started if it is pending.', |
| 239 | }) |
| 240 | @IsString() |
| 241 | commitSha: string; |
| 242 | |
| 243 | @ApiProperty({ |
| 244 | type: String, |
| 245 | nullable: true, |
| 246 | description: |
| 247 | 'Null once that account is deleted, even though the review stays dismissed.', |
| 248 | }) |
| 249 | @IsString() |
| 250 | @IsOptional() |
| 251 | dismissedByUsername: string |
| 252 | |
| 253 | @ApiProperty({ |
| 254 | type: String, |
| 255 | nullable: true, |
| 256 | description: |
| 257 | 'Set once the review is dismissed; a dismissed verdict no longer counts.', |
| 258 | }) |
| 259 | @IsString() |
| 260 | @IsOptional() |
| 261 | dismissalMessage: string |
| 262 | |
| 263 | @ApiProperty({ type |
| 264 | @ValidateNested({ each |
| 265 | @Type(() => |
| 266 | comments: ReviewThreadDTO |
| 267 | |
| 268 | @ApiProperty({ |
| 269 | description: 'When the review was submitted, or started if it is pending.', |
| 270 | }) |
| 271 | @IsISO8601() |
| 272 | createdAt: string; |
| 273 | } |
| 274 | |
| 275 | export class GetPendingReviewResponseDTO |
| 276 | @ApiProperty({ |
| 277 | type: PullRequestReviewDTO, |
| 278 | nullable: true, |
| 279 | description: 'Your unsubmitted review, visible to nobody else.', |
| 280 | }) |
| 281 | @ValidateNested() |
| 282 | @Type(() => |
| 283 | @IsOptional() |
| 284 | review: PullRequestReviewDTO |
| 285 | } |
| 286 | |
| 287 | export class ReviewerDTO |
| 288 | @ApiProperty() |
| 289 | @IsString() |
| 290 | username: string; |
| 291 | |
| 292 | @ApiProperty({ type |
| 293 | @IsString() |
| 294 | @IsOptional() |
| 295 | image: string |
| 296 | |
| 297 | @ApiProperty({ |
| 298 | enum: ['approved', |
| 299 | description: |
| 300 | "The reviewer's latest verdict, unless it was dismissed. Comment-only reviews do not change it.", |
| 301 | }) |
| 302 | @IsIn(['approved' |
| 303 | state: 'approved |
| 304 | } |
| 305 | |
| 306 | export class ApplySuggestionResponseDTO |
| 307 | @ApiProperty({ description |
| 308 | @IsString() |
| 309 | commitSha: string; |
| 310 | } |