chore: debug log 仅输出app的log fix(commons): fix sanitize not return value. feat(webhooks): add gitea webhooks api. Co-authored-by: Ivan Li <ivanli@live.cn> Co-authored-by: Ivan <ivanli@live.cn> Reviewed-on: #2 Co-Authored-By: Ivan Li <ivan@noreply.%(DOMAIN)s> Co-Committed-By: Ivan Li <ivan@noreply.%(DOMAIN)s>
38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import { Body, Controller, Headers, Param, Post } from '@nestjs/common';
|
|
import { validateOrReject } from 'class-validator';
|
|
import { pick } from 'ramda';
|
|
import { GiteaHookPayloadDto } from './dtos/gitea-hook-payload.dto';
|
|
import { SourceService } from './enums/source-service.enum';
|
|
import { WebhookLog } from './webhook-log.entity';
|
|
import { WebhooksService } from './webhooks.service';
|
|
|
|
@Controller('gitea-webhooks')
|
|
export class GiteaWebhooksController {
|
|
constructor(private readonly service: WebhooksService) {}
|
|
@Post(':pipelineId')
|
|
async onCall(
|
|
@Headers('X-Gitea-Delivery') delivery: string,
|
|
@Headers('X-Gitea-Event') event: string,
|
|
@Headers('X-Gitea-Signature') signature: string,
|
|
@Body() body: Buffer,
|
|
@Param('pipelineId') pipelineId: string,
|
|
) {
|
|
const payload = Object.assign(
|
|
new GiteaHookPayloadDto(),
|
|
JSON.parse(body.toString('utf-8')),
|
|
);
|
|
await validateOrReject(payload);
|
|
await this.service.verifySignature(body, signature, 'boardcat');
|
|
return await this.service
|
|
.onCall(pipelineId, {
|
|
payload,
|
|
sourceDelivery: delivery,
|
|
sourceEvent: event,
|
|
sourceService: SourceService.gitea,
|
|
})
|
|
.then((data) =>
|
|
pick<keyof WebhookLog>(['id', 'createdAt', 'localEvent'])(data),
|
|
);
|
|
}
|
|
}
|