| 1 | import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; |
| 2 | import { Type } |
| 3 | import { |
| 4 | IsBoolean, |
| 5 | IsIn, |
| 6 | IsInt, |
| 7 | IsNotEmpty, |
| 8 | IsOptional, |
| 9 | IsString, |
| 10 | Max, |
| 11 | MaxLength, |
| 12 | Min, |
| 13 | ValidateNested, |
| 14 | } from 'class-validator'; |
| 15 | |
| 16 | import { CommitDTO } |
| 17 | |
| 18 | export class GetPullRequestCommitsQueryDTO |
| 19 | @ApiPropertyOptional({ |
| 20 | description: 'Sha to resume from, taken from a previous `nextCursor`.', |
| 21 | }) |
| 22 | @IsString() |
| 23 | @IsOptional() |
| 24 | cursor?: string |
| 25 | |
| 26 | @ApiPropertyOptional({ minimum |
| 27 | @Type(() => |
| 28 | @IsInt() |
| 29 | @Min(1) |
| 30 | @Max(100) |
| 31 | @IsOptional() |
| 32 | limit?: number |
| 33 | } |
| 34 | |
| 35 | export class GetPullRequestCommitsResponseDTO |
| 36 | @ApiProperty({ type |
| 37 | @ValidateNested({ each |
| 38 | @Type(() => |
| 39 | commits: CommitDTO |
| 40 | |
| 41 | @ApiProperty() |
| 42 | @IsInt() |
| 43 | total: number; |
| 44 | |
| 45 | @ApiProperty({ type |
| 46 | @IsString() |
| 47 | @IsOptional() |
| 48 | nextCursor: string |
| 49 | } |
| 50 | |
| 51 | export class PullRequestFileDTO |
| 52 | @ApiProperty({ description |
| 53 | @IsString() |
| 54 | status: string; |
| 55 | |
| 56 | @ApiProperty() |
| 57 | @IsString() |
| 58 | path: string; |
| 59 | |
| 60 | @ApiProperty() |
| 61 | @IsInt() |
| 62 | additions: number; |
| 63 | |
| 64 | @ApiProperty() |
| 65 | @IsInt() |
| 66 | deletions: number; |
| 67 | |
| 68 | @ApiProperty({ description |
| 69 | @IsBoolean() |
| 70 | binary: boolean; |
| 71 | } |
| 72 | |
| 73 | export class GetPullRequestFilesResponseDTO |
| 74 | @ApiProperty({ |
| 75 | description: |
| 76 | 'Commit the diff is taken from, the merge base of the two branches.', |
| 77 | }) |
| 78 | @IsString() |
| 79 | from: string; |
| 80 | |
| 81 | @ApiProperty({ description |
| 82 | @IsString() |
| 83 | to: string; |
| 84 | |
| 85 | @ApiProperty({ type |
| 86 | @ValidateNested({ each |
| 87 | @Type(() => |
| 88 | files: PullRequestFileDTO |
| 89 | } |
| 90 | |
| 91 | export class GetPullRequestPatchQueryDTO |
| 92 | @ApiPropertyOptional({ description |
| 93 | @IsString() |
| 94 | @IsOptional() |
| 95 | @MaxLength(4096) |
| 96 | path?: string |
| 97 | } |
| 98 | |
| 99 | export const MERGE_METHODS = |
| 100 | export type MergeMethod |
| 101 | |
| 102 | export class MergePullRequestRequestDTO |
| 103 | @ApiPropertyOptional({ |
| 104 | description: |
| 105 | 'Subject of the merge or squash commit. A rebase keeps every commit message and ignores it.', |
| 106 | }) |
| 107 | @IsString() |
| 108 | @IsNotEmpty() |
| 109 | @IsOptional() |
| 110 | @MaxLength(200) |
| 111 | title?: string |
| 112 | |
| 113 | @ApiPropertyOptional({ |
| 114 | description: |
| 115 | "Body of the squash commit. Defaults to the head's commit messages; an empty string leaves the body out. Ignored by the other methods.", |
| 116 | }) |
| 117 | @IsString() |
| 118 | @IsOptional() |
| 119 | @MaxLength(65536) |
| 120 | message?: string |
| 121 | |
| 122 | @ApiPropertyOptional({ |
| 123 | enumName: 'MergeMethod', |
| 124 | enum: MERGE_METHODS, |
| 125 | default: 'merge', |
| 126 | description: |
| 127 | '`merge` adds a merge commit, `squash` lands the whole request as one commit, `rebase` replays each of its commits onto the base.', |
| 128 | }) |
| 129 | @IsIn(MERGE_METHODS) |
| 130 | @IsOptional() |
| 131 | method?: MergeMethod |
| 132 | } |
| 133 | |
| 134 | export class MergePullRequestResponseDTO |
| 135 | @ApiProperty({ |
| 136 | description: |
| 137 | 'The new base tip: the merge commit, the squashed commit, or the last rebased one.', |
| 138 | }) |
| 139 | @IsString() |
| 140 | mergeCommitSha: string; |
| 141 | |
| 142 | @ApiProperty({ description |
| 143 | @IsInt() |
| 144 | seq: number; |
| 145 | } |