-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathAzureDevOpsEventsConsumer.cs
34 lines (30 loc) · 1.3 KB
/
AzureDevOpsEventsConsumer.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
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Tingle.EventBus;
namespace CustomEventSerializer
{
internal class AzureDevOpsEventsConsumer : IEventConsumer<AzureDevOpsCodePushed>
{
private readonly ILogger logger;
public AzureDevOpsEventsConsumer(ILogger<AzureDevOpsEventsConsumer> logger)
{
this.logger = logger ?? throw new System.ArgumentNullException(nameof(logger));
}
public Task ConsumeAsync(EventContext<AzureDevOpsCodePushed> context, CancellationToken cancellationToken = default)
{
var @event = context.Event;
var resource = @event.Resource;
var repository = resource?.Repository;
var defaultBranch = repository?.DefaultBranch;
// get the updated branchs (refs)
var updatedReferences = resource?.RefUpdates?.Select(ru => ru.Name).ToList() ?? new List<string?>();
logger.LogInformation("Default branch: ({DefaultBranch})", defaultBranch);
logger.LogInformation("Updated branches (references):\r\n- {ChangedReferences}",
string.Join("\r\n- ", updatedReferences));
return Task.CompletedTask;
}
}
}