Skip to content

Commit 175f4d5

Browse files
authoredJun 27, 2020
Expose eventType as event variable to rules (#136)
* New feature to avoid revision check Use new directive .check revision false this should help in scenario like #128 and #125 * Documentation migrated to aggregator-docs repo * Expose eventType as event variable to rules
1 parent e5705d7 commit 175f4d5

File tree

7 files changed

+79
-33
lines changed

7 files changed

+79
-33
lines changed
 

‎src/aggregator-cli/Rules/AggregatorRules.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ internal async Task<bool> InvokeLocalAsync(string projectName, string @event, in
431431
var engine = new Engine.RuleEngine(engineLogger, saveMode, dryRun: dryRun);
432432

433433
var workItem = await clientsContext.WitClient.GetWorkItemAsync(projectName, workItemId, expand: WorkItemExpand.All, cancellationToken: cancellationToken);
434-
string result = await engine.RunAsync(rule, teamProjectId, workItem, clientsContext, cancellationToken);
434+
string result = await engine.RunAsync(rule, teamProjectId, workItem, @event, clientsContext, cancellationToken);
435435
_logger.WriteInfo($"Rule returned '{result}'");
436436

437437
return true;

‎src/aggregator-function/AzureFunctionHandler.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.IO;
33
using System.Linq;
44
using System.Threading;
@@ -132,13 +132,13 @@ protected WorkItemEventContext CreateContextFromEvent(WebHookEvent eventData)
132132
var workItem = resourceObject.GetValue("revision").ToObject<WorkItem>();
133133
MigrateIdentityInformation(eventData.ResourceVersion, workItem);
134134
var workItemUpdate = resourceObject.ToObject<WorkItemUpdate>();
135-
return new WorkItemEventContext(teamProjectId, new Uri(collectionUrl), workItem, workItemUpdate);
135+
return new WorkItemEventContext(teamProjectId, new Uri(collectionUrl), workItem, eventData.EventType, workItemUpdate);
136136
}
137137
else
138138
{
139139
var workItem = resourceObject.ToObject<WorkItem>();
140140
MigrateIdentityInformation(eventData.ResourceVersion, workItem);
141-
return new WorkItemEventContext(teamProjectId, new Uri(collectionUrl), workItem);
141+
return new WorkItemEventContext(teamProjectId, new Uri(collectionUrl), workItem, eventData.EventType);
142142
}
143143
}
144144

‎src/aggregator-ruleng/RuleEngine.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace aggregator.Engine
1515
{
1616
internal interface IRuleEngine
1717
{
18-
Task<string> RunAsync(IRule rule, Guid projectId, WorkItemData workItemPayload, IClientsContext clients, CancellationToken cancellationToken = default);
18+
Task<string> RunAsync(IRule rule, Guid projectId, WorkItemData workItemPayload, string eventType, IClientsContext clients, CancellationToken cancellationToken = default);
1919
}
2020

2121
public abstract class RuleEngineBase : IRuleEngine
@@ -34,9 +34,9 @@ protected RuleEngineBase(IAggregatorLogger logger, SaveMode saveMode, bool dryRu
3434
this.dryRun = dryRun;
3535
}
3636

37-
public async Task<string> RunAsync(IRule rule, Guid projectId, WorkItemData workItemPayload, IClientsContext clients, CancellationToken cancellationToken = default)
37+
public async Task<string> RunAsync(IRule rule, Guid projectId, WorkItemData workItemPayload, string eventType, IClientsContext clients, CancellationToken cancellationToken = default)
3838
{
39-
var executionContext = CreateRuleExecutionContext(projectId, workItemPayload, clients, rule.Settings);
39+
var executionContext = CreateRuleExecutionContext(projectId, workItemPayload, eventType, clients, rule.Settings);
4040

4141
var result = await ExecuteRuleAsync(rule, executionContext, cancellationToken);
4242

@@ -45,7 +45,7 @@ public async Task<string> RunAsync(IRule rule, Guid projectId, WorkItemData work
4545

4646
protected abstract Task<string> ExecuteRuleAsync(IRule rule, RuleExecutionContext executionContext, CancellationToken cancellationToken = default);
4747

48-
protected RuleExecutionContext CreateRuleExecutionContext(Guid projectId, WorkItemData workItemPayload, IClientsContext clients, IRuleSettings ruleSettings)
48+
protected RuleExecutionContext CreateRuleExecutionContext(Guid projectId, WorkItemData workItemPayload, string eventType, IClientsContext clients, IRuleSettings ruleSettings)
4949
{
5050
var workItem = workItemPayload.WorkItem;
5151
var context = new EngineContext(clients, projectId, workItem.GetTeamProject(), logger, ruleSettings);
@@ -59,7 +59,8 @@ protected RuleExecutionContext CreateRuleExecutionContext(Guid projectId, WorkIt
5959
self = self,
6060
selfChanges = selfChanges,
6161
store = store,
62-
logger = logger
62+
logger = logger,
63+
eventType = eventType
6364
};
6465
return globals;
6566
}

‎src/aggregator-ruleng/RuleExecutionContext.cs

+1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ public class RuleExecutionContext
1313
public WorkItemUpdateWrapper selfChanges;
1414
public WorkItemStore store;
1515
public IAggregatorLogger logger;
16+
public string eventType;
1617
}
1718
}

‎src/aggregator-ruleng/RuleExecutor.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ public async Task<string> ExecuteAsync(IRule rule, WorkItemEventContext eventCon
4343
{
4444
var engine = new RuleEngine(logger, configuration.SaveMode, configuration.DryRun);
4545

46-
var ruleResult = await engine.RunAsync(rule, eventContext.ProjectId, eventContext.WorkItemPayload, clientsContext, cancellationToken);
46+
var ruleResult = await engine.RunAsync(rule, eventContext.ProjectId, eventContext.WorkItemPayload, eventContext.EventType, clientsContext, cancellationToken);
4747
logger.WriteInfo(ruleResult);
4848
return ruleResult;
4949
}
5050
}
5151
}
5252
}
53-
}
53+
}

‎src/aggregator-ruleng/WorkItemEventContext.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ namespace aggregator.Engine
66

77
public class WorkItemEventContext
88
{
9-
public WorkItemEventContext(Guid projectId, Uri collectionUri, WorkItem workItem, WorkItemUpdate workItemUpdate = null)
9+
public WorkItemEventContext(Guid projectId, Uri collectionUri, WorkItem workItem, string eventType, WorkItemUpdate workItemUpdate = null)
1010
{
1111
ProjectId = projectId;
1212
CollectionUri = collectionUri;
1313
WorkItemPayload = new WorkItemData(workItem, workItemUpdate);
14+
EventType = eventType;
1415
}
1516

1617
public WorkItemData WorkItemPayload { get; }
1718
public Guid ProjectId { get; }
1819
public Uri CollectionUri { get; }
20+
public string EventType { get; }
1921
}
2022

2123
public static class WorkItemEventContextExtension

0 commit comments

Comments
 (0)