| 1 | import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; |
| 2 | import { Transform } |
| 3 | import { |
| 4 | Allow, |
| 5 | ArrayMaxSize, |
| 6 | IsArray, |
| 7 | IsIn, |
| 8 | IsISO8601, |
| 9 | IsOptional, |
| 10 | IsString, |
| 11 | MaxLength, |
| 12 | MinLength, |
| 13 | } from 'class-validator'; |
| 14 | |
| 15 | /** GitHub's issue list query; `milestone`, `mentioned`, `type` and `issue_field_values` are dropped by the whitelist, as GitHub ignores filters it cannot apply. */ |
| 16 | export class GithubListIssuesQueryDTO |
| 17 | @ApiPropertyOptional({ enum |
| 18 | @IsOptional() |
| 19 | @IsIn(['open' |
| 20 | state?: 'open |
| 21 | |
| 22 | @ApiPropertyOptional({ description |
| 23 | @IsOptional() |
| 24 | @IsString() |
| 25 | labels?: string |
| 26 | |
| 27 | @ApiPropertyOptional({ description |
| 28 | @IsOptional() |
| 29 | @IsString() |
| 30 | assignee?: string |
| 31 | |
| 32 | @ApiPropertyOptional() |
| 33 | @IsOptional() |
| 34 | @IsString() |
| 35 | creator?: string |
| 36 | |
| 37 | @ApiPropertyOptional({ |
| 38 | enum: ['created', |
| 39 | default: 'created', |
| 40 | }) |
| 41 | @IsOptional() |
| 42 | @IsIn(['created' |
| 43 | sort?: 'created |
| 44 | |
| 45 | @ApiPropertyOptional({ enum |
| 46 | @IsOptional() |
| 47 | @IsIn(['asc' |
| 48 | direction?: 'asc |
| 49 | |
| 50 | @ApiPropertyOptional({ description |
| 51 | @IsOptional() |
| 52 | @IsISO8601() |
| 53 | since?: string |
| 54 | |
| 55 | @ApiPropertyOptional({ default |
| 56 | @Allow() |
| 57 | page?: string |
| 58 | |
| 59 | @ApiPropertyOptional({ default |
| 60 | @Allow() |
| 61 | per_page?: string |
| 62 | } |
| 63 | |
| 64 | /** GitHub's comment list query, for one issue or the whole repository. */ |
| 65 | export class GithubListCommentsQueryDTO |
| 66 | @ApiPropertyOptional({ |
| 67 | enum: ['created', |
| 68 | description: 'Repository-wide list only.', |
| 69 | }) |
| 70 | @IsOptional() |
| 71 | @IsIn(['created' |
| 72 | sort?: 'created |
| 73 | |
| 74 | @ApiPropertyOptional({ |
| 75 | enum: ['asc', |
| 76 | description: 'Repository-wide list only; ignored without `sort`.', |
| 77 | }) |
| 78 | @IsOptional() |
| 79 | @IsIn(['asc' |
| 80 | direction?: 'asc |
| 81 | |
| 82 | @ApiPropertyOptional({ description |
| 83 | @IsOptional() |
| 84 | @IsISO8601() |
| 85 | since?: string |
| 86 | |
| 87 | @ApiPropertyOptional({ default |
| 88 | @Allow() |
| 89 | page?: string |
| 90 | |
| 91 | @ApiPropertyOptional({ default |
| 92 | @Allow() |
| 93 | per_page?: string |
| 94 | } |
| 95 | |
| 96 | /** GitHub's `page` and `per_page` alone, for lists with no filters. */ |
| 97 | export class GithubPageQueryDTO |
| 98 | @ApiPropertyOptional({ default |
| 99 | @Allow() |
| 100 | page?: string |
| 101 | |
| 102 | @ApiPropertyOptional({ default |
| 103 | @Allow() |
| 104 | per_page?: string |
| 105 | } |
| 106 | |
| 107 | /** GitHub's create-issue body. `milestone`, `type` and the rest are accepted; a milestone other than null is refused, as Ghost has none. */ |
| 108 | export class GithubCreateIssueDTO |
| 109 | @ApiProperty({ description |
| 110 | @Transform(({ |
| 111 | @IsString() |
| 112 | @MinLength(1) |
| 113 | @MaxLength(256) |
| 114 | title: string; |
| 115 | |
| 116 | @ApiPropertyOptional({ type |
| 117 | @IsOptional() |
| 118 | @IsString() |
| 119 | body?: string |
| 120 | |
| 121 | @ApiPropertyOptional({ description |
| 122 | @IsOptional() |
| 123 | @IsString() |
| 124 | assignee?: string |
| 125 | |
| 126 | @ApiPropertyOptional({ type |
| 127 | @IsOptional() |
| 128 | @IsArray() |
| 129 | @IsString({ each |
| 130 | assignees?: string |
| 131 | |
| 132 | @ApiPropertyOptional({ |
| 133 | description: 'Names, or objects with a `name`; missing labels are created.', |
| 134 | }) |
| 135 | @Allow() |
| 136 | labels?: unknown |
| 137 | |
| 138 | @ApiPropertyOptional({ description |
| 139 | @Allow() |
| 140 | milestone?: unknown |
| 141 | } |
| 142 | |
| 143 | export class GithubUpdateIssueDTO |
| 144 | @ApiPropertyOptional() |
| 145 | @IsOptional() |
| 146 | @Transform(({ |
| 147 | @IsString() |
| 148 | @MinLength(1) |
| 149 | @MaxLength(256) |
| 150 | title?: string |
| 151 | |
| 152 | @ApiPropertyOptional({ type |
| 153 | @IsOptional() |
| 154 | @IsString() |
| 155 | body?: string |
| 156 | |
| 157 | @ApiPropertyOptional({ enum |
| 158 | @IsOptional() |
| 159 | @IsIn(['open' |
| 160 | state?: 'open |
| 161 | |
| 162 | @ApiPropertyOptional({ |
| 163 | enum: ['completed', |
| 164 | description: 'Accepted and not stored: Ghost records no close reason.', |
| 165 | }) |
| 166 | @IsOptional() |
| 167 | @IsIn(['completed' |
| 168 | state_reason?: string |
| 169 | |
| 170 | @ApiPropertyOptional({ description |
| 171 | @IsOptional() |
| 172 | @IsString() |
| 173 | assignee?: string |
| 174 | |
| 175 | @ApiPropertyOptional({ type |
| 176 | @IsOptional() |
| 177 | @IsArray() |
| 178 | @IsString({ each |
| 179 | assignees?: string |
| 180 | |
| 181 | @ApiPropertyOptional({ |
| 182 | description: |
| 183 | 'Replaces the set. Names, or objects with a `name`; missing labels are created.', |
| 184 | }) |
| 185 | @Allow() |
| 186 | labels?: unknown |
| 187 | |
| 188 | @ApiPropertyOptional({ description |
| 189 | @Allow() |
| 190 | milestone?: unknown |
| 191 | } |
| 192 | |
| 193 | export class GithubAssigneesDTO |
| 194 | @ApiProperty({ type |
| 195 | @IsArray() |
| 196 | @ArrayMaxSize(10) |
| 197 | @IsString({ each |
| 198 | assignees: string[] |
| 199 | } |
| 200 | |
| 201 | export class GithubCommentDTO |
| 202 | @ApiProperty() |
| 203 | @IsString() |
| 204 | @MinLength(1) |
| 205 | body: string; |
| 206 | } |