internal async Task <string> ExecuteAsync(dynamic data, CancellationToken cancellationToken) { string collectionUrl = data.resourceContainers.collection.baseUrl; string eventType = data.eventType; int workItemId = (eventType != "workitem.updated") ? data.resource.id : data.resource.workItemId; Guid teamProjectId = data.resourceContainers.project.id; string teamProjectName = (eventType != "workitem.updated") ? data.resource.fields["System.TeamProject"] : data.resource.revision.fields["System.TeamProject"]; logger.WriteVerbose($"Connecting to Azure DevOps using {configuration.DevOpsTokenType}..."); var clientCredentials = default(VssCredentials); if (configuration.DevOpsTokenType == DevOpsTokenType.PAT) { clientCredentials = new VssBasicCredential(configuration.DevOpsTokenType.ToString(), configuration.DevOpsToken); } else { logger.WriteError($"Azure DevOps Token type {configuration.DevOpsTokenType} not supported!"); throw new ArgumentOutOfRangeException(nameof(configuration.DevOpsTokenType)); } cancellationToken.ThrowIfCancellationRequested(); // TODO improve from https://github.com/Microsoft/vsts-work-item-migrator using (var devops = new VssConnection(new Uri(collectionUrl), clientCredentials)) { await devops.ConnectAsync(cancellationToken); logger.WriteInfo($"Connected to Azure DevOps"); using (var witClient = devops.GetClient <WorkItemTrackingHttpClient>()) { string ruleFilePath = Path.Combine(functionDirectory, $"{ruleName}.rule"); if (!File.Exists(ruleFilePath)) { logger.WriteError($"Rule code not found at {ruleFilePath}"); return("Rule file not found!"); } logger.WriteVerbose($"Rule code found at {ruleFilePath}"); string[] ruleCode; using (var fileStream = File.OpenRead(ruleFilePath)) { var reader = new StreamReader(fileStream); ruleCode = await ReadAllLinesAsync(reader); } var engine = new Engine.RuleEngine(logger, ruleCode, configuration.SaveMode, configuration.DryRun); return(await engine.ExecuteAsync(teamProjectId, teamProjectName, workItemId, witClient, cancellationToken)); } } }
internal async Task <string> Execute(dynamic data) { string collectionUrl = data.resourceContainers.collection.baseUrl; string eventType = data.eventType; int workItemId = (eventType != "workitem.updated") ? data.resource.id : data.resource.workItemId; Guid teamProjectId = data.resourceContainers.project.id; string teamProjectName = (eventType != "workitem.updated") ? data.resource.fields["System.TeamProject"] : data.resource.revision.fields["System.TeamProject"]; logger.WriteVerbose($"Connecting to Azure DevOps using {configuration.DevOpsTokenType}..."); var clientCredentials = default(VssCredentials); if (configuration.DevOpsTokenType == DevOpsTokenType.PAT) { clientCredentials = new VssBasicCredential(configuration.DevOpsTokenType.ToString(), configuration.DevOpsToken); } else { logger.WriteError($"Azure DevOps Token type {configuration.DevOpsTokenType} not supported!"); throw new ArgumentOutOfRangeException(nameof(configuration.DevOpsTokenType)); } using (var devops = new VssConnection(new Uri(collectionUrl), clientCredentials)) { await devops.ConnectAsync(); logger.WriteInfo($"Connected to Azure DevOps"); using (var witClient = devops.GetClient <WorkItemTrackingHttpClient>()) { string ruleFilePath = Path.Combine(functionDirectory, $"{ruleName}.rule"); if (!File.Exists(ruleFilePath)) { logger.WriteError($"Rule code not found at {ruleFilePath}"); return("Rule file not found!"); } logger.WriteVerbose($"Rule code found at {ruleFilePath}"); string[] ruleCode = File.ReadAllLines(ruleFilePath); var engine = new Engine.RuleEngine(logger, ruleCode, configuration.SaveMode); return(await engine.ExecuteAsync(collectionUrl, teamProjectId, teamProjectName, configuration.DevOpsToken, workItemId, witClient)); } } }
internal async Task <string> ExecuteAsync(WorkItemEventContext eventContext, CancellationToken cancellationToken) { logger.WriteVerbose($"Connecting to Azure DevOps using {configuration.DevOpsTokenType}..."); var clientCredentials = default(VssCredentials); if (configuration.DevOpsTokenType == DevOpsTokenType.PAT) { clientCredentials = new VssBasicCredential(configuration.DevOpsTokenType.ToString(), configuration.DevOpsToken); } else { logger.WriteError($"Azure DevOps Token type {configuration.DevOpsTokenType} not supported!"); throw new ArgumentOutOfRangeException(nameof(configuration.DevOpsTokenType)); } cancellationToken.ThrowIfCancellationRequested(); // TODO improve from https://github.com/Microsoft/vsts-work-item-migrator using (var devops = new VssConnection(eventContext.CollectionUri, clientCredentials)) { await devops.ConnectAsync(cancellationToken); logger.WriteInfo($"Connected to Azure DevOps"); using (var clientsContext = new AzureDevOpsClientsContext(devops)) { string ruleFilePath = Path.Combine(functionDirectory, $"{ruleName}.rule"); if (!File.Exists(ruleFilePath)) { logger.WriteError($"Rule code not found at {ruleFilePath}"); return("Rule file not found!"); } logger.WriteVerbose($"Rule code found at {ruleFilePath}"); string[] ruleCode; using (var fileStream = File.OpenRead(ruleFilePath)) { var reader = new StreamReader(fileStream); ruleCode = await ReadAllLinesAsync(reader); } var engine = new Engine.RuleEngine(logger, ruleCode, configuration.SaveMode, configuration.DryRun); return(await engine.ExecuteAsync(eventContext.ProjectId, eventContext.WorkItemPayload, clientsContext, cancellationToken)); } } }