Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Release deployment approval completed" hook event to the VSTS receiver. #36

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions samples/VstsReceiver/WebHooks/VstsWebHookHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,32 @@ public override Task ExecuteAsync(WebHookHandlerContext context, JObject payload
{
return Task.FromResult(true);
}

/// <summary>
/// We use <see cref="VstsWebHookHandlerBase"/> so just have to override the methods we want to process WebHooks for.
/// This one processes the <see cref="ReleaseCreatedPayload"/> WebHook.
/// </summary>
public override Task ExecuteAsync(WebHookHandlerContext context, ReleaseCreatedPayload payload)
{
return Task.FromResult(true);
}

/// <summary>
/// We use <see cref="VstsWebHookHandlerBase"/> so just have to override the methods we want to process WebHooks for.
/// This one processes the <see cref="ReleaseAbandonedPayload"/> WebHook.
/// </summary>
public override Task ExecuteAsync(WebHookHandlerContext context, ReleaseAbandonedPayload payload)
{
return Task.FromResult(true);
}

/// <summary>
/// We use <see cref="VstsWebHookHandlerBase"/> so just have to override the methods we want to process WebHooks for.
/// This one processes the <see cref="ReleaseDeploymentApprovalCompletedPayload"/> WebHook.
/// </summary>
public override Task ExecuteAsync(WebHookHandlerContext context, ReleaseDeploymentApprovalCompletedPayload payload)
{
return Task.FromResult(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public override Task ExecuteAsync(string receiver, WebHookHandlerContext context
case "git.pullrequest.created": return ExecuteAsync(context, data.ToObject<GitPullRequestCreatedPayload>());
case "git.pullrequest.updated": return ExecuteAsync(context, data.ToObject<GitPullRequestUpdatedPayload>());
case "git.pullrequest.merged": return ExecuteAsync(context, data.ToObject<GitPullRequestMergeCommitCreatedPayload>());
case "ms.vss-release.release-created-event": return ExecuteAsync(context, data.ToObject<ReleaseCreatedPayload> ());
case "ms.vss-release.release-abandoned-event": return ExecuteAsync(context, data.ToObject<ReleaseAbandonedPayload>());
case "ms.vss-release.deployment-approval-completed-event": return ExecuteAsync(context, data.ToObject<ReleaseDeploymentApprovalCompletedPayload>());
default:
var message = string.Format(CultureInfo.CurrentCulture, VstsReceiverResources.Handler_NonMappedEventType, action);
context.RequestContext.Configuration.DependencyResolver.GetLogger().Warn(message);
Expand Down Expand Up @@ -187,5 +190,35 @@ public virtual Task ExecuteAsync(WebHookHandlerContext context, JObject payload)
{
return Task.FromResult(true);
}

/// <summary>
/// Executes the incoming WebHook request for event '<c>ms.vss-release.release-created-event</c>'.
/// </summary>
/// <param name="context">Provides context for the <see cref="IWebHookHandler"/> for further processing the incoming WebHook.</param>
/// <param name="payload">Strong-typed WebHook payload.</param>
public virtual Task ExecuteAsync(WebHookHandlerContext context, ReleaseCreatedPayload payload)
{
return Task.FromResult(true);
}

/// <summary>
/// Executes the incoming WebHook request for event '<c>ms.vss-release.release-abandoned-event</c>'.
/// </summary>
/// <param name="context">Provides context for the <see cref="IWebHookHandler"/> for further processing the incoming WebHook.</param>
/// <param name="payload">Strong-typed WebHook payload.</param>
public virtual Task ExecuteAsync(WebHookHandlerContext context, ReleaseAbandonedPayload payload)
{
return Task.FromResult(true);
}

/// <summary>
/// Executes the incoming WebHook request for event '<c>ms.vss-release.deployment-approval-completed-event</c>'.
/// </summary>
/// <param name="context">Provides context for the <see cref="IWebHookHandler"/> for further processing the incoming WebHook.</param>
/// <param name="payload">Strong-typed WebHook payload.</param>
public virtual Task ExecuteAsync(WebHookHandlerContext context, ReleaseDeploymentApprovalCompletedPayload payload)
{
return Task.FromResult(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Extensions\HttpConfigurationExtensions.cs" />
<Compile Include="Payloads\Approval.cs" />
<Compile Include="Payloads\ReleaseAbandonedPayload.cs" />
<Compile Include="Payloads\ReleaseArtifact.cs" />
<Compile Include="Payloads\ReleaseArtifactDefinitionReference.cs" />
<Compile Include="Payloads\ReleaseArtifactDefinitionReferenceInfo.cs" />
<Compile Include="Payloads\ReleaseDeploymentApprovalCompletedPayload.cs" />
<Compile Include="Payloads\ReleaseDeploymentApprovalCompletedResource.cs" />
<Compile Include="Payloads\ReleaseEnvironmentsRelease.cs" />
<Compile Include="Payloads\ReleaseEnvironmentsEnvironmentOptions.cs" />
<Compile Include="Payloads\ReleaseEnvironmentsPostApprovalsSnapshot.cs" />
<Compile Include="Payloads\GitPullRequestMergeCommitCreatedPayload.cs" />
<Compile Include="Payloads\GitPullRequestUpdatedPayload.cs" />
<Compile Include="Payloads\GitPullLinks.cs" />
Expand Down Expand Up @@ -77,6 +87,19 @@
<Compile Include="Payloads\PayloadMessage.cs" />
<Compile Include="Payloads\PayloadResourceContainer.cs" />
<Compile Include="Payloads\PayloadResourceContainers.cs" />
<Compile Include="Payloads\Project.cs" />
<Compile Include="Payloads\ReleaseEnvironments.cs" />
<Compile Include="Payloads\ReleaseCreatedPayload.cs" />
<Compile Include="Payloads\ReleaseLinks.cs" />
<Compile Include="Payloads\Release.cs" />
<Compile Include="Payloads\ReleaseResource.cs" />
<Compile Include="Payloads\ReleaseEnvironmentsPreApprovalsSnapshot.cs" />
<Compile Include="Payloads\ReleaseEnvironmentsPreApprovalsSnapshotApprovalOptions.cs" />
<Compile Include="Payloads\ReleaseEnvironmentsVariables.cs" />
<Compile Include="Payloads\ReleaseEnvironmentsWorkflowTask.cs" />
<Compile Include="Payloads\ReleaseEnvironmentsWorkflowTaskInputs.cs" />
<Compile Include="Payloads\ReleaseDefinition.cs" />
<Compile Include="Payloads\ReleaseVariables.cs" />
<Compile Include="Payloads\TeamRoomMessagePostedResource.cs" />
<Compile Include="Payloads\WorkItemCommentedOnResource.cs" />
<Compile Include="Payloads\WorkItemCreatedResource.cs" />
Expand Down
116 changes: 116 additions & 0 deletions src/Microsoft.AspNet.WebHooks.Receivers.VSTS/Payloads/Approval.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// 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.AspNet.WebHooks.Payloads
{
/// <summary>
/// Describes approval.
/// </summary>
public class Approval
{
/// <summary>
/// Gets the approval identifier.
/// </summary>
[JsonProperty("id")]
public int Id { get; set; }

/// <summary>
/// Gets the revision.
/// </summary>
[JsonProperty("revision")]
public int Revision { get; set; }

/// <summary>
/// Gets the approver of the release.
/// </summary>
[JsonProperty("approver")]
public ResourceUser Approver { get; set; }

/// <summary>
/// Gets the user which approved the release.
/// </summary>
[JsonProperty("approvedBy")]
public ResourceUser ApprovedBy { get; set; }

/// <summary>
/// Gets the type of approval.
/// </summary>
[JsonProperty("approvalType")]
public string ApprovalType { get; set; }

/// <summary>
/// Gets the created time of the release.
/// </summary>
[JsonProperty("createdOn")]
public DateTime CreatedOn { get; set; }

/// <summary>
/// Gets the modified time of the release.
/// </summary>
[JsonProperty("modifiedOn")]
public DateTime ModifiedOn { get; set; }

/// <summary>
/// Gets the outcome status.
/// </summary>
[JsonProperty("status")]
public string Status { get; set; }

/// <summary>
/// Gets the comments of the approve.
/// </summary>
[JsonProperty("comments")]
public string Comments { get; set; }

/// <summary>
/// The IsAutomated.
/// </summary>
[JsonProperty("isAutomated")]
public bool IsAutomated { get; set; }

/// <summary>
/// The IsNotificationOn.
/// </summary>
[JsonProperty("isNotificationOn")]
public bool IsNotificationOn { get; set; }

/// <summary>
/// Gets the trial number.
/// </summary>
[JsonProperty("trialNumber")]
public int TrialNumber { get; set; }

/// <summary>
/// Gets the Attempt.
/// </summary>
[JsonProperty("attempt")]
public int Attempt { get; set; }

/// <summary>
/// Gets the Rank.
/// </summary>
[JsonProperty("rank")]
public int Rank { get; set; }

/// <summary>
/// Gets the Release.
/// </summary>
[JsonProperty("release")]
public Release Release { get; set; }

/// <summary>
/// Gets the definition of the release.
/// </summary>
[JsonProperty("releaseDefinition")]
public ReleaseDefinition ReleaseDefinition { get; set; }

/// <summary>
/// Gets the environment of the release.
/// </summary>
[JsonProperty("releaseEnvironment")]
public ReleaseEnvironments ReleaseEnvironment { get; set; }
}
}
22 changes: 22 additions & 0 deletions src/Microsoft.AspNet.WebHooks.Receivers.VSTS/Payloads/Project.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Newtonsoft.Json;

namespace Microsoft.AspNet.WebHooks.Payloads
{
/// <summary>
/// Information about a project.
/// </summary>
public class Project
{
/// <summary>
/// The project Id.
/// </summary>
[JsonProperty("id")]
public string Id { get; set; }

/// <summary>
/// The project name.
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
}
}
132 changes: 132 additions & 0 deletions src/Microsoft.AspNet.WebHooks.Receivers.VSTS/Payloads/Release.cs
Original file line number Diff line number Diff line change
@@ -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.AspNet.WebHooks.Payloads
{
/// <summary>
/// Describes release.
/// </summary>
public class Release
{
private readonly Collection<ReleaseEnvironments> _environments = new Collection<ReleaseEnvironments>();
private readonly Collection<ReleaseArtifact> _artifacts = new Collection<ReleaseArtifact>();

/// <summary>
/// Gets the release identifier.
/// </summary>
[JsonProperty("id")]
public int Id { get; set; }

/// <summary>
/// Gets the release name.
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }

/// <summary>
/// Gets the outcome status of the release.
/// </summary>
[JsonProperty("status")]
public string Status { get; set; }

/// <summary>
/// Gets the created time of the release.
/// </summary>
[JsonProperty("createdOn")]
public DateTime CreatedOn { get; set; }

/// <summary>
/// Gets the modified time of the release.
/// </summary>
[JsonProperty("modifiedOn")]
public DateTime ModifiedOn { get; set; }

/// <summary>
/// Gets the user which last changed the release.
/// </summary>
[JsonProperty("modifiedBy")]
public ResourceUser ModifiedBy { get; set; }

/// <summary>
/// Gets the user which created the release.
/// </summary>
[JsonProperty("createdBy")]
public ResourceUser CreatedBy { get; set; }

/// <summary>
/// Gets the environments of the release.
/// </summary>
[JsonProperty("environments")]
public Collection<ReleaseEnvironments> Environments
{
get { return _environments; }
}

/// <summary>
/// Gets variables of the release.
/// </summary>
[JsonProperty("variables")]
public ReleaseVariables Variables { get; set; }

/// <summary>
/// Gets artifacts of the release.
/// </summary>
[JsonProperty("artifacts")]
public Collection<ReleaseArtifact> Artifacts
{
get { return _artifacts; }
}

/// <summary>
/// Gets the definition of the release.
/// </summary>
[JsonProperty("releaseDefinition")]
public ReleaseDefinition ReleaseDefinition { get; set; }

/// <summary>
/// Gets the description of the release.
/// </summary>
[JsonProperty("description")]
public string Description { get; set; }

/// <summary>
/// Gets the reason of the release.
/// </summary>
[JsonProperty("reason")]
public string Reason { get; set; }

/// <summary>
/// Gets the name format of the release.
/// </summary>
[JsonProperty("releaseNameFormat")]
public string ReleaseNameFormat { get; set; }

/// <summary>
/// Is KeepForever.
/// </summary>
[JsonProperty("keepForever")]
public bool KeepForever { get; set; }

/// <summary>
/// Gets the definition snapshot revision of the release.
/// </summary>
[JsonProperty("definitionSnapshotRevision")]
public int DefinitionSnapshotRevision { get; set; }

/// <summary>
/// Gets the comment of the release.
/// </summary>
[JsonProperty("comment")]
public string Comment { get; set; }

/// <summary>
/// Gets links of the release.
/// </summary>
[JsonProperty("_links")]
public ReleaseLinks Links { get; set; }
}
}
Loading