From a2071a86dd380fadb267b2dcbaa449485fbf3f08 Mon Sep 17 00:00:00 2001 From: Necati Meral Date: Fri, 22 Jan 2021 23:31:50 +0100 Subject: [PATCH 1/2] Added Microsoft.AspNetcore.WebHooks.Receivers.AzureDevOps --- src/WebHooks/WebHooks.sln | 22 ++- ...zureDevOpsStronglyTypedCoreReceiver.csproj | 11 ++ .../Controllers/AzureDevOpsController.cs | 35 +++++ .../Program.cs | 17 +++ .../Startup.cs | 25 ++++ .../appsettings.json | 16 +++ .../AzureDevOpsConstants.cs | 22 +++ .../AzureDevOpsWebHookAttribute.cs | 61 ++++++++ .../BasePayload.cs | 81 +++++++++++ .../BaseResource.cs | 13 ++ .../BaseWorkItemResource.cs | 45 ++++++ .../BuildCompletedDefinition.cs | 50 +++++++ .../BuildCompletedDrop.cs | 38 +++++ .../BuildCompletedLog.cs | 32 +++++ .../BuildCompletedPayload.cs | 12 ++ .../BuildCompletedQueueDefinition.cs | 38 +++++ .../BuildCompletedRequest.cs | 32 +++++ .../BuildCompletedResource.cs | 128 +++++++++++++++++ .../CodeCheckedInPayload.cs | 12 ++ .../CodeCheckedInResource.cs | 50 +++++++ .../AzureDevOpsMvcBuilderExtensions.cs | 43 ++++++ .../AzureDevOpsMvcCoreBuilderExtensions.cs | 45 ++++++ .../AzureDevOpsServiceCollectionSetup.cs | 28 ++++ .../GitCommit.cs | 44 ++++++ .../GitLink.cs | 20 +++ .../GitMergeCommit.cs | 26 ++++ .../GitProject.cs | 38 +++++ .../GitPullLinks.cs | 67 +++++++++ .../GitPullRequestCreatedPayload.cs | 12 ++ ...GitPullRequestMergeCommitCreatedPayload.cs | 12 ++ ...itPullRequestMergeCommitCreatedResource.cs | 12 ++ .../GitPullRequestResource.cs | 132 ++++++++++++++++++ .../GitPullRequestUpdatedPayload.cs | 12 ++ .../GitPullRequestUpdatedResource.cs | 20 +++ .../GitPushLinks.cs | 43 ++++++ .../GitPushPayload.cs | 12 ++ .../GitPushResource.cs | 72 ++++++++++ .../GitRefUpdate.cs | 31 ++++ .../GitRepository.cs | 50 +++++++ .../GitReviewer.cs | 32 +++++ .../GitUser.cs | 44 ++++++ .../GitUserInfo.cs | 32 +++++ .../Metadata/AzureDevOpsMetadata.cs | 35 +++++ ...Core.WebHooks.Receivers.AzureDevOps.csproj | 17 +++ .../PayloadMessage.cs | 31 ++++ .../PayloadResourceContainer.cs | 19 +++ .../PayloadResourceContainers.cs | 31 ++++ .../Properties/Resources.Designer.cs | 72 ++++++++++ .../Properties/Resources.resx | 123 ++++++++++++++++ .../ResourceUser.cs | 44 ++++++ .../TeamRoomMessagePostedPayload.cs | 12 ++ .../TeamRoomMessagePostedResource.cs | 50 +++++++ .../WorkItemCommentedOnPayload.cs | 12 ++ .../WorkItemCommentedOnResource.cs | 12 ++ .../WorkItemCreatedPayload.cs | 12 ++ .../WorkItemCreatedResource.cs | 12 ++ .../WorkItemDeletedPayload.cs | 12 ++ .../WorkItemDeletedResource.cs | 12 ++ .../WorkItemFields.cs | 104 ++++++++++++++ .../WorkItemLink.cs | 19 +++ .../WorkItemLinks.cs | 61 ++++++++ .../WorkItemRestoredPayload.cs | 12 ++ .../WorkItemRestoredResource.cs | 12 ++ .../WorkItemUpdatedFieldValue.cs | 26 ++++ .../WorkItemUpdatedFields.cs | 68 +++++++++ .../WorkItemUpdatedPayload.cs | 12 ++ .../WorkItemUpdatedResource.cs | 38 +++++ .../WorkItemUpdatedRevision.cs | 38 +++++ 68 files changed, 2459 insertions(+), 4 deletions(-) create mode 100644 src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/AzureDevOpsStronglyTypedCoreReceiver.csproj create mode 100644 src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/Controllers/AzureDevOpsController.cs create mode 100644 src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/Program.cs create mode 100644 src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/Startup.cs create mode 100644 src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/appsettings.json create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/AzureDevOpsConstants.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/AzureDevOpsWebHookAttribute.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BasePayload.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BaseResource.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BaseWorkItemResource.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedDefinition.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedDrop.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedLog.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedPayload.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedQueueDefinition.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedRequest.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedResource.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/CodeCheckedInPayload.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/CodeCheckedInResource.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Extensions/AzureDevOpsMvcBuilderExtensions.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Extensions/AzureDevOpsMvcCoreBuilderExtensions.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Extensions/AzureDevOpsServiceCollectionSetup.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitCommit.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitLink.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitMergeCommit.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitProject.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullLinks.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullRequestCreatedPayload.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullRequestMergeCommitCreatedPayload.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullRequestMergeCommitCreatedResource.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullRequestResource.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullRequestUpdatedPayload.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullRequestUpdatedResource.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPushLinks.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPushPayload.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPushResource.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitRefUpdate.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitRepository.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitReviewer.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitUser.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitUserInfo.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Metadata/AzureDevOpsMetadata.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps.csproj create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/PayloadMessage.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/PayloadResourceContainer.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/PayloadResourceContainers.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Properties/Resources.Designer.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Properties/Resources.resx create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/ResourceUser.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/TeamRoomMessagePostedPayload.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/TeamRoomMessagePostedResource.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemCommentedOnPayload.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemCommentedOnResource.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemCreatedPayload.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemCreatedResource.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemDeletedPayload.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemDeletedResource.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemFields.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemLink.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemLinks.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemRestoredPayload.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemRestoredResource.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemUpdatedFieldValue.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemUpdatedFields.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemUpdatedPayload.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemUpdatedResource.cs create mode 100644 src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemUpdatedRevision.cs diff --git a/src/WebHooks/WebHooks.sln b/src/WebHooks/WebHooks.sln index 6df629902..54467e146 100644 --- a/src/WebHooks/WebHooks.sln +++ b/src/WebHooks/WebHooks.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27110.0 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30711.63 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Src", "Src", "{929F44D0-A040-4DC3-A22F-4C5829C05D44}" ProjectSection(SolutionItems) = preProject @@ -35,7 +35,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GitHubCoreReceiver", "sampl EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.WebHooks.Receivers.AzureAlert", "src\Microsoft.AspNetCore.WebHooks.Receivers.AzureAlert\Microsoft.AspNetCore.WebHooks.Receivers.AzureAlert.csproj", "{FAE4E7F8-7786-4388-802D-69C5C40DD5ED}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.WebHooks.Receivers.AzureContainerRegistry", "src\Microsoft.AspNetCore.WebHooks.Receivers.AzureContainerRegistry\Microsoft.AspNetCore.WebHooks.Receivers.AzureContainerRegistry.csproj", "{B4297872-1ED3-4A5D-95A8-0C1A11FDF781}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.WebHooks.Receivers.AzureContainerRegistry", "src\Microsoft.AspNetCore.WebHooks.Receivers.AzureContainerRegistry\Microsoft.AspNetCore.WebHooks.Receivers.AzureContainerRegistry.csproj", "{B4297872-1ED3-4A5D-95A8-0C1A11FDF781}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.WebHooks.Receivers.BitBucket", "src\Microsoft.AspNetCore.WebHooks.Receivers.BitBucket\Microsoft.AspNetCore.WebHooks.Receivers.BitBucket.csproj", "{06B0D9D1-1368-423E-B2F7-5F408423A187}" EndProject @@ -99,6 +99,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TrelloCoreReceiver", "sampl EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.WebHooks.FunctionalTest", "test\Microsoft.AspNetCore.WebHooks.FunctionalTest\Microsoft.AspNetCore.WebHooks.FunctionalTest.csproj", "{F42E56B7-60D4-481A-8585-04015B2B501E}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps", "src\Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps\Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps.csproj", "{820D031D-237E-4892-A0BD-EF341421066A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureDevOpsStronglyTypedCoreReceiver", "samples\AzureDevOpstronglyTypedCoreReceiver\AzureDevOpsStronglyTypedCoreReceiver.csproj", "{DAE01DE1-421B-420C-87DE-74ED9279A034}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -249,6 +253,14 @@ Global {F42E56B7-60D4-481A-8585-04015B2B501E}.Debug|Any CPU.Build.0 = Debug|Any CPU {F42E56B7-60D4-481A-8585-04015B2B501E}.Release|Any CPU.ActiveCfg = Release|Any CPU {F42E56B7-60D4-481A-8585-04015B2B501E}.Release|Any CPU.Build.0 = Release|Any CPU + {820D031D-237E-4892-A0BD-EF341421066A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {820D031D-237E-4892-A0BD-EF341421066A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {820D031D-237E-4892-A0BD-EF341421066A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {820D031D-237E-4892-A0BD-EF341421066A}.Release|Any CPU.Build.0 = Release|Any CPU + {DAE01DE1-421B-420C-87DE-74ED9279A034}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DAE01DE1-421B-420C-87DE-74ED9279A034}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DAE01DE1-421B-420C-87DE-74ED9279A034}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DAE01DE1-421B-420C-87DE-74ED9279A034}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -290,9 +302,11 @@ Global {91E02D64-BA6E-473C-A250-D1051A50DDAB} = {9575CB90-BC4B-43BB-8AEA-82C53FDA4187} {E9E37253-3FE1-44A4-A9E7-A2B6C54EECFE} = {E957C8D9-B4A0-488B-838F-BAB4DE080A76} {F42E56B7-60D4-481A-8585-04015B2B501E} = {9575CB90-BC4B-43BB-8AEA-82C53FDA4187} + {820D031D-237E-4892-A0BD-EF341421066A} = {929F44D0-A040-4DC3-A22F-4C5829C05D44} + {DAE01DE1-421B-420C-87DE-74ED9279A034} = {E957C8D9-B4A0-488B-838F-BAB4DE080A76} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {12CE6238-F847-4984-8622-1ED46072150A} EnterpriseLibraryConfigurationToolBinariesPathV6 = packages\EnterpriseLibrary.TransientFaultHandling.6.0.1304.0\lib\portable-net45+win+wp8;packages\EnterpriseLibrary.TransientFaultHandling.Data.6.0.1304.1\lib\NET45 + SolutionGuid = {12CE6238-F847-4984-8622-1ED46072150A} EndGlobalSection EndGlobal diff --git a/src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/AzureDevOpsStronglyTypedCoreReceiver.csproj b/src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/AzureDevOpsStronglyTypedCoreReceiver.csproj new file mode 100644 index 000000000..c8685dd78 --- /dev/null +++ b/src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/AzureDevOpsStronglyTypedCoreReceiver.csproj @@ -0,0 +1,11 @@ + + + $(StandardTestWebsiteTfms) + + + + + + + + diff --git a/src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/Controllers/AzureDevOpsController.cs b/src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/Controllers/AzureDevOpsController.cs new file mode 100644 index 000000000..72f35313b --- /dev/null +++ b/src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/Controllers/AzureDevOpsController.cs @@ -0,0 +1,35 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.WebHooks; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json.Linq; + +namespace AzureDevOpsStronglyTypedCoreReceiver.Controllers +{ + public class AzureDevOpsController : ControllerBase + { + private readonly ILogger _logger; + + public AzureDevOpsController(ILoggerFactory loggerFactory) + { + _logger = loggerFactory.CreateLogger(); + } + + [AzureDevOpsWebHook] + public IActionResult AzureDevOps(string id, string @event, string webHookId, JObject data) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + _logger.LogInformation( + 1, + $"{nameof(AzureDevOpsController)} / '{{Id}}' received '{{EventName}}' and '{{WebHookId}}'.", + id, + @event, + webHookId); + + return Ok(); + } + } +} diff --git a/src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/Program.cs b/src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/Program.cs new file mode 100644 index 000000000..7e7296634 --- /dev/null +++ b/src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/Program.cs @@ -0,0 +1,17 @@ +using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Hosting; + +namespace AzureDevOpsStronglyTypedCoreReceiver +{ + public class Program + { + public static void Main(string[] args) + { + CreateWebHostBuilder(args).Build().Run(); + } + + public static IWebHostBuilder CreateWebHostBuilder(string[] args) => + WebHost.CreateDefaultBuilder(args) + .UseStartup(); + } +} diff --git a/src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/Startup.cs b/src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/Startup.cs new file mode 100644 index 000000000..bc8f5527e --- /dev/null +++ b/src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/Startup.cs @@ -0,0 +1,25 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; + +namespace AzureDevOpsStronglyTypedCoreReceiver +{ + public class Startup + { + // This method gets called by the runtime. Use this method to add services to the container. + // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 + public void ConfigureServices(IServiceCollection services) + { + services + .AddMvcCore() + .AddAzureDevOpsWebHooks() + .AddDataAnnotations(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IHostingEnvironment env) + { + app.UseMvc(); + } + } +} diff --git a/src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/appsettings.json b/src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/appsettings.json new file mode 100644 index 000000000..e5c9d1634 --- /dev/null +++ b/src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/appsettings.json @@ -0,0 +1,16 @@ +{ + "WebHooks:AzureDevOps:SecretKey:default": "01234567890123456789012345678901", + "Logging": { + "IncludeScopes": false, + "LogLevel": { + "Default": "Warning" + }, + "Console": { + "LogLevel": { + "AzureDevOpsStronglyTypedCoreReceiver": "Information", + "Default": "Warning", + "Microsoft": "Information" + } + } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/AzureDevOpsConstants.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/AzureDevOpsConstants.cs new file mode 100644 index 000000000..1e753b9dd --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/AzureDevOpsConstants.cs @@ -0,0 +1,22 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Well-known names used in Azure DevOps receivers and handlers. + /// + public static class AzureDevOpsConstants + { + /// + /// Gets the JSON path of the property in an Azure DevOps WebHook request body containing the Azure DevOps event + /// type. + /// + public static string EventBodyPropertyPath => "$['eventType']"; + + /// + /// Gets the name of the Azure DevOps WebHook receiver. + /// + public static string ReceiverName => "azuredevops"; + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/AzureDevOpsWebHookAttribute.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/AzureDevOpsWebHookAttribute.cs new file mode 100644 index 000000000..13eef0629 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/AzureDevOpsWebHookAttribute.cs @@ -0,0 +1,61 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Infrastructure; +using Microsoft.AspNetCore.WebHooks.Filters; +using Microsoft.AspNetCore.WebHooks.Metadata; +using Microsoft.AspNetCore.WebHooks.Properties; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// + /// An indicating the associated action is an Azure DevOps WebHook endpoint. Specifies the + /// optional . Also adds a and a + /// (unless + /// is ) for the action. + /// + /// + /// The signature of the action should be: + /// + /// Task{IActionResult} ActionName(string id, string @event, TData data) + /// + /// or include the subset of parameters required. TData must be compatible with expected requests e.g. + /// or . + /// + /// + /// An example Azure DevOps WebHook URI is + /// 'https://{host}/api/webhooks/incoming/azuredevops/{id}?code=83699ec7c1d794c0c780e49a5c72972590571fd8'. + /// See + /// + /// for additional details about Azure DevOps WebHook requests. + /// + /// + /// + /// + /// If the application enables CORS in general (see the Microsoft.AspNetCore.Cors package), apply + /// DisableCorsAttribute to this action. If the application depends on the + /// Microsoft.AspNetCore.Mvc.ViewFeatures package, apply IgnoreAntiforgeryTokenAttribute to this + /// action. + /// + /// + /// should be used at most once per and + /// in a WebHook application. + /// + /// + public class AzureDevOpsWebHookAttribute : WebHookAttribute + { + private string _eventName; + + /// + /// Instantiates a new indicating the associated action is an Azure + /// DevOps WebHook endpoint. + /// + public AzureDevOpsWebHookAttribute() + : base(AzureDevOpsConstants.ReceiverName) + { + } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BasePayload.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BasePayload.cs new file mode 100644 index 000000000..6f23fdcd6 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BasePayload.cs @@ -0,0 +1,81 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Root object of payload sent for all types of events. + /// + /// Type of resource within payload which differs depending on 'eventType' field + public abstract class BasePayload where T : BaseResource + { + /// + /// Gets the subscription identifier which triggered the event. + /// + [JsonProperty("subscriptionId")] + public string SubscriptionId { get; set; } + + /// + /// Gets the notification identifier within subscription. + /// + [JsonProperty("notificationId")] + public int NotificationId { get; set; } + + /// + /// Gets the identifier of HTTP request. + /// + [JsonProperty("id")] + public string Id { get; set; } + + /// + /// Gets the type of the event. + /// + [JsonProperty("eventType")] + public string EventType { get; set; } + + /// + /// Gets the publisher identifier. + /// + [JsonProperty("publisherId")] + public string PublisherId { get; set; } + + /// + /// Gets the message which describes the event. + /// + [JsonProperty("message")] + public PayloadMessage Message { get; set; } + + /// + /// Gets the detailed message which describes the event. + /// + [JsonProperty("detailedMessage")] + public PayloadMessage DetailedMessage { get; set; } + + /// + /// Gets the resource itself - data associated with corresponding event. + /// + [JsonProperty("resource")] + public T Resource { get; set; } + + /// + /// Gets the resource version. + /// + [JsonProperty("resourceVersion")] + public string ResourceVersion { get; set; } + + /// + /// Gets the resource containers. + /// + [JsonProperty("resourceContainers")] + public PayloadResourceContainers ResourceContainers { get; set; } + + /// + /// Gets the date when HTTP request was created. + /// + [JsonProperty("createdDate")] + public DateTime CreatedDate { get; set; } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BaseResource.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BaseResource.cs new file mode 100644 index 000000000..b446b9688 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BaseResource.cs @@ -0,0 +1,13 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Base class for resource object which describes + /// a specific event type. + /// + public abstract class BaseResource + { + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BaseWorkItemResource.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BaseWorkItemResource.cs new file mode 100644 index 000000000..6b7a34681 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BaseWorkItemResource.cs @@ -0,0 +1,45 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Base class for resource object which describes WorkItem event types. + /// + /// Type which describes fields associated with this kind of WorkItem change + public abstract class BaseWorkItemResource : BaseResource + { + /// + /// Gets the identifier of WorkItem. + /// + [JsonProperty("id")] + public int Id { get; set; } + + /// + /// Gets the revision number. + /// + [JsonProperty("rev")] + public int RevisionNumber { get; set; } + + /// + /// Gets fields associated with the WorkItem. + /// + [JsonProperty("fields")] + public T Fields { get; set; } + + /// + /// Gets links associated with the WorkItem. + /// + [JsonProperty("_links")] + public WorkItemLinks Links { get; set; } + + /// + /// Gets the URL of the WorkItem. + /// + [JsonProperty("url")] + public Uri Url { get; set; } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedDefinition.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedDefinition.cs new file mode 100644 index 000000000..6457d3314 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedDefinition.cs @@ -0,0 +1,50 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes build definition + /// + public class BuildCompletedDefinition + { + /// + /// Gets the size of the batch. + /// + [JsonProperty("batchSize")] + public int BatchSize { get; set; } + + /// + /// Gets the trigger type. + /// + [JsonProperty("triggerType")] + public string TriggerType { get; set; } + + /// + /// Gets the trigger type. + /// + [JsonProperty("definitionType")] + public string DefinitionType { get; set; } + + /// + /// Gets the identifier of the build definition. + /// + [JsonProperty("id")] + public int Id { get; set; } + + /// + /// Gets the name of the build definition. + /// + [JsonProperty("name")] + public string Name { get; set; } + + /// + /// Gets the URL of the build definition. + /// + [JsonProperty("url")] + public Uri Url { get; set; } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedDrop.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedDrop.cs new file mode 100644 index 000000000..381f02625 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedDrop.cs @@ -0,0 +1,38 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes build drop + /// + public class BuildCompletedDrop + { + /// + /// Gets drop location. + /// + [JsonProperty("location")] + public string Location { get; set; } + + /// + /// Gets drop type. + /// + [JsonProperty("type")] + public string DropType { get; set; } + + /// + /// Gets drop location URL. + /// + [JsonProperty("url")] + public Uri Url { get; set; } + + /// + /// Gets drop location download URL. + /// + [JsonProperty("downloadUrl")] + public Uri DownloadUrl { get; set; } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedLog.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedLog.cs new file mode 100644 index 000000000..6ef1a24cc --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedLog.cs @@ -0,0 +1,32 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes build log + /// + public class BuildCompletedLog + { + /// + /// Gets the log type. + /// + [JsonProperty("type")] + public string LogType { get; set; } + + /// + /// Gets the log URL. + /// + [JsonProperty("url")] + public Uri Url { get; set; } + + /// + /// Gets the log download URL. + /// + [JsonProperty("downloadUrl")] + public Uri DownloadUrl { get; set; } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedPayload.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedPayload.cs new file mode 100644 index 000000000..80ec71c65 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedPayload.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the entire payload of event 'build.complete'. + /// + public class BuildCompletedPayload : BasePayload + { + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedQueueDefinition.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedQueueDefinition.cs new file mode 100644 index 000000000..575aefe04 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedQueueDefinition.cs @@ -0,0 +1,38 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the queue of the build. + /// + public class BuildCompletedQueueDefinition + { + /// + /// Gets the type of the queue. + /// + [JsonProperty("queueType")] + public string QueueType { get; set; } + + /// + /// Gets the identifier of the queue. + /// + [JsonProperty("id")] + public int Id { get; set; } + + /// + /// Gets the name of the queue. + /// + [JsonProperty("name")] + public string Name { get; set; } + + /// + /// Gets the URL of the queue. + /// + [JsonProperty("url")] + public Uri Url { get; set; } + } +} \ No newline at end of file diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedRequest.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedRequest.cs new file mode 100644 index 000000000..4e34c840a --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedRequest.cs @@ -0,0 +1,32 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the request of the build. + /// + public class BuildCompletedRequest + { + /// + /// Gets the identifier of the request. + /// + [JsonProperty("id")] + public int Id { get; set; } + + /// + /// Gets the URL of the request. + /// + [JsonProperty("url")] + public Uri Url { get; set; } + + /// + /// Gets the user associated with the request. + /// + [JsonProperty("requestedFor")] + public ResourceUser RequestedFor { get; set; } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedResource.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedResource.cs new file mode 100644 index 000000000..6b270c805 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/BuildCompletedResource.cs @@ -0,0 +1,128 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.ObjectModel; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the resource that associated with + /// + public class BuildCompletedResource : BaseResource + { + private readonly Collection _requests = new Collection(); + + /// + /// Gets the build URI. + /// + [JsonProperty("uri")] + public Uri Uri { get; set; } + + /// + /// Gets the build identifier. + /// + [JsonProperty("id")] + public int Id { get; set; } + + /// + /// Gets the build number. + /// + [JsonProperty("buildNumber")] + public string BuildNumber { get; set; } + + /// + /// Gets the build URL. + /// + [JsonProperty("url")] + public Uri Url { get; set; } + + /// + /// Gets the start time of the build. + /// + [JsonProperty("startTime")] + public DateTime StartTime { get; set; } + + /// + /// Gets the finish time of the build. + /// + [JsonProperty("finishTime")] + public DateTime FinishTime { get; set; } + + /// + /// Gets the reason which triggered the build. + /// + [JsonProperty("reason")] + public string Reason { get; set; } + + /// + /// Gets the outcome status of the build. + /// + [JsonProperty("status")] + public string Status { get; set; } + + /// + /// Gets the build drop location. + /// + [JsonProperty("dropLocation")] + public string DropLocation { get; set; } + + /// + /// Gets the build drop. + /// + [JsonProperty("drop")] + public BuildCompletedDrop Drop { get; set; } + + /// + /// Gets the build log. + /// + [JsonProperty("log")] + public BuildCompletedLog Log { get; set; } + + /// + /// Gets the source version for the build. + /// + [JsonProperty("sourceGetVersion")] + public string SourceGetVersion { get; set; } + + /// + /// Gets the user which last changed the source. + /// + [JsonProperty("lastChangedBy")] + public ResourceUser LastChangedBy { get; set; } + + /// + /// Gets value indicating whether this build retain indefinitely. + /// + [JsonProperty("retainIndefinitely")] + public bool RetainIndefinitely { get; set; } + + /// + /// Gets value indicating whether this build has diagnostics. + /// + [JsonProperty("hasDiagnostics")] + public bool HasDiagnostics { get; set; } + + /// + /// Gets the definition of the build. + /// + [JsonProperty("definition")] + public BuildCompletedDefinition Definition { get; set; } + + /// + /// Gets the build queue. + /// + [JsonProperty("queue")] + public BuildCompletedQueueDefinition Queue { get; set; } + + /// + /// Gets build requests. + /// + [JsonProperty("requests")] + public Collection Requests + { + get { return _requests; } + } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/CodeCheckedInPayload.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/CodeCheckedInPayload.cs new file mode 100644 index 000000000..36786fea7 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/CodeCheckedInPayload.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the entire payload of event 'tfvc.checkin'. + /// + public class CodeCheckedInPayload : BasePayload + { + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/CodeCheckedInResource.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/CodeCheckedInResource.cs new file mode 100644 index 000000000..3e7b01ffb --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/CodeCheckedInResource.cs @@ -0,0 +1,50 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the resource that associated with + /// + public class CodeCheckedInResource : BaseResource + { + /// + /// Gets the changeset identifier. + /// + [JsonProperty("changesetId")] + public int ChangesetId { get; set; } + + /// + /// Gets the changeset URL. + /// + [JsonProperty("url")] + public Uri Url { get; set; } + + /// + /// Gets the changeset author. + /// + [JsonProperty("author")] + public ResourceUser Author { get; set; } + + /// + /// Gets the user that checked in the changeset. + /// + [JsonProperty("checkedInBy")] + public ResourceUser CheckedInBy { get; set; } + + /// + /// Gets the changeset creation date. + /// + [JsonProperty("createdDate")] + public DateTime CreatedDate { get; set; } + + /// + /// Gets the changeset comment. + /// + [JsonProperty("comment")] + public string Comment { get; set; } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Extensions/AzureDevOpsMvcBuilderExtensions.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Extensions/AzureDevOpsMvcBuilderExtensions.cs new file mode 100644 index 000000000..349d9c999 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Extensions/AzureDevOpsMvcBuilderExtensions.cs @@ -0,0 +1,43 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.ComponentModel; + +namespace Microsoft.Extensions.DependencyInjection +{ + /// + /// Extension methods for setting up Azure DevOps WebHooks in an . + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public static class AzureDevOpsMvcBuilderExtensions + { + /// + /// + /// Add Azure DevOps WebHook configuration and services to the specified . See + /// + /// for additional details about Azure DevOps WebHook requests. + /// + /// + /// The 'WebHooks:AzureDevOps:SecretKey:default' configuration value contains the secret key for Azure + /// DevOps WebHook URIs of the form 'https://{host}/api/webhooks/incoming/azuredevops?code={secret key}'. + /// 'WebHooks:AzureDevOps:SecretKey:{id}' configuration values contain secret keys for + /// Azure DevOps WebHook URIs of the form + /// 'https://{host}/api/webhooks/incoming/azuredevops/{id}?code={secret key}'. + /// + /// + /// The to configure. + /// The . + public static IMvcBuilder AddAzureDevOpsWebHooks(this IMvcBuilder builder) + { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + AzureDevOpsServiceCollectionSetup.AddAzureDevOpsServices(builder.Services); + + return builder.AddWebHooks(); + } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Extensions/AzureDevOpsMvcCoreBuilderExtensions.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Extensions/AzureDevOpsMvcCoreBuilderExtensions.cs new file mode 100644 index 000000000..598efc55f --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Extensions/AzureDevOpsMvcCoreBuilderExtensions.cs @@ -0,0 +1,45 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.ComponentModel; + +namespace Microsoft.Extensions.DependencyInjection +{ + /// + /// Extension methods for setting up Azure DevOps WebHooks in an . + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public static class AzureDevOpsMvcCoreBuilderExtensions + { + /// + /// + /// Add Azure DevOps WebHook configuration and services to the specified . See + /// + /// for additional details about Azure DevOps WebHook requests. + /// + /// + /// The 'WebHooks:AzureDevOps:SecretKey:default' configuration value contains the secret key for Azure + /// DevOps WebHook URIs of the form 'https://{host}/api/webhooks/incoming/azureDevOps?code={secret key}'. + /// 'WebHooks:AzureDevOps:SecretKey:{id}' configuration values contain secret keys for + /// Azure DevOps WebHook URIs of the form + /// 'https://{host}/api/webhooks/incoming/azuredevops/{id}?code={secret key}'. + /// + /// + /// The to configure. + /// The . + public static IMvcCoreBuilder AddAzureDevOpsWebHooks(this IMvcCoreBuilder builder) + { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + AzureDevOpsServiceCollectionSetup.AddAzureDevOpsServices(builder.Services); + + return builder + .AddJsonFormatters() + .AddWebHooks(); + } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Extensions/AzureDevOpsServiceCollectionSetup.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Extensions/AzureDevOpsServiceCollectionSetup.cs new file mode 100644 index 000000000..120145003 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Extensions/AzureDevOpsServiceCollectionSetup.cs @@ -0,0 +1,28 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.WebHooks.Metadata; + +namespace Microsoft.Extensions.DependencyInjection +{ + /// + /// Methods to add services for the Azure DevOps receiver. + /// + internal static class AzureDevOpsServiceCollectionSetup + { + /// + /// Add services for the Azure DevOps receiver. + /// + /// The to update. + public static void AddAzureDevOpsServices(IServiceCollection services) + { + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + + WebHookMetadata.Register(services); + } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitCommit.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitCommit.cs new file mode 100644 index 000000000..7c94ed127 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitCommit.cs @@ -0,0 +1,44 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Contains information about the commit. + /// + public class GitCommit + { + /// + /// The Id of the commit. + /// + [JsonProperty("commitId")] + public string CommitId { get; set; } + + /// + /// The user that authorized the commit. + /// + [JsonProperty("author")] + public GitUserInfo Author { get; set; } + + /// + /// The user that committed the commit. + /// + [JsonProperty("committer")] + public GitUserInfo Committer { get; set; } + + /// + /// The commit comment. + /// + [JsonProperty("comment")] + public string Comment { get; set; } + + /// + /// The url of the commit. + /// + [JsonProperty("url")] + public Uri Url { get; set; } + } +} \ No newline at end of file diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitLink.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitLink.cs new file mode 100644 index 000000000..8eee22285 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitLink.cs @@ -0,0 +1,20 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// The link. + /// + public class GitLink + { + /// + /// The url. + /// + [JsonProperty("href")] + public Uri Href { get; set; } + } +} \ No newline at end of file diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitMergeCommit.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitMergeCommit.cs new file mode 100644 index 000000000..e7f4bde8f --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitMergeCommit.cs @@ -0,0 +1,26 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Merge Commit Information + /// + public class GitMergeCommit + { + /// + /// Commit Id + /// + [JsonProperty("commitId")] + public string CommitId { get; set; } + + /// + /// Commit Url + /// + [JsonProperty("url")] + public Uri Url { get; set; } + } +} \ No newline at end of file diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitProject.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitProject.cs new file mode 100644 index 000000000..a8ee1688a --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitProject.cs @@ -0,0 +1,38 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Information about a project. + /// + public class GitProject + { + /// + /// The project Id. + /// + [JsonProperty("id")] + public string Id { get; set; } + + /// + /// The project name. + /// + [JsonProperty("name")] + public string Name { get; set; } + + /// + /// The url of the project. + /// + [JsonProperty("url")] + public Uri Url { get; set; } + + /// + /// The state of the project. + /// + [JsonProperty("state")] + public string State { get; set; } + } +} \ No newline at end of file diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullLinks.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullLinks.cs new file mode 100644 index 000000000..d49d1fb13 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullLinks.cs @@ -0,0 +1,67 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Links for the Pull Request + /// + public class GitPullLinks + { + /// + /// Pull Request Link + /// + [JsonProperty("self")] + public GitLink Self { get; set; } + + /// + /// Link to pull request web view + /// + [JsonProperty("web")] + public GitLink Web { get; set; } + + /// + /// Repository Link + /// + [JsonProperty("repository")] + public GitLink Repository { get; set; } + + /// + /// Link to Work Items + /// + [JsonProperty("workItems")] + public GitLink WorkItems { get; set; } + + /// + /// Link to the Source Branch + /// + [JsonProperty("sourceBranch")] + public GitLink SourceBranch { get; set; } + + /// + /// Link to the Target Branch + /// + [JsonProperty("targetBranch")] + public GitLink TargetBranch { get; set; } + + /// + /// Link to the Source Commit + /// + [JsonProperty("sourceCommit")] + public GitLink SourceCommit { get; set; } + + /// + /// Link to the Target Commit + /// + [JsonProperty("targetCommit")] + public GitLink TargetCommit { get; set; } + + /// + /// Link to user that created the Commit + /// + [JsonProperty("createdBy")] + public GitLink CreatedBy { get; set; } + } +} \ No newline at end of file diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullRequestCreatedPayload.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullRequestCreatedPayload.cs new file mode 100644 index 000000000..acc9655f3 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullRequestCreatedPayload.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Payload for the creation of a pull request + /// + public class GitPullRequestCreatedPayload : BasePayload + { + } +} \ No newline at end of file diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullRequestMergeCommitCreatedPayload.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullRequestMergeCommitCreatedPayload.cs new file mode 100644 index 000000000..ec203f1cc --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullRequestMergeCommitCreatedPayload.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Payload for the creation of a merge commit. + /// + public class GitPullRequestMergeCommitCreatedPayload : BasePayload + { + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullRequestMergeCommitCreatedResource.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullRequestMergeCommitCreatedResource.cs new file mode 100644 index 000000000..55b0e83b4 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullRequestMergeCommitCreatedResource.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the resource that associated with + /// + public class GitPullRequestMergeCommitCreatedResource : GitPullRequestUpdatedResource + { + } +} \ No newline at end of file diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullRequestResource.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullRequestResource.cs new file mode 100644 index 000000000..576c1e150 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullRequestResource.cs @@ -0,0 +1,132 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.ObjectModel; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the resource that associated with + /// + public class GitPullRequestResource : BaseResource + { + private readonly Collection _reviewers = new Collection(); + private readonly Collection _commits = new Collection(); + + /// + /// The repository being updated + /// + [JsonProperty("repository")] + public GitRepository Repository { get; set; } + + /// + /// The Id of the Pull Request + /// + [JsonProperty("pullRequestId")] + public int PullRequestId { get; set; } + + /// + /// The Status of the Pull Request + /// + [JsonProperty("status")] + public string Status { get; set; } + + /// + /// The user creating the Pull Request + /// + [JsonProperty("createdBy")] + public GitUser CreatedBy { get; set; } + + /// + /// The date the Pull Request was created. + /// + [JsonProperty("creationDate")] + public DateTime CreationDate { get; set; } + + /// + /// The title of the Pull Request. + /// + [JsonProperty("title")] + public string Title { get; set; } + + /// + /// The Description of the Pull Request + /// + [JsonProperty("description")] + public string Description { get; set; } + + /// + /// Source Reference Name + /// + [JsonProperty("sourceRefName")] + public string SourceRefName { get; set; } + + /// + /// Target Reference Name + /// + [JsonProperty("targetRefName")] + public string TargetRefName { get; set; } + + /// + /// Merge Status + /// + [JsonProperty("mergeStatus")] + public string MergeStatus { get; set; } + + /// + /// Merge Id + /// + [JsonProperty("mergeId")] + public string MergeId { get; set; } + + /// + /// Last Merge Source Commit + /// + [JsonProperty("lastMergeSourceCommit")] + public GitMergeCommit LastMergeSourceCommit { get; set; } + + /// + /// Last Merge Target Commit + /// + [JsonProperty("lastMergeTargetCommit")] + public GitMergeCommit LastMergeTargetCommit { get; set; } + + /// + /// Last Merge Commit + /// + [JsonProperty("lastMergeCommit")] + public GitMergeCommit LastMergeCommit { get; set; } + + /// + /// Pull Request Reviewers + /// + [JsonProperty("reviewers")] + public Collection Reviewers + { + get { return _reviewers; } + } + + /// + /// Pull Request Url + /// + [JsonProperty("url")] + public Uri Url { get; set; } + + /// + /// Commit Links + /// + [JsonProperty("_links")] + public GitPullLinks Links { get; set; } + + /// + /// A list of commits in the pull request + /// + [JsonProperty("commits")] + public Collection Commits + { + get { return _commits; } + } + } +} \ No newline at end of file diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullRequestUpdatedPayload.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullRequestUpdatedPayload.cs new file mode 100644 index 000000000..3eda577f7 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullRequestUpdatedPayload.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Payload for the update of a pull request + /// + public class GitPullRequestUpdatedPayload : BasePayload + { + } +} \ No newline at end of file diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullRequestUpdatedResource.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullRequestUpdatedResource.cs new file mode 100644 index 000000000..ebe3df9ab --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPullRequestUpdatedResource.cs @@ -0,0 +1,20 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the resource that associated with + /// + public class GitPullRequestUpdatedResource : GitPullRequestResource + { + /// + /// The date the Pull Request was closed. + /// + [JsonProperty("closedDate")] + public DateTime ClosedDate { get; set; } + } +} \ No newline at end of file diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPushLinks.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPushLinks.cs new file mode 100644 index 000000000..4f8213892 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPushLinks.cs @@ -0,0 +1,43 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// A collection of links about this push. + /// + public class GitPushLinks + { + /// + /// The link to the push. + /// + [JsonProperty("self")] + public GitLink Self { get; set; } + + /// + /// The link to the repository. + /// + [JsonProperty("repository")] + public GitLink Repository { get; set; } + + /// + /// The link to the commits. + /// + [JsonProperty("commits")] + public GitLink Commits { get; set; } + + /// + /// The link to the user pushing the code. + /// + [JsonProperty("pusher")] + public GitLink Pusher { get; set; } + + /// + /// The link to any references. + /// + [JsonProperty("refs")] + public GitLink Refs { get; set; } + } +} \ No newline at end of file diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPushPayload.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPushPayload.cs new file mode 100644 index 000000000..544882459 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPushPayload.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the entire payload of event 'git.push'. + /// + public class GitPushPayload : BasePayload + { + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPushResource.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPushResource.cs new file mode 100644 index 000000000..6632689b5 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitPushResource.cs @@ -0,0 +1,72 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.ObjectModel; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the resource that associated with + /// + public class GitPushResource : BaseResource + { + private readonly Collection _commits = new Collection(); + private readonly Collection _refUpdates = new Collection(); + + /// + /// List of Commits in the push. + /// + [JsonProperty("commits")] + public Collection Commits + { + get { return _commits; } + } + + /// + /// List of Reference updates. + /// + [JsonProperty("refUpdates")] + public Collection RefUpdates + { + get { return _refUpdates; } + } + + /// + /// The repository being updated + /// + [JsonProperty("repository")] + public GitRepository Repository { get; set; } + + /// + /// The user pushing the code. + /// + [JsonProperty("pushedBy")] + public GitUser PushedBy { get; set; } + + /// + /// The Id of the push. + /// + [JsonProperty("pushId")] + public int PushId { get; set; } + + /// + /// The date of the push. + /// + [JsonProperty("date")] + public DateTime Date { get; set; } + + /// + /// The Url of the push. + /// + [JsonProperty("url")] + public Uri Url { get; set; } + + /// + /// Links for the push + /// + [JsonProperty("_links")] + public GitPushLinks Links { get; set; } + } +} \ No newline at end of file diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitRefUpdate.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitRefUpdate.cs new file mode 100644 index 000000000..20222e87f --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitRefUpdate.cs @@ -0,0 +1,31 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Information about the references. + /// + public class GitRefUpdate + { + /// + /// The name of the reference. + /// + [JsonProperty("name")] + public string Name { get; set; } + + /// + /// The old object Id. + /// + [JsonProperty("oldObjectId")] + public string OldObjectId { get; set; } + + /// + /// The new object Id. + /// + [JsonProperty("newObjectId")] + public string NewObjectId { get; set; } + } +} \ No newline at end of file diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitRepository.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitRepository.cs new file mode 100644 index 000000000..487574cc8 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitRepository.cs @@ -0,0 +1,50 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Repository information. + /// + public class GitRepository + { + /// + /// The Repository Id + /// + [JsonProperty("id")] + public string Id { get; set; } + + /// + /// The Repository name. + /// + [JsonProperty("name")] + public string Name { get; set; } + + /// + /// The Repository Url. + /// + [JsonProperty("url")] + public Uri Url { get; set; } + + /// + /// The project. + /// + [JsonProperty("project")] + public GitProject Project { get; set; } + + /// + /// The name of the default branch. + /// + [JsonProperty("defaultBranch")] + public string DefaultBranch { get; set; } + + /// + /// The remote Url. + /// + [JsonProperty("remoteUrl")] + public Uri RemoteUrl { get; set; } + } +} \ No newline at end of file diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitReviewer.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitReviewer.cs new file mode 100644 index 000000000..2bd9b21f7 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitReviewer.cs @@ -0,0 +1,32 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Information on a reviewer of a Pull Request. Extends + /// + public class GitReviewer : GitUser + { + /// + /// Url of reviewer. + /// + [JsonProperty("reviewerUrl")] + public Uri ReviewerUrl { get; set; } + + /// + /// The Reviewer's Vote + /// + [JsonProperty("vote")] + public int Vote { get; set; } + + /// + /// Is Container + /// + [JsonProperty("isContainer")] + public bool IsContainer { get; set; } + } +} \ No newline at end of file diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitUser.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitUser.cs new file mode 100644 index 000000000..96b5bcb7c --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitUser.cs @@ -0,0 +1,44 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Information about the git user. + /// + public class GitUser + { + /// + /// The git user Id. + /// + [JsonProperty("id")] + public string Id { get; set; } + + /// + /// The git user display name. + /// + [JsonProperty("displayName")] + public string DisplayName { get; set; } + + /// + /// The git user unique name. + /// + [JsonProperty("uniqueName")] + public string UniqueName { get; set; } + + /// + /// The git user url. + /// + [JsonProperty("url")] + public Uri Url { get; set; } + + /// + /// The git user's image url. + /// + [JsonProperty("imageUrl")] + public Uri ImageUrl { get; set; } + } +} \ No newline at end of file diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitUserInfo.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitUserInfo.cs new file mode 100644 index 000000000..5f9766a3f --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/GitUserInfo.cs @@ -0,0 +1,32 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Display information about a git user + /// + public class GitUserInfo + { + /// + /// Name of the user + /// + [JsonProperty("name")] + public string Name { get; set; } + + /// + /// Email of the user. + /// + [JsonProperty("email")] + public string Email { get; set; } + + /// + /// A date associated with the user. + /// + [JsonProperty("date")] + public DateTime Date { get; set; } + } +} \ No newline at end of file diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Metadata/AzureDevOpsMetadata.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Metadata/AzureDevOpsMetadata.cs new file mode 100644 index 000000000..c9d6f3e39 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Metadata/AzureDevOpsMetadata.cs @@ -0,0 +1,35 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.WebHooks.Metadata +{ + /// + /// An service containing metadata about the Azure Alert receiver. + /// + public class AzureDevOpsMetadata : + WebHookMetadata, + IWebHookEventFromBodyMetadata, + IWebHookVerifyCodeMetadata + { + /// + /// Instantiates a new instance. + /// + public AzureDevOpsMetadata() + : base(AzureDevOpsConstants.ReceiverName) + { + } + + // IWebHookBodyTypeMetadataService... + + /// + public override WebHookBodyType BodyType => WebHookBodyType.Json; + + // IWebHookEventFromBodyMetadata... + + /// + public bool AllowMissing => false; + + /// + public string BodyPropertyPath => AzureDevOpsConstants.EventBodyPropertyPath; + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps.csproj b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps.csproj new file mode 100644 index 000000000..f7b04bbb8 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps.csproj @@ -0,0 +1,17 @@ + + + ASP.NET Core Azure DevOps WebHooks infrastructure. Contains the AzureDevOpsWebHookAttribute class and AddAzureDevOpsWebHooks method. + aspnetcore;webhook;receiver;azurealert + + + + + + + + + + True + + + diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/PayloadMessage.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/PayloadMessage.cs new file mode 100644 index 000000000..581a5cb5e --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/PayloadMessage.cs @@ -0,0 +1,31 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes payload message. + /// + public class PayloadMessage + { + /// + /// Gets the message in plain text. + /// + [JsonProperty("text")] + public string Text { get; set; } + + /// + /// Gets the message in HTML format. + /// + [JsonProperty("html")] + public string Html { get; set; } + + /// + /// Gets the message in markdown format. + /// + [JsonProperty("markdown")] + public string Markdown { get; set; } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/PayloadResourceContainer.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/PayloadResourceContainer.cs new file mode 100644 index 000000000..43a46e377 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/PayloadResourceContainer.cs @@ -0,0 +1,19 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes container + /// + public class PayloadResourceContainer + { + /// + /// Gets the identifier of container. + /// + [JsonProperty("id")] + public string Id { get; set; } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/PayloadResourceContainers.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/PayloadResourceContainers.cs new file mode 100644 index 000000000..2d09565c0 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/PayloadResourceContainers.cs @@ -0,0 +1,31 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes containers containing the resource + /// + public class PayloadResourceContainers + { + /// + /// Gets the collection. + /// + [JsonProperty("collection")] + public PayloadResourceContainer Collection { get; set; } + + /// + /// Gets the account. + /// + [JsonProperty("account")] + public PayloadResourceContainer Account { get; set; } + + /// + /// Gets the project. + /// + [JsonProperty("project")] + public PayloadResourceContainer Project { get; set; } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Properties/Resources.Designer.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Properties/Resources.Designer.cs new file mode 100644 index 000000000..2655535d5 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Properties/Resources.Designer.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace Microsoft.AspNetCore.WebHooks.Properties { + using System; + + + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.AspNetCore.WebHooks.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die Value cannot be null or empty. ähnelt. + /// + internal static string General_ArgumentCannotBeNullOrEmpty { + get { + return ResourceManager.GetString("General_ArgumentCannotBeNullOrEmpty", resourceCulture); + } + } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Properties/Resources.resx b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Properties/Resources.resx new file mode 100644 index 000000000..fd709f66a --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/Properties/Resources.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Value cannot be null or empty. + + \ No newline at end of file diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/ResourceUser.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/ResourceUser.cs new file mode 100644 index 000000000..6e7315553 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/ResourceUser.cs @@ -0,0 +1,44 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes user entity + /// + public class ResourceUser + { + /// + /// Gets the identifier of the user. + /// + [JsonProperty("id")] + public string Id { get; set; } + + /// + /// Gets the user display name. + /// + [JsonProperty("displayName")] + public string DisplayName { get; set; } + + /// + /// Gets the user unique name. + /// + [JsonProperty("uniqueName")] + public string UniqueName { get; set; } + + /// + /// Gets the user URL. + /// + [JsonProperty("url")] + public Uri Url { get; set; } + + /// + /// Gets the user image URL. + /// + [JsonProperty("imageUrl")] + public Uri ImageUrl { get; set; } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/TeamRoomMessagePostedPayload.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/TeamRoomMessagePostedPayload.cs new file mode 100644 index 000000000..aad4eb0b0 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/TeamRoomMessagePostedPayload.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the entire payload of event 'message.posted'. + /// + public class TeamRoomMessagePostedPayload : BasePayload + { + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/TeamRoomMessagePostedResource.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/TeamRoomMessagePostedResource.cs new file mode 100644 index 000000000..3ac0994f0 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/TeamRoomMessagePostedResource.cs @@ -0,0 +1,50 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the resource that associated with + /// + public class TeamRoomMessagePostedResource : BaseResource + { + /// + /// Gets the identifier. + /// + [JsonProperty("id")] + public int Id { get; set; } + + /// + /// Gets the content of the message. + /// + [JsonProperty("content")] + public string Content { get; set; } + + /// + /// Gets the type of the message. + /// + [JsonProperty("messageType")] + public string MessageType { get; set; } + + /// + /// Gets the posted time of the message. + /// + [JsonProperty("postedTime")] + public DateTime PostedTime { get; set; } + + /// + /// Gets the room identifier where message was posted. + /// + [JsonProperty("postedRoomId")] + public int PostedRoomId { get; set; } + + /// + /// Gets the user who posted the message. + /// + [JsonProperty("postedBy")] + public ResourceUser PostedBy { get; set; } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemCommentedOnPayload.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemCommentedOnPayload.cs new file mode 100644 index 000000000..7a7bea819 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemCommentedOnPayload.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the entire payload of event 'workitem.commented'. + /// + public class WorkItemCommentedOnPayload : BasePayload + { + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemCommentedOnResource.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemCommentedOnResource.cs new file mode 100644 index 000000000..572b3e33e --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemCommentedOnResource.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the resource that associated with + /// + public class WorkItemCommentedOnResource : BaseWorkItemResource + { + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemCreatedPayload.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemCreatedPayload.cs new file mode 100644 index 000000000..2491ca6c2 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemCreatedPayload.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the entire payload of event 'workitem.created'. + /// + public class WorkItemCreatedPayload : BasePayload + { + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemCreatedResource.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemCreatedResource.cs new file mode 100644 index 000000000..acab3d240 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemCreatedResource.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the resource that associated with + /// + public class WorkItemCreatedResource : BaseWorkItemResource + { + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemDeletedPayload.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemDeletedPayload.cs new file mode 100644 index 000000000..81d090d29 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemDeletedPayload.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the entire payload of event 'workitem.deleted'. + /// + public class WorkItemDeletedPayload : BasePayload + { + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemDeletedResource.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemDeletedResource.cs new file mode 100644 index 000000000..01c65c3b9 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemDeletedResource.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the resource that associated with + /// + public class WorkItemDeletedResource : BaseWorkItemResource + { + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemFields.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemFields.cs new file mode 100644 index 000000000..f82bb98a7 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemFields.cs @@ -0,0 +1,104 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes fields of the WorkItem + /// + public class WorkItemFields + { + /// + /// Gets the value of field System.AreaPath. + /// + [JsonProperty("System.AreaPath")] + public string SystemAreaPath { get; set; } + + /// + /// Gets the value of field System.TeamProject. + /// + [JsonProperty("System.TeamProject")] + public string SystemTeamProject { get; set; } + + /// + /// Gets the value of field System.IterationPath. + /// + [JsonProperty("System.IterationPath")] + public string SystemIterationPath { get; set; } + + /// + /// Gets the value of field System.WorkItemType. + /// + [JsonProperty("System.WorkItemType")] + public string SystemWorkItemType { get; set; } + + /// + /// Gets the value of field System.State. + /// + [JsonProperty("System.State")] + public string SystemState { get; set; } + + /// + /// Gets the value of field System.Reason. + /// + [JsonProperty("System.Reason")] + public string SystemReason { get; set; } + + /// + /// Gets the value of field System.AssignedTo. + /// + [JsonProperty("System.AssignedTo")] + public string SystemAssignedTo { get; set; } + + /// + /// Gets the value of field System.CreatedDate. + /// + [JsonProperty("System.CreatedDate")] + public DateTime SystemCreatedDate { get; set; } + + /// + /// Gets the value of field System.CreatedBy. + /// + [JsonProperty("System.CreatedBy")] + public string SystemCreatedBy { get; set; } + + /// + /// Gets the value of field System.ChangedDate. + /// + [JsonProperty("System.ChangedDate")] + public DateTime SystemChangedDate { get; set; } + + /// + /// Gets the value of field System.ChangedBy. + /// + [JsonProperty("System.ChangedBy")] + public string SystemChangedBy { get; set; } + + /// + /// Gets the value of field System.Title. + /// + [JsonProperty("System.Title")] + public string SystemTitle { get; set; } + + /// + /// Gets the value of field Microsoft.VSTS.Common.Severity. + /// + [JsonProperty("Microsoft.VSTS.Common.Severity")] + public string MicrosoftCommonSeverity { get; set; } + + /// + /// Gets the value of field WEF_EB329F44FE5F4A94ACB1DA153FDF38BA_Kanban.Column. + /// + [JsonProperty("WEF_EB329F44FE5F4A94ACB1DA153FDF38BA_Kanban.Column")] + public string KanbanColumn { get; set; } + + /// + /// Gets the value of field System.History. + /// + [JsonProperty("System.History")] + public string SystemHistory { get; set; } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemLink.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemLink.cs new file mode 100644 index 000000000..48e02a5d6 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemLink.cs @@ -0,0 +1,19 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the WorkItem's link. + /// + public class WorkItemLink + { + /// + /// Gets the URL of WorkItem's link. + /// + [JsonProperty("href")] + public string Href { get; set; } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemLinks.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemLinks.cs new file mode 100644 index 000000000..ae227ebae --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemLinks.cs @@ -0,0 +1,61 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes links of the WorkItem. + /// + public class WorkItemLinks + { + /// + /// Gets the link to the WorkItem itself. + /// + [JsonProperty("self")] + public WorkItemLink Self { get; set; } + + /// + /// Gets the link to the parent WorkItem if exists. + /// + [JsonProperty("parent")] + public WorkItemLink Parent { get; set; } + + /// + /// Gets the link to the WorkItem' updates. + /// + [JsonProperty("workItemUpdates")] + public WorkItemLink WorkItemUpdates { get; set; } + + /// + /// Gets the link to the WorkItem's revisions. + /// + [JsonProperty("workItemRevisions")] + public WorkItemLink WorkItemRevisions { get; set; } + + /// + /// Gets the link to the WorkItem's type. + /// + [JsonProperty("workItemType")] + public WorkItemLink WorkItemType { get; set; } + + /// + /// Gets the link to the WorkItem's fields. + /// + [JsonProperty("fields")] + public WorkItemLink Fields { get; set; } + + /// + /// Gets the link to the WorkItem's HTML. + /// + [JsonProperty("html")] + public WorkItemLink Html { get; set; } + + /// + /// Gets the link to the WorkItem's history. + /// + [JsonProperty("workItemHistory")] + public WorkItemLink WorkItemHistory { get; set; } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemRestoredPayload.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemRestoredPayload.cs new file mode 100644 index 000000000..3a012a71d --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemRestoredPayload.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the entire payload of event 'workitem.restored'. + /// + public class WorkItemRestoredPayload : BasePayload + { + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemRestoredResource.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemRestoredResource.cs new file mode 100644 index 000000000..0fc77ff0c --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemRestoredResource.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the resource that associated with + /// + public class WorkItemRestoredResource : BaseWorkItemResource + { + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemUpdatedFieldValue.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemUpdatedFieldValue.cs new file mode 100644 index 000000000..85dc7432d --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemUpdatedFieldValue.cs @@ -0,0 +1,26 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes change of specific field + /// + /// The string-type of the field that is being changed + public class WorkItemUpdatedFieldValue + { + /// + /// Gets the value of the field before the change. + /// + [JsonProperty("oldValue")] + public T OldValue { get; set; } + + /// + /// Gets the value of the field after the change. + /// + [JsonProperty("newValue")] + public T NewValue { get; set; } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemUpdatedFields.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemUpdatedFields.cs new file mode 100644 index 000000000..cc169c775 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemUpdatedFields.cs @@ -0,0 +1,68 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes fields of the WorkItem that was updated + /// + public class WorkItemUpdatedFields + { + /// + /// Gets the change information for the field 'System.Rev'. + /// + [JsonProperty("System.Rev")] + public WorkItemUpdatedFieldValue SystemRev { get; set; } + + /// + /// Gets the change information for the field 'System.AuthorizedDate'. + /// + [JsonProperty("System.AuthorizedDate")] + public WorkItemUpdatedFieldValue SystemAuthorizedDate { get; set; } + + /// + /// Gets the change information for the field 'System.RevisedDate'. + /// + [JsonProperty("System.RevisedDate")] + public WorkItemUpdatedFieldValue SystemRevisedDate { get; set; } + + /// + /// Gets the change information for the field 'System.State'. + /// + [JsonProperty("System.State")] + public WorkItemUpdatedFieldValue SystemState { get; set; } + + /// + /// Gets the change information for the field 'System.Reason'. + /// + [JsonProperty("System.Reason")] + public WorkItemUpdatedFieldValue SystemReason { get; set; } + + /// + /// Gets the change information for the field 'System.AssignedTo'. + /// + [JsonProperty("System.AssignedTo")] + public WorkItemUpdatedFieldValue SystemAssignedTo { get; set; } + + /// + /// Gets the change information for the field 'System.ChangedDate'. + /// + [JsonProperty("System.ChangedDate")] + public WorkItemUpdatedFieldValue SystemChangedDate { get; set; } + + /// + /// Gets the change information for the field 'System.Watermark'. + /// + [JsonProperty("System.Watermark")] + public WorkItemUpdatedFieldValue SystemWatermark { get; set; } + + /// + /// Gets the change information for the field 'Microsoft.VSTS.Common.Severity'. + /// + [JsonProperty("Microsoft.Vsts.Common.Severity")] + public WorkItemUpdatedFieldValue MicrosoftCommonSeverity { get; set; } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemUpdatedPayload.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemUpdatedPayload.cs new file mode 100644 index 000000000..014ac7148 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemUpdatedPayload.cs @@ -0,0 +1,12 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the entire payload of event 'workitem.updated'. + /// + public class WorkItemUpdatedPayload : BasePayload + { + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemUpdatedResource.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemUpdatedResource.cs new file mode 100644 index 000000000..96dbacd1e --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemUpdatedResource.cs @@ -0,0 +1,38 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the resource that associated with + /// + public class WorkItemUpdatedResource : BaseWorkItemResource + { + /// + /// Gets WorkItem identifier. + /// + [JsonProperty("workItemId")] + public int WorkItemId { get; set; } + + /// + /// Gets the author of revision. + /// + [JsonProperty("revisedBy")] + public ResourceUser RevisedBy { get; set; } + + /// + /// Gets the revised date. + /// + [JsonProperty("revisedDate")] + public DateTime RevisedDate { get; set; } + + /// + /// Gets the revision. + /// + [JsonProperty("revision")] + public WorkItemUpdatedRevision Revision { get; set; } + } +} diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemUpdatedRevision.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemUpdatedRevision.cs new file mode 100644 index 000000000..731cd3594 --- /dev/null +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/WorkItemUpdatedRevision.cs @@ -0,0 +1,38 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Newtonsoft.Json; + +namespace Microsoft.AspNetCore.WebHooks +{ + /// + /// Describes the revision + /// + public class WorkItemUpdatedRevision + { + /// + /// Gets the identifier of the revision. + /// + [JsonProperty("id")] + public int Id { get; set; } + + /// + /// Gets the revision number. + /// + [JsonProperty("rev")] + public int Rev { get; set; } + + /// + /// Gets the revision fields. + /// + [JsonProperty("fields")] + public WorkItemFields Fields { get; set; } + + /// + /// Gets the revision URL. + /// + [JsonProperty("url")] + public Uri Url { get; set; } + } +} From 204b2cfe0d991b3b1f64679c26850408ccaca415 Mon Sep 17 00:00:00 2001 From: Necati Meral Date: Fri, 22 Jan 2021 23:41:35 +0100 Subject: [PATCH 2/2] Fixed naming since it isn't strongly named (yet) --- src/WebHooks/WebHooks.sln | 4 ++-- .../AzureDevOpsCoreReceiver.csproj} | 0 .../Controllers/AzureDevOpsController.cs | 0 .../Program.cs | 0 .../Startup.cs | 0 .../appsettings.json | 0 .../AzureDevOpsWebHookAttribute.cs | 2 -- 7 files changed, 2 insertions(+), 4 deletions(-) rename src/WebHooks/samples/{AzureDevOpstronglyTypedCoreReceiver/AzureDevOpsStronglyTypedCoreReceiver.csproj => AzureDevOpsCoreReceiver/AzureDevOpsCoreReceiver.csproj} (100%) rename src/WebHooks/samples/{AzureDevOpstronglyTypedCoreReceiver => AzureDevOpsCoreReceiver}/Controllers/AzureDevOpsController.cs (100%) rename src/WebHooks/samples/{AzureDevOpstronglyTypedCoreReceiver => AzureDevOpsCoreReceiver}/Program.cs (100%) rename src/WebHooks/samples/{AzureDevOpstronglyTypedCoreReceiver => AzureDevOpsCoreReceiver}/Startup.cs (100%) rename src/WebHooks/samples/{AzureDevOpstronglyTypedCoreReceiver => AzureDevOpsCoreReceiver}/appsettings.json (100%) diff --git a/src/WebHooks/WebHooks.sln b/src/WebHooks/WebHooks.sln index 54467e146..25265ec19 100644 --- a/src/WebHooks/WebHooks.sln +++ b/src/WebHooks/WebHooks.sln @@ -101,7 +101,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.WebHoo EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps", "src\Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps\Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps.csproj", "{820D031D-237E-4892-A0BD-EF341421066A}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureDevOpsStronglyTypedCoreReceiver", "samples\AzureDevOpstronglyTypedCoreReceiver\AzureDevOpsStronglyTypedCoreReceiver.csproj", "{DAE01DE1-421B-420C-87DE-74ED9279A034}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureDevOpsCoreReceiver", "samples\AzureDevOpsCoreReceiver\AzureDevOpsCoreReceiver.csproj", "{DAE01DE1-421B-420C-87DE-74ED9279A034}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -306,7 +306,7 @@ Global {DAE01DE1-421B-420C-87DE-74ED9279A034} = {E957C8D9-B4A0-488B-838F-BAB4DE080A76} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - EnterpriseLibraryConfigurationToolBinariesPathV6 = packages\EnterpriseLibrary.TransientFaultHandling.6.0.1304.0\lib\portable-net45+win+wp8;packages\EnterpriseLibrary.TransientFaultHandling.Data.6.0.1304.1\lib\NET45 SolutionGuid = {12CE6238-F847-4984-8622-1ED46072150A} + EnterpriseLibraryConfigurationToolBinariesPathV6 = packages\EnterpriseLibrary.TransientFaultHandling.6.0.1304.0\lib\portable-net45+win+wp8;packages\EnterpriseLibrary.TransientFaultHandling.Data.6.0.1304.1\lib\NET45 EndGlobalSection EndGlobal diff --git a/src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/AzureDevOpsStronglyTypedCoreReceiver.csproj b/src/WebHooks/samples/AzureDevOpsCoreReceiver/AzureDevOpsCoreReceiver.csproj similarity index 100% rename from src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/AzureDevOpsStronglyTypedCoreReceiver.csproj rename to src/WebHooks/samples/AzureDevOpsCoreReceiver/AzureDevOpsCoreReceiver.csproj diff --git a/src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/Controllers/AzureDevOpsController.cs b/src/WebHooks/samples/AzureDevOpsCoreReceiver/Controllers/AzureDevOpsController.cs similarity index 100% rename from src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/Controllers/AzureDevOpsController.cs rename to src/WebHooks/samples/AzureDevOpsCoreReceiver/Controllers/AzureDevOpsController.cs diff --git a/src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/Program.cs b/src/WebHooks/samples/AzureDevOpsCoreReceiver/Program.cs similarity index 100% rename from src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/Program.cs rename to src/WebHooks/samples/AzureDevOpsCoreReceiver/Program.cs diff --git a/src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/Startup.cs b/src/WebHooks/samples/AzureDevOpsCoreReceiver/Startup.cs similarity index 100% rename from src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/Startup.cs rename to src/WebHooks/samples/AzureDevOpsCoreReceiver/Startup.cs diff --git a/src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/appsettings.json b/src/WebHooks/samples/AzureDevOpsCoreReceiver/appsettings.json similarity index 100% rename from src/WebHooks/samples/AzureDevOpstronglyTypedCoreReceiver/appsettings.json rename to src/WebHooks/samples/AzureDevOpsCoreReceiver/appsettings.json diff --git a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/AzureDevOpsWebHookAttribute.cs b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/AzureDevOpsWebHookAttribute.cs index 13eef0629..15ba4a161 100644 --- a/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/AzureDevOpsWebHookAttribute.cs +++ b/src/WebHooks/src/Microsoft.AspNetCore.WebHooks.Receivers.AzureDevOps/AzureDevOpsWebHookAttribute.cs @@ -47,8 +47,6 @@ namespace Microsoft.AspNetCore.WebHooks /// public class AzureDevOpsWebHookAttribute : WebHookAttribute { - private string _eventName; - /// /// Instantiates a new indicating the associated action is an Azure /// DevOps WebHook endpoint.