| 1 | import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; |
| 2 | import { |
| 3 | IsBoolean, |
| 4 | IsIn, |
| 5 | IsOptional, |
| 6 | IsString, |
| 7 | MaxLength, |
| 8 | MinLength, |
| 9 | ValidateIf, |
| 10 | } from 'class-validator'; |
| 11 | |
| 12 | const MAKE_LATEST = [ |
| 13 | |
| 14 | /** GitHub's create-release body. */ |
| 15 | export class GithubCreateReleaseDTO |
| 16 | @ApiProperty() |
| 17 | @IsString() |
| 18 | @MinLength(1) |
| 19 | @MaxLength(250) |
| 20 | tag_name: string; |
| 21 | |
| 22 | @ApiPropertyOptional({ |
| 23 | description: |
| 24 | 'Branch or commit SHA a new tag is created from. Defaults to the default branch; unused when the tag already exists.', |
| 25 | }) |
| 26 | @IsOptional() |
| 27 | @IsString() |
| 28 | @MaxLength(250) |
| 29 | target_commitish?: string |
| 30 | |
| 31 | @ApiPropertyOptional() |
| 32 | @IsOptional() |
| 33 | @IsString() |
| 34 | @MaxLength(200) |
| 35 | name?: string |
| 36 | |
| 37 | @ApiPropertyOptional() |
| 38 | @IsOptional() |
| 39 | @IsString() |
| 40 | @MaxLength(100000) |
| 41 | body?: string |
| 42 | |
| 43 | @ApiPropertyOptional({ default |
| 44 | @IsOptional() |
| 45 | @IsBoolean() |
| 46 | draft?: boolean |
| 47 | |
| 48 | @ApiPropertyOptional({ default |
| 49 | @IsOptional() |
| 50 | @IsBoolean() |
| 51 | prerelease?: boolean |
| 52 | |
| 53 | @ApiPropertyOptional({ |
| 54 | description: |
| 55 | 'Ghost has no discussions, so any category is one that does not exist: 404, as GitHub answers an unknown category.', |
| 56 | }) |
| 57 | @IsOptional() |
| 58 | @IsString() |
| 59 | discussion_category_name?: string |
| 60 | |
| 61 | @ApiPropertyOptional({ |
| 62 | default: false, |
| 63 | description: 'Ghost cannot generate notes; `true` is refused with 422.', |
| 64 | }) |
| 65 | @IsOptional() |
| 66 | @IsBoolean() |
| 67 | generate_release_notes?: boolean |
| 68 | |
| 69 | @ApiPropertyOptional({ |
| 70 | enum: MAKE_LATEST, |
| 71 | default: 'true', |
| 72 | description: |
| 73 | 'Accepted and ignored: Ghost computes the latest release as the newest published one that is not a prerelease.', |
| 74 | }) |
| 75 | @IsOptional() |
| 76 | @IsIn(MAKE_LATEST) |
| 77 | make_latest?: ( |
| 78 | } |
| 79 | |
| 80 | /** GitHub's update-release body. */ |
| 81 | export class GithubUpdateReleaseDTO |
| 82 | @ApiPropertyOptional({ |
| 83 | description: 'Moving a release to another tag is refused with 422.', |
| 84 | }) |
| 85 | @IsOptional() |
| 86 | @IsString() |
| 87 | tag_name?: string |
| 88 | |
| 89 | @ApiPropertyOptional({ description |
| 90 | @IsOptional() |
| 91 | @IsString() |
| 92 | target_commitish?: string |
| 93 | |
| 94 | @ApiPropertyOptional({ type |
| 95 | @IsOptional() |
| 96 | @ValidateIf((_ |
| 97 | @IsString() |
| 98 | @MaxLength(200) |
| 99 | name?: string |
| 100 | |
| 101 | @ApiPropertyOptional({ type |
| 102 | @IsOptional() |
| 103 | @ValidateIf((_ |
| 104 | @IsString() |
| 105 | @MaxLength(100000) |
| 106 | body?: string |
| 107 | |
| 108 | @ApiPropertyOptional() |
| 109 | @IsOptional() |
| 110 | @IsBoolean() |
| 111 | draft?: boolean |
| 112 | |
| 113 | @ApiPropertyOptional() |
| 114 | @IsOptional() |
| 115 | @IsBoolean() |
| 116 | prerelease?: boolean |
| 117 | |
| 118 | @ApiPropertyOptional({ |
| 119 | enum: MAKE_LATEST, |
| 120 | description: 'Accepted and ignored, as on create.', |
| 121 | }) |
| 122 | @IsOptional() |
| 123 | @IsIn(MAKE_LATEST) |
| 124 | make_latest?: ( |
| 125 | |
| 126 | @ApiPropertyOptional({ description |
| 127 | @IsOptional() |
| 128 | @IsString() |
| 129 | discussion_category_name?: string |
| 130 | } |
| 131 | |
| 132 | /** GitHub's upload query: the asset's file name and an optional label. */ |
| 133 | export class GithubUploadReleaseAssetQueryDTO |
| 134 | @ApiProperty() |
| 135 | @IsString() |
| 136 | @MaxLength(255) |
| 137 | name: string; |
| 138 | |
| 139 | @ApiPropertyOptional() |
| 140 | @IsOptional() |
| 141 | @IsString() |
| 142 | @MaxLength(255) |
| 143 | label?: string |
| 144 | } |
| 145 | |
| 146 | /** GitHub's update-release-asset body. `state` is undocumented and dropped by the whitelist. */ |
| 147 | export class GithubUpdateReleaseAssetDTO |
| 148 | @ApiPropertyOptional() |
| 149 | @IsOptional() |
| 150 | @IsString() |
| 151 | @MaxLength(255) |
| 152 | name?: string |
| 153 | |
| 154 | @ApiPropertyOptional({ description |
| 155 | @IsOptional() |
| 156 | @IsString() |
| 157 | @MaxLength(255) |
| 158 | label?: string |
| 159 | } |