| 1 | import { |
| 2 | Body, |
| 3 | Controller, |
| 4 | Delete, |
| 5 | HttpCode, |
| 6 | HttpStatus, |
| 7 | Param, |
| 8 | Post, |
| 9 | Session, |
| 10 | } from '@nestjs/common'; |
| 11 | import { |
| 12 | ApiBadRequestResponse, |
| 13 | ApiConflictResponse, |
| 14 | ApiCreatedResponse, |
| 15 | ApiForbiddenResponse, |
| 16 | ApiNoContentResponse, |
| 17 | ApiNotFoundResponse, |
| 18 | ApiOperation, |
| 19 | ApiTags, |
| 20 | } from '@nestjs/swagger'; |
| 21 | import type { UserSession |
| 22 | |
| 23 | import { ErrorResponseDTO } |
| 24 | import { BranchDTO, CreateBranchRequestDTO |
| 25 | import { RepositoryBranchesService } |
| 26 | |
| 27 | @Controller('repositories/:username/:repo/branches') |
| 28 | @ApiTags('Branches') |
| 29 | export class BranchesController |
| 30 | constructor(private readonly |
| 31 | |
| 32 | @Post() |
| 33 | @ApiOperation({ |
| 34 | summary: 'Create a branch', |
| 35 | description: |
| 36 | 'Needs write access. The branch starts at `from`, or at the default branch.', |
| 37 | }) |
| 38 | @ApiCreatedResponse({ type |
| 39 | @ApiBadRequestResponse({ |
| 40 | description: 'The branch name is not one git accepts.', |
| 41 | type: ErrorResponseDTO, |
| 42 | }) |
| 43 | @ApiForbiddenResponse({ type |
| 44 | @ApiNotFoundResponse({ |
| 45 | description: |
| 46 | 'The repository, or the revision to branch from, does not exist.', |
| 47 | type: ErrorResponseDTO, |
| 48 | }) |
| 49 | @ApiConflictResponse({ |
| 50 | description: 'A branch with that name already exists.', |
| 51 | type: ErrorResponseDTO, |
| 52 | }) |
| 53 | createBranch( |
| 54 | @Param('username' |
| 55 | @Param('repo' |
| 56 | @Body() body |
| 57 | @Session() session |
| 58 | ): Promise<BranchDTO |
| 59 | return this.branches |
| 60 | username, |
| 61 | repo, |
| 62 | requesterId: session.user |
| 63 | body, |
| 64 | }); |
| 65 | } |
| 66 | |
| 67 | @Delete(':branch' |
| 68 | @HttpCode(HttpStatus. |
| 69 | @ApiOperation({ |
| 70 | summary: 'Delete a branch', |
| 71 | description: |
| 72 | 'Needs write access. A branch containing `/` is sent percent-encoded.', |
| 73 | }) |
| 74 | @ApiNoContentResponse() |
| 75 | @ApiForbiddenResponse({ type |
| 76 | @ApiNotFoundResponse({ type |
| 77 | @ApiConflictResponse({ |
| 78 | description: |
| 79 | 'The branch is the default branch, or an open pull request compares it.', |
| 80 | type: ErrorResponseDTO, |
| 81 | }) |
| 82 | deleteBranch( |
| 83 | @Param('username' |
| 84 | @Param('repo' |
| 85 | @Param('branch' |
| 86 | @Session() session |
| 87 | ): Promise<void |
| 88 | return this.branches |
| 89 | username, |
| 90 | repo, |
| 91 | branch, |
| 92 | requesterId: session.user |
| 93 | }); |
| 94 | } |
| 95 | } |