-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebhookController.cs
46 lines (39 loc) · 1.54 KB
/
WebhookController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
namespace rubberduckvba.Server.Api.Admin;
[ApiController]
public class WebhookController : RubberduckApiController
{
private readonly WebhookPayloadValidationService _validator;
private readonly HangfireLauncherService _hangfire;
public WebhookController(
ILogger<WebhookController> logger,
HangfireLauncherService hangfire,
WebhookPayloadValidationService validator)
: base(logger)
{
_validator = validator;
_hangfire = hangfire;
}
[Authorize("webhook", AuthenticationSchemes = "webhook-signature")]
[HttpPost("webhook/github")]
public IActionResult GitHub([FromBody] JToken payload)
{
var eventType = _validator.Validate(payload, Request.Headers, out var content, out var gitref);
if (eventType == WebhookPayloadType.Push)
{
var jobId = _hangfire.UpdateXmldocContent();
var message = $"Webhook push event was accepted. Tag '{gitref?.Name}' associated to the payload will be processed by JobId '{jobId}'.";
Logger.LogInformation(message);
return Ok(message);
}
else if (eventType == WebhookPayloadType.Greeting)
{
Logger.LogInformation("Webhook push event was accepted; nothing to process. {content}", content);
return string.IsNullOrWhiteSpace(content) ? NoContent() : Ok(content);
}
// reject the payload
return BadRequest();
}
}