| 1 | import { |
| 2 | Body, |
| 3 | Controller, |
| 4 | HttpCode, |
| 5 | HttpStatus, |
| 6 | Param, |
| 7 | Post, |
| 8 | UseGuards, |
| 9 | } from '@nestjs/common'; |
| 10 | import { ApiExcludeController } |
| 11 | import { Public } |
| 12 | |
| 13 | import { ImportDispatcherService } |
| 14 | import { ImportWriterService } |
| 15 | import { |
| 16 | FinishImportRequestDTO, |
| 17 | ImportAttemptDTO, |
| 18 | ImportCommentsRequestDTO, |
| 19 | ImportIssuesRequestDTO, |
| 20 | ImportReleasesRequestDTO, |
| 21 | } from './dto/importer-callback.dto.js'; |
| 22 | import { ImporterSecretGuard } |
| 23 | |
| 24 | /** Called by `apps/importer` only. Each call renews the attempt's lease, so a working importer never looks silent. */ |
| 25 | @Controller('internal/imports/:importId') |
| 26 | @ApiExcludeController() |
| 27 | @Public() |
| 28 | @UseGuards(ImporterSecretGuard) |
| 29 | export class ImporterCallbacksController |
| 30 | constructor( |
| 31 | private readonly dispatcher |
| 32 | private readonly writer |
| 33 | ) {} |
| 34 | |
| 35 | @Post('heartbeat' |
| 36 | @HttpCode(HttpStatus. |
| 37 | async heartbeat( |
| 38 | @Param('importId' |
| 39 | @Body() { |
| 40 | ) { |
| 41 | await this.dispatcher |
| 42 | } |
| 43 | |
| 44 | @Post('releases' |
| 45 | @HttpCode(HttpStatus. |
| 46 | async releases( |
| 47 | @Param('importId' |
| 48 | @Body() { |
| 49 | ) { |
| 50 | const repositoryId = |
| 51 | await this.writer |
| 52 | } |
| 53 | |
| 54 | @Post('issues' |
| 55 | @HttpCode(HttpStatus. |
| 56 | async issues( |
| 57 | @Param('importId' |
| 58 | @Body() { |
| 59 | ) { |
| 60 | const repositoryId = |
| 61 | await this.writer |
| 62 | } |
| 63 | |
| 64 | @Post('comments' |
| 65 | @HttpCode(HttpStatus. |
| 66 | async comments( |
| 67 | @Param('importId' |
| 68 | @Body() { |
| 69 | ) { |
| 70 | const repositoryId = |
| 71 | await this.writer |
| 72 | } |
| 73 | |
| 74 | @Post('finish' |
| 75 | @HttpCode(HttpStatus. |
| 76 | async finish( |
| 77 | @Param('importId' |
| 78 | @Body() body |
| 79 | ) { |
| 80 | await this.dispatcher |
| 81 | importId, |
| 82 | body.attempt, |
| 83 | body.succeeded |
| 84 | ? { succeeded: true, |
| 85 | : { succeeded: false, |
| 86 | ); |
| 87 | } |
| 88 | } |