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