| 1 | import { schema } from '@ghost/db'; |
| 2 | import { ApiProperty, ApiPropertyOptional |
| 3 | import { Type } |
| 4 | import { |
| 5 | IsBoolean, |
| 6 | IsISO8601, |
| 7 | IsIn, |
| 8 | IsInt, |
| 9 | IsOptional, |
| 10 | IsString, |
| 11 | Max, |
| 12 | Min, |
| 13 | ValidateNested, |
| 14 | } from 'class-validator'; |
| 15 | |
| 16 | import { ReviewerDTO } |
| 17 | |
| 18 | export class PullRequestSideDTO |
| 19 | @ApiProperty({ |
| 20 | example: 'bob', |
| 21 | type: String, |
| 22 | nullable: true, |
| 23 | description: 'Null when the repository was deleted.', |
| 24 | }) |
| 25 | @IsString() |
| 26 | @IsOptional() |
| 27 | username: string |
| 28 | |
| 29 | @ApiProperty({ example |
| 30 | @IsString() |
| 31 | @IsOptional() |
| 32 | slug: string |
| 33 | |
| 34 | @ApiProperty({ example |
| 35 | @IsString() |
| 36 | ref: string; |
| 37 | } |
| 38 | |
| 39 | export class PullRequestDTO |
| 40 | @ApiProperty() |
| 41 | @IsString() |
| 42 | id: string; |
| 43 | |
| 44 | @ApiProperty({ |
| 45 | description: 'Per base repository, and what the URL carries.', |
| 46 | }) |
| 47 | @IsInt() |
| 48 | number: number; |
| 49 | |
| 50 | @ApiProperty() |
| 51 | @IsString() |
| 52 | title: string; |
| 53 | |
| 54 | @ApiProperty({ type |
| 55 | @IsString() |
| 56 | @IsOptional() |
| 57 | body: string |
| 58 | |
| 59 | @ApiProperty({ |
| 60 | enumName: 'PullRequestState', |
| 61 | enum: schema.pullRequestState |
| 62 | }) |
| 63 | @IsIn(schema. |
| 64 | state: (typeof |
| 65 | |
| 66 | @ApiProperty({ |
| 67 | description: |
| 68 | 'A draft cannot be merged until it is marked ready for review.', |
| 69 | }) |
| 70 | @IsBoolean() |
| 71 | draft: boolean; |
| 72 | |
| 73 | @ApiProperty({ type |
| 74 | @ValidateNested() |
| 75 | @Type(() => |
| 76 | base: PullRequestSideDTO |
| 77 | |
| 78 | @ApiProperty({ type |
| 79 | @ValidateNested() |
| 80 | @Type(() => |
| 81 | head: PullRequestSideDTO |
| 82 | |
| 83 | @ApiProperty({ description |
| 84 | @IsString() |
| 85 | headSha: string; |
| 86 | |
| 87 | @ApiProperty({ type |
| 88 | @IsString() |
| 89 | @IsOptional() |
| 90 | mergeCommitSha: string |
| 91 | |
| 92 | @ApiProperty() |
| 93 | @IsString() |
| 94 | authorUsername: string; |
| 95 | |
| 96 | @ApiProperty({ type |
| 97 | @IsString() |
| 98 | @IsOptional() |
| 99 | authorImage: string |
| 100 | |
| 101 | @ApiProperty() |
| 102 | @IsISO8601() |
| 103 | createdAt: string; |
| 104 | |
| 105 | @ApiProperty() |
| 106 | @IsISO8601() |
| 107 | updatedAt: string; |
| 108 | } |
| 109 | |
| 110 | export class SquashMessageDTO |
| 111 | @ApiProperty({ example |
| 112 | @IsString() |
| 113 | title: string; |
| 114 | |
| 115 | @ApiProperty({ description |
| 116 | @IsString() |
| 117 | message: string; |
| 118 | } |
| 119 | |
| 120 | export class PullRequestDetailDTO |
| 121 | @ApiProperty({ |
| 122 | type: String, |
| 123 | nullable: true, |
| 124 | description: 'Commit the two branches diverged from.', |
| 125 | }) |
| 126 | @IsString() |
| 127 | @IsOptional() |
| 128 | mergeBase: string |
| 129 | |
| 130 | @ApiProperty({ |
| 131 | description: 'Commits the head branch adds on top of the base.', |
| 132 | }) |
| 133 | @IsInt() |
| 134 | commitCount: number; |
| 135 | |
| 136 | @ApiProperty() |
| 137 | @IsInt() |
| 138 | changedFiles: number; |
| 139 | |
| 140 | @ApiProperty() |
| 141 | @IsInt() |
| 142 | additions: number; |
| 143 | |
| 144 | @ApiProperty() |
| 145 | @IsInt() |
| 146 | deletions: number; |
| 147 | |
| 148 | @ApiProperty({ |
| 149 | description: 'Whether the merge is conflict-free right now. Never cached.', |
| 150 | }) |
| 151 | @IsBoolean() |
| 152 | mergeable: boolean; |
| 153 | |
| 154 | @ApiProperty({ |
| 155 | type: [String], |
| 156 | description: |
| 157 | 'Paths that conflict when the head is merged into the base, right now. Empty when it merges cleanly.', |
| 158 | }) |
| 159 | @IsString({ each |
| 160 | conflicts: string[] |
| 161 | |
| 162 | @ApiProperty({ |
| 163 | type: String, |
| 164 | nullable: true, |
| 165 | description: |
| 166 | 'Why `refs/pull/<number>/head` and `/merge` stopped following the branches: the size limit that refused the last update. Null while they are current.', |
| 167 | }) |
| 168 | @IsString() |
| 169 | @IsOptional() |
| 170 | pullRefsBlocked: string |
| 171 | |
| 172 | @ApiProperty({ |
| 173 | type: SquashMessageDTO, |
| 174 | nullable: true, |
| 175 | description: |
| 176 | 'What a squash merge commits unless the merger rewrites it. Null when there is nothing to merge.', |
| 177 | }) |
| 178 | @ValidateNested() |
| 179 | @Type(() => |
| 180 | @IsOptional() |
| 181 | squash: SquashMessageDTO |
| 182 | |
| 183 | @ApiProperty({ type |
| 184 | @ValidateNested({ each |
| 185 | @Type(() => |
| 186 | reviewers: ReviewerDTO |
| 187 | |
| 188 | @ApiProperty({ |
| 189 | description: |
| 190 | 'True when the requesting user is the author or can write to the base repository.', |
| 191 | }) |
| 192 | @IsBoolean() |
| 193 | viewerCanEdit: boolean; |
| 194 | } |
| 195 | |
| 196 | export class GetPullRequestsQueryDTO |
| 197 | @ApiPropertyOptional({ |
| 198 | enumName: 'PullRequestStateFilter', |
| 199 | enum: [...schema |
| 200 | default: 'open', |
| 201 | }) |
| 202 | @IsIn([...schema |
| 203 | @IsOptional() |
| 204 | state?: ( |
| 205 | |
| 206 | @ApiPropertyOptional() |
| 207 | @IsString() |
| 208 | @IsOptional() |
| 209 | cursor?: string |
| 210 | |
| 211 | @ApiPropertyOptional({ minimum |
| 212 | @Type(() => |
| 213 | @IsInt() |
| 214 | @Min(1) |
| 215 | @Max(100) |
| 216 | @IsOptional() |
| 217 | limit?: number |
| 218 | } |
| 219 | |
| 220 | export class GetPullRequestsResponseDTO |
| 221 | @ApiProperty({ type |
| 222 | @ValidateNested({ each |
| 223 | @Type(() => |
| 224 | pullRequests: PullRequestDTO |
| 225 | |
| 226 | @ApiProperty({ description |
| 227 | @IsInt() |
| 228 | total: number; |
| 229 | |
| 230 | @ApiProperty({ type |
| 231 | @IsString() |
| 232 | @IsOptional() |
| 233 | nextCursor: string |
| 234 | |
| 235 | @ApiProperty() |
| 236 | @IsBoolean() |
| 237 | hasMore: boolean; |
| 238 | } |