| 1 | import { |
| 2 | Body, |
| 3 | Controller, |
| 4 | Delete, |
| 5 | Get, |
| 6 | Param, |
| 7 | ParseIntPipe, |
| 8 | Patch, |
| 9 | Post, |
| 10 | Session, |
| 11 | } from '@nestjs/common'; |
| 12 | import { |
| 13 | ApiBadRequestResponse, |
| 14 | ApiConflictResponse, |
| 15 | ApiCreatedResponse, |
| 16 | ApiNotFoundResponse, |
| 17 | ApiOkResponse, |
| 18 | ApiOperation, |
| 19 | ApiTags, |
| 20 | } from '@nestjs/swagger'; |
| 21 | import type { UserSession |
| 22 | |
| 23 | import { ErrorResponseDTO } |
| 24 | import { |
| 25 | ApplySuggestionResponseDTO, |
| 26 | CreateReviewRequestDTO, |
| 27 | DismissReviewRequestDTO, |
| 28 | GetPendingReviewResponseDTO, |
| 29 | PullRequestReviewDTO, |
| 30 | ReviewCommentBodyDTO, |
| 31 | ReviewCommentRequestDTO, |
| 32 | ReviewReplyDTO, |
| 33 | UpdateReviewRequestDTO, |
| 34 | } from './dto/pull-request-review.dto.js'; |
| 35 | import { ReviewsService } |
| 36 | |
| 37 | @Controller('repositories/:username/:repo/pulls/:number') |
| 38 | @ApiTags('Pull request reviews') |
| 39 | export class ReviewsController |
| 40 | constructor(private readonly |
| 41 | |
| 42 | @Post('reviews' |
| 43 | @ApiOperation({ |
| 44 | summary: 'Comment on, approve or request changes to a pull request', |
| 45 | }) |
| 46 | @ApiCreatedResponse({ type |
| 47 | @ApiBadRequestResponse({ type |
| 48 | @ApiNotFoundResponse({ type |
| 49 | @ApiConflictResponse({ type |
| 50 | submitReview( |
| 51 | @Param('username' |
| 52 | @Param('repo' |
| 53 | @Param('number' |
| 54 | @Body() body |
| 55 | @Session() session |
| 56 | ) { |
| 57 | return this.reviews |
| 58 | username, |
| 59 | repo, |
| 60 | number, |
| 61 | requesterId: session.user |
| 62 | body, |
| 63 | }); |
| 64 | } |
| 65 | |
| 66 | @Get('reviews/pending' |
| 67 | @ApiOperation({ summary |
| 68 | @ApiOkResponse({ type |
| 69 | @ApiNotFoundResponse({ type |
| 70 | getPendingReview( |
| 71 | @Param('username' |
| 72 | @Param('repo' |
| 73 | @Param('number' |
| 74 | @Session() session |
| 75 | ) { |
| 76 | return this.reviews |
| 77 | username, |
| 78 | repo, |
| 79 | number, |
| 80 | requesterId: session.user |
| 81 | }); |
| 82 | } |
| 83 | |
| 84 | @Post('reviews/pending/comments' |
| 85 | @ApiOperation({ summary |
| 86 | @ApiCreatedResponse({ type |
| 87 | @ApiBadRequestResponse({ type |
| 88 | @ApiNotFoundResponse({ type |
| 89 | @ApiConflictResponse({ type |
| 90 | addPendingComment( |
| 91 | @Param('username' |
| 92 | @Param('repo' |
| 93 | @Param('number' |
| 94 | @Body() body |
| 95 | @Session() session |
| 96 | ) { |
| 97 | return this.reviews |
| 98 | username, |
| 99 | repo, |
| 100 | number, |
| 101 | requesterId: session.user |
| 102 | body, |
| 103 | }); |
| 104 | } |
| 105 | |
| 106 | @Delete('reviews/pending' |
| 107 | @ApiOperation({ summary |
| 108 | @ApiOkResponse({ schema |
| 109 | @ApiNotFoundResponse({ type |
| 110 | discardPendingReview( |
| 111 | @Param('username' |
| 112 | @Param('repo' |
| 113 | @Param('number' |
| 114 | @Session() session |
| 115 | ) { |
| 116 | return this.reviews |
| 117 | username, |
| 118 | repo, |
| 119 | number, |
| 120 | requesterId: session.user |
| 121 | }); |
| 122 | } |
| 123 | |
| 124 | @Patch('reviews/:reviewId' |
| 125 | @ApiOperation({ summary |
| 126 | @ApiOkResponse({ type |
| 127 | @ApiNotFoundResponse({ type |
| 128 | updateReview( |
| 129 | @Param('username' |
| 130 | @Param('repo' |
| 131 | @Param('number' |
| 132 | @Param('reviewId' |
| 133 | @Body() body |
| 134 | @Session() session |
| 135 | ) { |
| 136 | return this.reviews |
| 137 | username, |
| 138 | repo, |
| 139 | number, |
| 140 | reviewId, |
| 141 | requesterId: session.user |
| 142 | body: body.body |
| 143 | }); |
| 144 | } |
| 145 | |
| 146 | @Post('reviews/:reviewId/dismiss' |
| 147 | @ApiOperation({ summary |
| 148 | @ApiCreatedResponse({ type |
| 149 | @ApiNotFoundResponse({ type |
| 150 | @ApiConflictResponse({ type |
| 151 | dismissReview( |
| 152 | @Param('username' |
| 153 | @Param('repo' |
| 154 | @Param('number' |
| 155 | @Param('reviewId' |
| 156 | @Body() body |
| 157 | @Session() session |
| 158 | ) { |
| 159 | return this.reviews |
| 160 | username, |
| 161 | repo, |
| 162 | number, |
| 163 | reviewId, |
| 164 | requesterId: session.user |
| 165 | message: body.message |
| 166 | }); |
| 167 | } |
| 168 | |
| 169 | @Post('comments/:commentId/replies' |
| 170 | @ApiOperation({ summary |
| 171 | @ApiCreatedResponse({ type |
| 172 | @ApiNotFoundResponse({ type |
| 173 | @ApiConflictResponse({ type |
| 174 | replyToComment( |
| 175 | @Param('username' |
| 176 | @Param('repo' |
| 177 | @Param('number' |
| 178 | @Param('commentId' |
| 179 | @Body() body |
| 180 | @Session() session |
| 181 | ) { |
| 182 | return this.reviews |
| 183 | username, |
| 184 | repo, |
| 185 | number, |
| 186 | commentId, |
| 187 | requesterId: session.user |
| 188 | body: body.body |
| 189 | }); |
| 190 | } |
| 191 | |
| 192 | @Patch('comments/:commentId' |
| 193 | @ApiOperation({ summary |
| 194 | @ApiOkResponse({ type |
| 195 | @ApiNotFoundResponse({ type |
| 196 | updateComment( |
| 197 | @Param('username' |
| 198 | @Param('repo' |
| 199 | @Param('number' |
| 200 | @Param('commentId' |
| 201 | @Body() body |
| 202 | @Session() session |
| 203 | ) { |
| 204 | return this.reviews |
| 205 | username, |
| 206 | repo, |
| 207 | number, |
| 208 | commentId, |
| 209 | requesterId: session.user |
| 210 | body: body.body |
| 211 | }); |
| 212 | } |
| 213 | |
| 214 | @Delete('comments/:commentId' |
| 215 | @ApiOperation({ |
| 216 | summary: 'Delete a line comment and its replies, or one reply', |
| 217 | }) |
| 218 | @ApiOkResponse({ schema |
| 219 | @ApiNotFoundResponse({ type |
| 220 | deleteComment( |
| 221 | @Param('username' |
| 222 | @Param('repo' |
| 223 | @Param('number' |
| 224 | @Param('commentId' |
| 225 | @Session() session |
| 226 | ) { |
| 227 | return this.reviews |
| 228 | username, |
| 229 | repo, |
| 230 | number, |
| 231 | commentId, |
| 232 | requesterId: session.user |
| 233 | }); |
| 234 | } |
| 235 | |
| 236 | @Post('comments/:commentId/apply' |
| 237 | @ApiOperation({ |
| 238 | summary: "Commit a comment's suggested change to the head branch", |
| 239 | }) |
| 240 | @ApiCreatedResponse({ type |
| 241 | @ApiBadRequestResponse({ type |
| 242 | @ApiNotFoundResponse({ type |
| 243 | @ApiConflictResponse({ type |
| 244 | applySuggestion( |
| 245 | @Param('username' |
| 246 | @Param('repo' |
| 247 | @Param('number' |
| 248 | @Param('commentId' |
| 249 | @Session() session |
| 250 | ) { |
| 251 | return this.reviews |
| 252 | username, |
| 253 | repo, |
| 254 | number, |
| 255 | commentId, |
| 256 | requesterId: session.user |
| 257 | }); |
| 258 | } |
| 259 | } |