| 1 | import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; |
| 2 | import { |
| 3 | IsISO8601, |
| 4 | IsInt, |
| 5 | IsOptional, |
| 6 | IsString, |
| 7 | Max, |
| 8 | MaxLength, |
| 9 | Min, |
| 10 | Validate, |
| 11 | ValidateNested, |
| 12 | } from 'class-validator'; |
| 13 | import { Type } |
| 14 | |
| 15 | import { MAX_TREE_PATH_LENGTH } |
| 16 | import { SafeTreePathConstraint } |
| 17 | |
| 18 | export class GetRepositoryCommitsQueryDTO |
| 19 | @ApiPropertyOptional({ |
| 20 | description: 'Branch or commit sha to walk. Omit for the default branch.', |
| 21 | example: 'main', |
| 22 | }) |
| 23 | @IsString() |
| 24 | @IsOptional() |
| 25 | ref?: string |
| 26 | |
| 27 | @ApiPropertyOptional({ |
| 28 | description: 'Only commits touching this path.', |
| 29 | example: 'apps/api', |
| 30 | maxLength: MAX_TREE_PATH_LENGTH, |
| 31 | }) |
| 32 | @IsString() |
| 33 | @MaxLength(MAX_TREE_PATH_LENGTH) |
| 34 | @Validate(SafeTreePathConstraint) |
| 35 | @IsOptional() |
| 36 | path?: string |
| 37 | |
| 38 | @ApiPropertyOptional({ |
| 39 | description: 'Sha to resume from, taken from a previous `nextCursor`.', |
| 40 | }) |
| 41 | @IsString() |
| 42 | @IsOptional() |
| 43 | cursor?: string |
| 44 | |
| 45 | @ApiPropertyOptional({ minimum |
| 46 | @Type(() => |
| 47 | @IsInt() |
| 48 | @Min(1) |
| 49 | @Max(100) |
| 50 | @IsOptional() |
| 51 | limit?: number |
| 52 | } |
| 53 | |
| 54 | export class CommitVerificationDTO |
| 55 | @ApiProperty({ |
| 56 | description: |
| 57 | 'True only when the signature checks out *and* the signing key belongs ' + |
| 58 | "to an account that has verified the commit's author address.", |
| 59 | }) |
| 60 | verified: boolean; |
| 61 | |
| 62 | @ApiProperty({ description |
| 63 | @IsString() |
| 64 | reason: string; |
| 65 | |
| 66 | @ApiProperty({ |
| 67 | description: 'Long key id the signature names, lowercase hex.', |
| 68 | }) |
| 69 | @IsString() |
| 70 | keyId: string; |
| 71 | } |
| 72 | |
| 73 | export class CommitDTO |
| 74 | @ApiProperty({ description |
| 75 | @IsString() |
| 76 | sha: string; |
| 77 | |
| 78 | @ApiProperty({ |
| 79 | description: 'Commit subject, the first line of the message.', |
| 80 | }) |
| 81 | @IsString() |
| 82 | subject: string; |
| 83 | |
| 84 | @ApiProperty({ |
| 85 | description: 'The rest of the message. Empty when there is none.', |
| 86 | }) |
| 87 | @IsString() |
| 88 | body: string; |
| 89 | |
| 90 | @ApiProperty() |
| 91 | @IsString() |
| 92 | authorName: string; |
| 93 | |
| 94 | @ApiProperty() |
| 95 | @IsString() |
| 96 | authorEmail: string; |
| 97 | |
| 98 | @ApiProperty({ description |
| 99 | @IsISO8601() |
| 100 | committedAt: string; |
| 101 | |
| 102 | @ApiProperty({ |
| 103 | type: CommitVerificationDTO, |
| 104 | nullable: true, |
| 105 | description: 'Signature status, or `null` when the commit carries none.', |
| 106 | }) |
| 107 | @ValidateNested() |
| 108 | @Type(() => |
| 109 | @IsOptional() |
| 110 | verification: CommitVerificationDTO |
| 111 | } |
| 112 | |
| 113 | export class GetRepositoryCommitsResponseDTO |
| 114 | @ApiProperty({ |
| 115 | description: 'Ref that was walked, always fully qualified.', |
| 116 | example: 'refs/heads/main', |
| 117 | }) |
| 118 | @IsString() |
| 119 | ref: string; |
| 120 | |
| 121 | @ApiProperty({ |
| 122 | description: |
| 123 | "Position of this page's first commit in the walk, 1-based. `0` when the page is empty.", |
| 124 | example: 41, |
| 125 | }) |
| 126 | @IsInt() |
| 127 | from: number; |
| 128 | |
| 129 | @ApiProperty({ |
| 130 | description: |
| 131 | "Position of this page's last commit. `0` when the page is empty.", |
| 132 | example: 60, |
| 133 | }) |
| 134 | @IsInt() |
| 135 | to: number; |
| 136 | |
| 137 | @ApiProperty({ |
| 138 | description: |
| 139 | 'Commits the walk can reach in total, narrowed by `path` when one is given.', |
| 140 | example: 128, |
| 141 | }) |
| 142 | @IsInt() |
| 143 | total: number; |
| 144 | |
| 145 | @ApiProperty({ type |
| 146 | @ValidateNested({ each |
| 147 | @Type(() => |
| 148 | commits: CommitDTO |
| 149 | |
| 150 | @ApiProperty({ |
| 151 | type: String, |
| 152 | nullable: true, |
| 153 | description: |
| 154 | 'Pass back as `cursor` for the next page. `null` on the last page.', |
| 155 | }) |
| 156 | @IsString() |
| 157 | @IsOptional() |
| 158 | nextCursor: string |
| 159 | } |
| 160 | |
| 161 | export class CommitFileDTO |
| 162 | @ApiProperty({ description |
| 163 | @IsString() |
| 164 | status: string; |
| 165 | |
| 166 | @ApiProperty() |
| 167 | @IsString() |
| 168 | path: string; |
| 169 | } |
| 170 | |
| 171 | export class GetRepositoryCommitResponseDTO |
| 172 | @ApiProperty({ |
| 173 | type: [CommitFileDTO], |
| 174 | description: 'Paths this commit changed, against its first parent.', |
| 175 | }) |
| 176 | @ValidateNested({ each |
| 177 | @Type(() => |
| 178 | files: CommitFileDTO |
| 179 | } |
| 180 | |
| 181 | export class GetCommitPatchQueryDTO |
| 182 | @ApiPropertyOptional({ description |
| 183 | @IsString() |
| 184 | @IsOptional() |
| 185 | @MaxLength(4096) |
| 186 | path?: string |
| 187 | } |