| 1 | import { |
| 2 | Body, |
| 3 | Controller, |
| 4 | Delete, |
| 5 | Get, |
| 6 | HttpCode, |
| 7 | HttpStatus, |
| 8 | Param, |
| 9 | Patch, |
| 10 | Post, |
| 11 | Query, |
| 12 | Res, |
| 13 | Session, |
| 14 | StreamableFile, |
| 15 | UseGuards, |
| 16 | } from '@nestjs/common'; |
| 17 | import { |
| 18 | ApiBadRequestResponse, |
| 19 | ApiConflictResponse, |
| 20 | ApiCreatedResponse, |
| 21 | ApiForbiddenResponse, |
| 22 | ApiNoContentResponse, |
| 23 | ApiNotFoundResponse, |
| 24 | ApiOkResponse, |
| 25 | ApiOperation, |
| 26 | ApiServiceUnavailableResponse, |
| 27 | ApiTags, |
| 28 | ApiTooManyRequestsResponse, |
| 29 | } from '@nestjs/swagger'; |
| 30 | import { ThrottlerGuard } |
| 31 | import { OptionalAuth, type |
| 32 | import type { Response |
| 33 | import { ErrorResponseDTO } |
| 34 | import { |
| 35 | CreateRepositoryRequestDTO, |
| 36 | CreateRepositoryResponseDTO, |
| 37 | } from './dto/create-repository.dto.js'; |
| 38 | import { |
| 39 | GetRepositoriesQueryDTO, |
| 40 | GetRepositoriesResponseDTO, |
| 41 | } from './dto/get-repositories.dto.js'; |
| 42 | import { |
| 43 | GetRepositoryBlobQueryDTO, |
| 44 | GetRepositoryBlobResponseDTO, |
| 45 | } from './dto/get-repository-blob.dto.js'; |
| 46 | import { GetRepositoryBranchesResponseDTO } |
| 47 | import { |
| 48 | GetRepositoryTagsQueryDTO, |
| 49 | GetRepositoryTagsResponseDTO, |
| 50 | } from './dto/get-repository-tags.dto.js'; |
| 51 | import { GetRepositoryLanguagesResponseDTO } |
| 52 | import { |
| 53 | GetRepositoryForksQueryDTO, |
| 54 | GetRepositoryForksResponseDTO, |
| 55 | } from './dto/get-repository-forks.dto.js'; |
| 56 | import { |
| 57 | GetRepositoryContributorsQueryDTO, |
| 58 | GetRepositoryContributorsResponseDTO, |
| 59 | } from './dto/get-repository-contributors.dto.js'; |
| 60 | import { |
| 61 | GetRepositoryStargazersQueryDTO, |
| 62 | GetRepositoryStargazersResponseDTO, |
| 63 | } from './dto/get-repository-stargazers.dto.js'; |
| 64 | import { |
| 65 | GetCommitPatchQueryDTO, |
| 66 | GetRepositoryCommitResponseDTO, |
| 67 | GetRepositoryCommitsQueryDTO, |
| 68 | GetRepositoryCommitsResponseDTO, |
| 69 | } from './dto/get-repository-commits.dto.js'; |
| 70 | import { |
| 71 | GetRepositoryContentsQueryDTO, |
| 72 | GetRepositoryContentsResponseDTO, |
| 73 | } from './dto/get-repository-contents.dto.js'; |
| 74 | import { |
| 75 | GetRepositoryPathsQueryDTO, |
| 76 | GetRepositoryPathsResponseDTO, |
| 77 | } from './dto/get-repository-paths.dto.js'; |
| 78 | import { |
| 79 | GetRepositoryReadmeQueryDTO, |
| 80 | GetRepositoryReadmeResponseDTO, |
| 81 | } from './dto/get-repository-readme.dto.js'; |
| 82 | import { StarRepositoryResponseDTO } |
| 83 | import { |
| 84 | ForkRepositoryRequestDTO, |
| 85 | ForkRepositoryResponseDTO, |
| 86 | TransferRepositoryRequestDTO, |
| 87 | TransferRepositoryResponseDTO, |
| 88 | } from './dto/fork-repository.dto.js'; |
| 89 | import { |
| 90 | SearchCodeQueryDTO, |
| 91 | SearchRepositoryCodeResponseDTO, |
| 92 | } from './dto/search-code.dto.js'; |
| 93 | import { UpdateRepositoryRequestDTO } |
| 94 | import { GetViewerRepositoriesResponseDTO } |
| 95 | import { RepositoryEntity } |
| 96 | import { RepositoriesService } |
| 97 | |
| 98 | @Controller('repositories') |
| 99 | @ApiTags('Repositories') |
| 100 | export class RepositoriesController |
| 101 | constructor(private readonly |
| 102 | |
| 103 | @Post() |
| 104 | @ApiOperation({ |
| 105 | summary: 'Create Repository', |
| 106 | description: 'Create Repository', |
| 107 | }) |
| 108 | @ApiCreatedResponse({ |
| 109 | type: CreateRepositoryResponseDTO, |
| 110 | }) |
| 111 | @ApiNotFoundResponse({ |
| 112 | type: ErrorResponseDTO, |
| 113 | }) |
| 114 | createRepository( |
| 115 | @Body() body |
| 116 | @Session() session |
| 117 | ) { |
| 118 | return this.repositoriesService |
| 119 | } |
| 120 | |
| 121 | @Get() |
| 122 | @ApiOperation({ |
| 123 | summary: 'List my repositories', |
| 124 | description: |
| 125 | "Repositories the signed-in user owns or collaborates on, most recently pushed first, with the user's role on each. Pages are cursor-based: pass a response `nextCursor` back as `cursor`.", |
| 126 | }) |
| 127 | @ApiOkResponse({ |
| 128 | type: GetViewerRepositoriesResponseDTO, |
| 129 | }) |
| 130 | @ApiBadRequestResponse({ |
| 131 | type: ErrorResponseDTO, |
| 132 | }) |
| 133 | getViewerRepositories( |
| 134 | @Session() session |
| 135 | @Query() query |
| 136 | ): Promise<GetViewerRepositoriesResponseDTO |
| 137 | return this.repositoriesService |
| 138 | session.user.id |
| 139 | query, |
| 140 | ); |
| 141 | } |
| 142 | |
| 143 | @Get(':username' |
| 144 | @ApiOperation({ |
| 145 | summary: 'Get repositories for username', |
| 146 | description: 'Get repositories for username', |
| 147 | }) |
| 148 | @ApiOkResponse({ |
| 149 | type: GetRepositoriesResponseDTO, |
| 150 | }) |
| 151 | @ApiNotFoundResponse({ |
| 152 | type: ErrorResponseDTO, |
| 153 | }) |
| 154 | @OptionalAuth() |
| 155 | getRepositories( |
| 156 | @Param('username' |
| 157 | @Session() session |
| 158 | @Query() query |
| 159 | ) { |
| 160 | return this.repositoriesService |
| 161 | username, |
| 162 | session?.user?.id |
| 163 | query, |
| 164 | ); |
| 165 | } |
| 166 | |
| 167 | @Get(':username/:slug' |
| 168 | @OptionalAuth() |
| 169 | @ApiOperation({ |
| 170 | summary: 'Get repository details', |
| 171 | description: 'Get a single repository by owner username and slug', |
| 172 | }) |
| 173 | @ApiOkResponse({ |
| 174 | type: RepositoryEntity, |
| 175 | }) |
| 176 | @ApiNotFoundResponse({ |
| 177 | type: ErrorResponseDTO, |
| 178 | }) |
| 179 | getRepository( |
| 180 | @Param('username' |
| 181 | @Param('slug' |
| 182 | @Session() session |
| 183 | ) { |
| 184 | return this.repositoriesService |
| 185 | username, |
| 186 | slug, |
| 187 | requesterId: session?.user |
| 188 | }); |
| 189 | } |
| 190 | |
| 191 | @Patch(':username/:slug' |
| 192 | @ApiOperation({ |
| 193 | summary: 'Update repository settings', |
| 194 | description: |
| 195 | 'Rename, describe, change visibility or pick the default branch. Owner only. Omitted fields are left as they are.', |
| 196 | }) |
| 197 | @ApiOkResponse({ |
| 198 | type: CreateRepositoryResponseDTO, |
| 199 | }) |
| 200 | @ApiForbiddenResponse({ |
| 201 | type: ErrorResponseDTO, |
| 202 | }) |
| 203 | @ApiNotFoundResponse({ |
| 204 | description: |
| 205 | 'The repository, or the requested default branch, does not exist.', |
| 206 | type: ErrorResponseDTO, |
| 207 | }) |
| 208 | updateRepository( |
| 209 | @Param('username' |
| 210 | @Param('slug' |
| 211 | @Body() body |
| 212 | @Session() session |
| 213 | ): Promise<CreateRepositoryResponseDTO |
| 214 | return this.repositoriesService |
| 215 | username, |
| 216 | slug, |
| 217 | requesterId: session.user |
| 218 | changes: body, |
| 219 | }); |
| 220 | } |
| 221 | |
| 222 | @Delete(':username/:slug' |
| 223 | @HttpCode(HttpStatus. |
| 224 | @ApiOperation({ |
| 225 | summary: 'Delete repository', |
| 226 | description: |
| 227 | 'Deletes the repository with its issues, pull requests and stars, and everything it stored. Owner only. Forks are kept and detached; closed and merged pull requests this repository opened elsewhere are kept without it.', |
| 228 | }) |
| 229 | @ApiNoContentResponse() |
| 230 | @ApiConflictResponse({ |
| 231 | description: |
| 232 | 'The repository heads an open pull request into another repository.', |
| 233 | type: ErrorResponseDTO, |
| 234 | }) |
| 235 | @ApiForbiddenResponse({ |
| 236 | type: ErrorResponseDTO, |
| 237 | }) |
| 238 | @ApiNotFoundResponse({ |
| 239 | type: ErrorResponseDTO, |
| 240 | }) |
| 241 | deleteRepository( |
| 242 | @Param('username' |
| 243 | @Param('slug' |
| 244 | @Session() session |
| 245 | ): Promise<void |
| 246 | return this.repositoriesService |
| 247 | username, |
| 248 | slug, |
| 249 | requesterId: session.user |
| 250 | }); |
| 251 | } |
| 252 | |
| 253 | @Post(':username/:slug/fork' |
| 254 | @ApiOperation({ |
| 255 | summary: 'Fork repository', |
| 256 | description: |
| 257 | 'Copy a repository under the requester. One fork per repository per owner.', |
| 258 | }) |
| 259 | @ApiCreatedResponse({ |
| 260 | type: ForkRepositoryResponseDTO, |
| 261 | }) |
| 262 | @ApiConflictResponse({ |
| 263 | type: ErrorResponseDTO, |
| 264 | }) |
| 265 | @ApiNotFoundResponse({ |
| 266 | type: ErrorResponseDTO, |
| 267 | }) |
| 268 | forkRepository( |
| 269 | @Param('username' |
| 270 | @Param('slug' |
| 271 | @Body() body |
| 272 | @Session() session |
| 273 | ) { |
| 274 | return this.repositoriesService |
| 275 | username, |
| 276 | slug, |
| 277 | ...body, |
| 278 | // Last, so a body that names a requesterId cannot fork as someone else. |
| 279 | requesterId: session.user |
| 280 | }); |
| 281 | } |
| 282 | |
| 283 | @Post(':username/:slug/transfer' |
| 284 | @ApiOperation({ |
| 285 | summary: 'Transfer repository', |
| 286 | description: |
| 287 | "Owner only. Moves at once to the requester's own account or an organization they administer; any other recipient accepts first. The old name keeps redirecting.", |
| 288 | }) |
| 289 | @ApiCreatedResponse({ |
| 290 | type: TransferRepositoryResponseDTO, |
| 291 | }) |
| 292 | @ApiBadRequestResponse({ |
| 293 | type: ErrorResponseDTO, |
| 294 | }) |
| 295 | @ApiForbiddenResponse({ |
| 296 | type: ErrorResponseDTO, |
| 297 | }) |
| 298 | @ApiConflictResponse({ |
| 299 | type: ErrorResponseDTO, |
| 300 | }) |
| 301 | @ApiNotFoundResponse({ |
| 302 | type: ErrorResponseDTO, |
| 303 | }) |
| 304 | transferRepository( |
| 305 | @Param('username' |
| 306 | @Param('slug' |
| 307 | @Body() body |
| 308 | @Session() session |
| 309 | ): Promise<TransferRepositoryResponseDTO |
| 310 | return this.repositoriesService |
| 311 | username, |
| 312 | slug, |
| 313 | requesterId: session.user |
| 314 | owner: body.owner |
| 315 | }); |
| 316 | } |
| 317 | |
| 318 | @Post(':username/:slug/star' |
| 319 | @ApiOperation({ |
| 320 | summary: 'Star repository', |
| 321 | description: |
| 322 | 'Star a repository. Starring twice leaves the count unchanged.', |
| 323 | }) |
| 324 | @ApiOkResponse({ |
| 325 | type: StarRepositoryResponseDTO, |
| 326 | }) |
| 327 | @ApiNotFoundResponse({ |
| 328 | type: ErrorResponseDTO, |
| 329 | }) |
| 330 | starRepository( |
| 331 | @Param('username' |
| 332 | @Param('slug' |
| 333 | @Session() session |
| 334 | ) { |
| 335 | return this.repositoriesService |
| 336 | username, |
| 337 | slug, |
| 338 | requesterId: session.user |
| 339 | }); |
| 340 | } |
| 341 | |
| 342 | @Delete(':username/:slug/star' |
| 343 | @ApiOperation({ |
| 344 | summary: 'Unstar repository', |
| 345 | description: "Remove the requester's star from a repository.", |
| 346 | }) |
| 347 | @ApiOkResponse({ |
| 348 | type: StarRepositoryResponseDTO, |
| 349 | }) |
| 350 | @ApiNotFoundResponse({ |
| 351 | type: ErrorResponseDTO, |
| 352 | }) |
| 353 | unstarRepository( |
| 354 | @Param('username' |
| 355 | @Param('slug' |
| 356 | @Session() session |
| 357 | ) { |
| 358 | return this.repositoriesService |
| 359 | username, |
| 360 | slug, |
| 361 | requesterId: session.user |
| 362 | }); |
| 363 | } |
| 364 | |
| 365 | @Get(':username/:slug/contents' |
| 366 | @OptionalAuth() |
| 367 | @ApiOperation({ |
| 368 | summary: 'List repository contents', |
| 369 | description: |
| 370 | 'One level of a directory at the requested ref - a branch or a commit sha - or the default branch when none is given, with the newest commit touching each entry. Directories report the newest commit anywhere beneath them.', |
| 371 | }) |
| 372 | @ApiOkResponse({ |
| 373 | type: GetRepositoryContentsResponseDTO, |
| 374 | }) |
| 375 | @ApiBadRequestResponse({ |
| 376 | description: |
| 377 | 'The `path` query parameter is not a repository-relative directory.', |
| 378 | type: ErrorResponseDTO, |
| 379 | }) |
| 380 | @ApiNotFoundResponse({ |
| 381 | type: ErrorResponseDTO, |
| 382 | }) |
| 383 | getRepositoryContents( |
| 384 | @Param('username' |
| 385 | @Param('slug' |
| 386 | @Session() session |
| 387 | @Query() query |
| 388 | ): Promise<GetRepositoryContentsResponseDTO |
| 389 | return this.repositoriesService |
| 390 | username, |
| 391 | repo: slug, |
| 392 | path: query.path |
| 393 | ref: query.ref |
| 394 | requesterId: session?.user |
| 395 | }); |
| 396 | } |
| 397 | |
| 398 | @Get(':username/:slug/paths' |
| 399 | @UseGuards(ThrottlerGuard) |
| 400 | @ApiTooManyRequestsResponse({ type |
| 401 | @OptionalAuth() |
| 402 | @ApiOperation({ |
| 403 | summary: 'List every file path', |
| 404 | description: |
| 405 | 'Every file in the repository at the requested ref - a branch, tag or commit sha - or the default branch when none is given, for finding a file by name. Unlike code search, it reads the ref directly, so it needs no index.', |
| 406 | }) |
| 407 | @ApiOkResponse({ |
| 408 | type: GetRepositoryPathsResponseDTO, |
| 409 | }) |
| 410 | @ApiNotFoundResponse({ |
| 411 | type: ErrorResponseDTO, |
| 412 | }) |
| 413 | getRepositoryPaths( |
| 414 | @Param('username' |
| 415 | @Param('slug' |
| 416 | @Session() session |
| 417 | @Query() query |
| 418 | ): Promise<GetRepositoryPathsResponseDTO |
| 419 | return this.repositoriesService |
| 420 | username, |
| 421 | repo: slug, |
| 422 | ref: query.ref |
| 423 | requesterId: session?.user |
| 424 | }); |
| 425 | } |
| 426 | |
| 427 | @Get(':username/:slug/readme' |
| 428 | @OptionalAuth() |
| 429 | @ApiOperation({ |
| 430 | summary: 'Read the README', |
| 431 | description: |
| 432 | 'The README of a directory - the root of the repository when no `path` is given - at the requested ref.', |
| 433 | }) |
| 434 | @ApiOkResponse({ |
| 435 | type: GetRepositoryReadmeResponseDTO, |
| 436 | }) |
| 437 | @ApiNotFoundResponse({ |
| 438 | type: ErrorResponseDTO, |
| 439 | }) |
| 440 | getRepositoryReadme( |
| 441 | @Param('username' |
| 442 | @Param('slug' |
| 443 | @Session() session |
| 444 | @Query() query |
| 445 | ): Promise<GetRepositoryReadmeResponseDTO |
| 446 | return this.repositoriesService |
| 447 | username, |
| 448 | repo: slug, |
| 449 | ref: query.ref |
| 450 | path: query.path |
| 451 | requesterId: session?.user |
| 452 | }); |
| 453 | } |
| 454 | |
| 455 | @Get(':username/:slug/blob' |
| 456 | @OptionalAuth() |
| 457 | @ApiOperation({ |
| 458 | summary: 'Read a file', |
| 459 | description: |
| 460 | 'Contents of a single file at the requested ref - a branch or a commit sha - or the default branch when none is given. Binary files come back base64-encoded, and a file past the inline size limit comes back without contents.', |
| 461 | }) |
| 462 | @ApiOkResponse({ |
| 463 | type: GetRepositoryBlobResponseDTO, |
| 464 | }) |
| 465 | @ApiBadRequestResponse({ |
| 466 | description: |
| 467 | 'The `path` query parameter is not a repository-relative file.', |
| 468 | type: ErrorResponseDTO, |
| 469 | }) |
| 470 | @ApiNotFoundResponse({ |
| 471 | type: ErrorResponseDTO, |
| 472 | }) |
| 473 | getRepositoryBlob( |
| 474 | @Param('username' |
| 475 | @Param('slug' |
| 476 | @Session() session |
| 477 | @Query() query |
| 478 | ): Promise<GetRepositoryBlobResponseDTO |
| 479 | return this.repositoriesService |
| 480 | username, |
| 481 | repo: slug, |
| 482 | path: query.path |
| 483 | ref: query.ref |
| 484 | requesterId: session?.user |
| 485 | }); |
| 486 | } |
| 487 | |
| 488 | @Get(':username/:slug/raw' |
| 489 | @OptionalAuth() |
| 490 | @ApiOperation({ |
| 491 | summary: 'Download a file', |
| 492 | description: |
| 493 | 'The raw bytes of a file. Images, audio, video and PDFs are served inline for the browser to render; everything else downloads.', |
| 494 | }) |
| 495 | @ApiOkResponse({ schema |
| 496 | @ApiNotFoundResponse({ |
| 497 | type: ErrorResponseDTO, |
| 498 | }) |
| 499 | async getRawBlob( |
| 500 | @Param('username' |
| 501 | @Param('slug' |
| 502 | @Session() session |
| 503 | @Query() query |
| 504 | @Res({ passthrough |
| 505 | ): Promise<StreamableFile |
| 506 | const blob = |
| 507 | username, |
| 508 | repo: slug, |
| 509 | path: query.path |
| 510 | ref: query.ref |
| 511 | requesterId: session?.user |
| 512 | }); |
| 513 | |
| 514 | response.set({ |
| 515 | 'Content-Type': blob. |
| 516 | 'Content-Length': String( |
| 517 | 'Content-Disposition': `${blob |
| 518 | // the bytes are user-controlled: never sniffed, never scripted |
| 519 | 'X-Content-Type-Options': 'nosniff', |
| 520 | 'Content-Security-Policy': "default-src 'none'; sandbox", |
| 521 | // content is addressed by commit-stable oid, so a hit can never be stale |
| 522 | 'Cache-Control': 'private, max-age=31536000, immutable', |
| 523 | ETag: `"${blob |
| 524 | }); |
| 525 | |
| 526 | return new StreamableFile |
| 527 | } |
| 528 | |
| 529 | @Get(':username/:slug/commits' |
| 530 | @OptionalAuth() |
| 531 | @ApiOperation({ |
| 532 | summary: 'List commits', |
| 533 | description: |
| 534 | 'History of a branch or commit, newest first, optionally narrowed to one path. Pages are cursor-based: pass a response `nextCursor` back as `cursor`.', |
| 535 | }) |
| 536 | @ApiOkResponse({ |
| 537 | type: GetRepositoryCommitsResponseDTO, |
| 538 | }) |
| 539 | @ApiBadRequestResponse({ |
| 540 | type: ErrorResponseDTO, |
| 541 | }) |
| 542 | @ApiNotFoundResponse({ |
| 543 | type: ErrorResponseDTO, |
| 544 | }) |
| 545 | getRepositoryCommits( |
| 546 | @Param('username' |
| 547 | @Param('slug' |
| 548 | @Session() session |
| 549 | @Query() query |
| 550 | ): Promise<GetRepositoryCommitsResponseDTO |
| 551 | return this.repositoriesService |
| 552 | username, |
| 553 | repo: slug, |
| 554 | requesterId: session?.user |
| 555 | query, |
| 556 | }); |
| 557 | } |
| 558 | |
| 559 | @Get(':username/:slug/commits/:sha' |
| 560 | @OptionalAuth() |
| 561 | @ApiOperation({ |
| 562 | summary: 'Read a commit', |
| 563 | description: |
| 564 | 'One commit with the paths it changed, against its first parent. Accepts a full sha or any unambiguous prefix.', |
| 565 | }) |
| 566 | @ApiOkResponse({ |
| 567 | type: GetRepositoryCommitResponseDTO, |
| 568 | }) |
| 569 | @ApiNotFoundResponse({ |
| 570 | type: ErrorResponseDTO, |
| 571 | }) |
| 572 | getRepositoryCommit( |
| 573 | @Param('username' |
| 574 | @Param('slug' |
| 575 | @Param('sha' |
| 576 | @Session() session |
| 577 | ): Promise<GetRepositoryCommitResponseDTO |
| 578 | return this.repositoriesService |
| 579 | username, |
| 580 | repo: slug, |
| 581 | sha, |
| 582 | requesterId: session?.user |
| 583 | }); |
| 584 | } |
| 585 | |
| 586 | @Get(':username/:slug/commits/:sha/patch' |
| 587 | @OptionalAuth() |
| 588 | @ApiOperation({ |
| 589 | summary: 'Read a commit as a patch', |
| 590 | description: 'The commit as a git patch file, unparsed.', |
| 591 | }) |
| 592 | @ApiOkResponse({ |
| 593 | content: { |
| 594 | 'text/x-patch': { |
| 595 | example: '', |
| 596 | }, |
| 597 | }, |
| 598 | }) |
| 599 | @ApiNotFoundResponse({ |
| 600 | type: ErrorResponseDTO, |
| 601 | }) |
| 602 | async getCommitPatch( |
| 603 | @Param('username' |
| 604 | @Param('slug' |
| 605 | @Param('sha' |
| 606 | @Query() query |
| 607 | @Session() session |
| 608 | @Res({ passthrough |
| 609 | ): Promise<string |
| 610 | const patch = |
| 611 | username, |
| 612 | repo: slug, |
| 613 | sha, |
| 614 | path: query.path |
| 615 | requesterId: session?.user |
| 616 | }); |
| 617 | |
| 618 | response.set({ |
| 619 | 'Content-Type': 'text/x-patch; charset=utf-8', |
| 620 | 'Content-Disposition': `inline; filename="${sha |
| 621 | 'X-Content-Type-Options': 'nosniff', |
| 622 | }); |
| 623 | |
| 624 | return patch; |
| 625 | } |
| 626 | |
| 627 | @Get(':username/:slug/branches' |
| 628 | @OptionalAuth() |
| 629 | @ApiOperation({ |
| 630 | summary: 'List repository branches', |
| 631 | description: 'Every branch of the repository, and which one it opens on.', |
| 632 | }) |
| 633 | @ApiOkResponse({ |
| 634 | type: GetRepositoryBranchesResponseDTO, |
| 635 | }) |
| 636 | @ApiNotFoundResponse({ |
| 637 | type: ErrorResponseDTO, |
| 638 | }) |
| 639 | getRepositoryBranches( |
| 640 | @Param('username' |
| 641 | @Param('slug' |
| 642 | @Session() session |
| 643 | ): Promise<GetRepositoryBranchesResponseDTO |
| 644 | return this.repositoriesService |
| 645 | username, |
| 646 | repo: slug, |
| 647 | requesterId: session?.user |
| 648 | }); |
| 649 | } |
| 650 | |
| 651 | @Get(':username/:slug/tags' |
| 652 | @OptionalAuth() |
| 653 | @ApiOperation({ |
| 654 | summary: 'List repository tags', |
| 655 | description: |
| 656 | 'Every tag, newest first, with the commit each one points at. Pages are cursor-based: pass a response `nextCursor` back as `cursor`.', |
| 657 | }) |
| 658 | @ApiOkResponse({ |
| 659 | type: GetRepositoryTagsResponseDTO, |
| 660 | }) |
| 661 | @ApiBadRequestResponse({ |
| 662 | type: ErrorResponseDTO, |
| 663 | }) |
| 664 | @ApiNotFoundResponse({ |
| 665 | type: ErrorResponseDTO, |
| 666 | }) |
| 667 | getRepositoryTags( |
| 668 | @Param('username' |
| 669 | @Param('slug' |
| 670 | @Session() session |
| 671 | @Query() query |
| 672 | ): Promise<GetRepositoryTagsResponseDTO |
| 673 | return this.repositoriesService |
| 674 | username, |
| 675 | repo: slug, |
| 676 | requesterId: session?.user |
| 677 | query, |
| 678 | }); |
| 679 | } |
| 680 | |
| 681 | @Get(':username/:slug/languages' |
| 682 | @OptionalAuth() |
| 683 | @ApiOperation({ |
| 684 | summary: 'Language breakdown', |
| 685 | description: 'Bytes per language on the default branch, largest first', |
| 686 | }) |
| 687 | @ApiOkResponse({ |
| 688 | type: GetRepositoryLanguagesResponseDTO, |
| 689 | }) |
| 690 | @ApiNotFoundResponse({ |
| 691 | type: ErrorResponseDTO, |
| 692 | }) |
| 693 | getRepositoryLanguages( |
| 694 | @Param('username' |
| 695 | @Param('slug' |
| 696 | @Session() session |
| 697 | ): Promise<GetRepositoryLanguagesResponseDTO |
| 698 | return this.repositoriesService |
| 699 | username, |
| 700 | repo: slug, |
| 701 | requesterId: session?.user |
| 702 | }); |
| 703 | } |
| 704 | |
| 705 | @Get(':username/:slug/search' |
| 706 | @UseGuards(ThrottlerGuard) |
| 707 | @ApiTooManyRequestsResponse({ type |
| 708 | @OptionalAuth() |
| 709 | @ApiOperation({ |
| 710 | summary: 'Search code', |
| 711 | description: |
| 712 | 'Full-text and regex search over the files on the default branch, powered by zoekt.', |
| 713 | }) |
| 714 | @ApiOkResponse({ |
| 715 | type: SearchRepositoryCodeResponseDTO, |
| 716 | }) |
| 717 | @ApiBadRequestResponse({ |
| 718 | type: ErrorResponseDTO, |
| 719 | }) |
| 720 | @ApiNotFoundResponse({ |
| 721 | type: ErrorResponseDTO, |
| 722 | }) |
| 723 | @ApiServiceUnavailableResponse({ |
| 724 | type: ErrorResponseDTO, |
| 725 | }) |
| 726 | searchRepositoryCode( |
| 727 | @Param('username' |
| 728 | @Param('slug' |
| 729 | @Session() session |
| 730 | @Query() query |
| 731 | ): Promise<SearchRepositoryCodeResponseDTO |
| 732 | return this.repositoriesService |
| 733 | username, |
| 734 | repo: slug, |
| 735 | requesterId: session?.user |
| 736 | query: query.q |
| 737 | cursor: query.cursor |
| 738 | limit: query.limit |
| 739 | }); |
| 740 | } |
| 741 | |
| 742 | @Get(':username/:slug/stargazers' |
| 743 | @OptionalAuth() |
| 744 | @ApiOperation({ |
| 745 | summary: 'List stargazers', |
| 746 | description: |
| 747 | 'Who starred the repository, most recently first. Pages are cursor-based: pass a response `nextCursor` back as `cursor`.', |
| 748 | }) |
| 749 | @ApiOkResponse({ |
| 750 | type: GetRepositoryStargazersResponseDTO, |
| 751 | }) |
| 752 | @ApiBadRequestResponse({ |
| 753 | type: ErrorResponseDTO, |
| 754 | }) |
| 755 | @ApiNotFoundResponse({ |
| 756 | type: ErrorResponseDTO, |
| 757 | }) |
| 758 | getRepositoryStargazers( |
| 759 | @Param('username' |
| 760 | @Param('slug' |
| 761 | @Session() session |
| 762 | @Query() query |
| 763 | ): Promise<GetRepositoryStargazersResponseDTO |
| 764 | return this.repositoriesService |
| 765 | username, |
| 766 | repo: slug, |
| 767 | requesterId: session?.user |
| 768 | query, |
| 769 | }); |
| 770 | } |
| 771 | |
| 772 | @Get(':username/:slug/forks' |
| 773 | @OptionalAuth() |
| 774 | @ApiOperation({ |
| 775 | summary: 'List forks', |
| 776 | description: |
| 777 | 'Forks of the repository, newest push first. A private fork is only listed to its own owner.', |
| 778 | }) |
| 779 | @ApiOkResponse({ |
| 780 | type: GetRepositoryForksResponseDTO, |
| 781 | }) |
| 782 | @ApiBadRequestResponse({ |
| 783 | type: ErrorResponseDTO, |
| 784 | }) |
| 785 | @ApiNotFoundResponse({ |
| 786 | type: ErrorResponseDTO, |
| 787 | }) |
| 788 | getRepositoryForks( |
| 789 | @Param('username' |
| 790 | @Param('slug' |
| 791 | @Session() session |
| 792 | @Query() query |
| 793 | ): Promise<GetRepositoryForksResponseDTO |
| 794 | return this.repositoriesService |
| 795 | username, |
| 796 | repo: slug, |
| 797 | requesterId: session?.user |
| 798 | query, |
| 799 | }); |
| 800 | } |
| 801 | |
| 802 | @Get(':username/:slug/contributors' |
| 803 | @OptionalAuth() |
| 804 | @ApiOperation({ |
| 805 | summary: 'List contributors', |
| 806 | description: |
| 807 | 'Authors of the default branch, most commits first, read from the contribution index with linked Ghost accounts. Never materializes the repository.', |
| 808 | }) |
| 809 | @ApiOkResponse({ |
| 810 | type: GetRepositoryContributorsResponseDTO, |
| 811 | }) |
| 812 | @ApiNotFoundResponse({ |
| 813 | type: ErrorResponseDTO, |
| 814 | }) |
| 815 | getRepositoryContributors( |
| 816 | @Param('username' |
| 817 | @Param('slug' |
| 818 | @Session() session |
| 819 | @Query() query |
| 820 | ): Promise<GetRepositoryContributorsResponseDTO |
| 821 | return this.repositoriesService |
| 822 | username, |
| 823 | repo: slug, |
| 824 | requesterId: session?.user |
| 825 | query, |
| 826 | }); |
| 827 | } |
| 828 | } |