| 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 | export class PullRequestSideDTO |
| 15 | @ApiProperty({ example |
| 16 | @IsString() |
| 17 | username: string; |
| 18 | |
| 19 | @ApiProperty({ example |
| 20 | @IsString() |
| 21 | slug: string; |
| 22 | |
| 23 | @ApiProperty({ example |
| 24 | @IsString() |
| 25 | ref: string; |
| 26 | } |
| 27 | |
| 28 | export class PullRequestDTO |
| 29 | @ApiProperty() |
| 30 | @IsString() |
| 31 | id: string; |
| 32 | |
| 33 | @ApiProperty({ |
| 34 | description: 'Per base repository, and what the URL carries.', |
| 35 | }) |
| 36 | @IsInt() |
| 37 | number: number; |
| 38 | |
| 39 | @ApiProperty() |
| 40 | @IsString() |
| 41 | title: string; |
| 42 | |
| 43 | @ApiProperty({ type |
| 44 | @IsString() |
| 45 | @IsOptional() |
| 46 | body: string |
| 47 | |
| 48 | @ApiProperty({ |
| 49 | enumName: 'PullRequestState', |
| 50 | enum: schema.pullRequestState |
| 51 | }) |
| 52 | @IsIn(schema. |
| 53 | state: (typeof |
| 54 | |
| 55 | @ApiProperty({ type |
| 56 | @ValidateNested() |
| 57 | @Type(() => |
| 58 | base: PullRequestSideDTO |
| 59 | |
| 60 | @ApiProperty({ type |
| 61 | @ValidateNested() |
| 62 | @Type(() => |
| 63 | head: PullRequestSideDTO |
| 64 | |
| 65 | @ApiProperty({ description |
| 66 | @IsString() |
| 67 | headSha: string; |
| 68 | |
| 69 | @ApiProperty({ type |
| 70 | @IsString() |
| 71 | @IsOptional() |
| 72 | mergeCommitSha: string |
| 73 | |
| 74 | @ApiProperty() |
| 75 | @IsString() |
| 76 | authorUsername: string; |
| 77 | |
| 78 | @ApiProperty() |
| 79 | @IsISO8601() |
| 80 | createdAt: string; |
| 81 | |
| 82 | @ApiProperty() |
| 83 | @IsISO8601() |
| 84 | updatedAt: string; |
| 85 | } |
| 86 | |
| 87 | export class PullRequestDetailDTO |
| 88 | @ApiProperty({ |
| 89 | type: String, |
| 90 | nullable: true, |
| 91 | description: 'Commit the two branches diverged from.', |
| 92 | }) |
| 93 | @IsString() |
| 94 | @IsOptional() |
| 95 | mergeBase: string |
| 96 | |
| 97 | @ApiProperty({ |
| 98 | description: 'Commits the head branch adds on top of the base.', |
| 99 | }) |
| 100 | @IsInt() |
| 101 | commitCount: number; |
| 102 | |
| 103 | @ApiProperty() |
| 104 | @IsInt() |
| 105 | changedFiles: number; |
| 106 | |
| 107 | @ApiProperty() |
| 108 | @IsInt() |
| 109 | additions: number; |
| 110 | |
| 111 | @ApiProperty() |
| 112 | @IsInt() |
| 113 | deletions: number; |
| 114 | |
| 115 | @ApiProperty({ |
| 116 | description: 'Whether the merge is conflict-free right now. Never cached.', |
| 117 | }) |
| 118 | @IsBoolean() |
| 119 | mergeable: boolean; |
| 120 | } |
| 121 | |
| 122 | export class GetPullRequestsQueryDTO |
| 123 | @ApiPropertyOptional({ |
| 124 | enumName: 'PullRequestStateFilter', |
| 125 | enum: [...schema |
| 126 | default: 'open', |
| 127 | }) |
| 128 | @IsIn([...schema |
| 129 | @IsOptional() |
| 130 | state?: ( |
| 131 | |
| 132 | @ApiPropertyOptional() |
| 133 | @IsString() |
| 134 | @IsOptional() |
| 135 | cursor?: string |
| 136 | |
| 137 | @ApiPropertyOptional({ minimum |
| 138 | @Type(() => |
| 139 | @IsInt() |
| 140 | @IsOptional() |
| 141 | limit?: number |
| 142 | } |
| 143 | |
| 144 | export class GetPullRequestsResponseDTO |
| 145 | @ApiProperty({ type |
| 146 | @ValidateNested({ each |
| 147 | @Type(() => |
| 148 | pullRequests: PullRequestDTO |
| 149 | |
| 150 | @ApiProperty({ description |
| 151 | @IsInt() |
| 152 | total: number; |
| 153 | |
| 154 | @ApiProperty({ type |
| 155 | @IsString() |
| 156 | @IsOptional() |
| 157 | nextCursor: string |
| 158 | |
| 159 | @ApiProperty() |
| 160 | @IsBoolean() |
| 161 | hasMore: boolean; |
| 162 | } |