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