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 created" hook event to the VSTS receiver. #34

Closed
wants to merge 3 commits into from
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
9 changes: 9 additions & 0 deletions samples/VstsReceiver/WebHooks/VstsWebHookHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,14 @@ 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ 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> ());
default:
var message = string.Format(CultureInfo.CurrentCulture, VstsReceiverResources.Handler_NonMappedEventType, action);
context.RequestContext.Configuration.DependencyResolver.GetLogger().Warn(message);
Expand Down Expand Up @@ -187,5 +188,15 @@ 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Extensions\HttpConfigurationExtensions.cs" />
<Compile Include="Payloads\ReleaseArtifact.cs" />
<Compile Include="Payloads\ReleaseArtifactDefinitionReference.cs" />
<Compile Include="Payloads\ReleaseArtifactDefinitionReferenceInfo.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 +83,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\ReleaseCreatedResource.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\ReleaseReleaseDefinition.cs" />
<Compile Include="Payloads\ReleaseVariables.cs" />
<Compile Include="Payloads\TeamRoomMessagePostedResource.cs" />
<Compile Include="Payloads\WorkItemCommentedOnResource.cs" />
<Compile Include="Payloads\WorkItemCreatedResource.cs" />
Expand Down
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 ReleaseReleaseDefinition 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; }
}
}
Original file line number Diff line number Diff line change
@@ -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.AspNet.WebHooks.Payloads
{
/// <summary>
/// Describes the artifact of the release.
/// </summary>
public class ReleaseArtifact
{
/// <summary>
/// Gets the source identifier.
/// </summary>
[JsonProperty("sourceId")]
public string SourceId { get; set; }

/// <summary>
/// Gets the artifact type.
/// </summary>
[JsonProperty("type")]
public string Type { get; set; }

/// <summary>
/// Gets the artifact alias.
/// </summary>
[JsonProperty("alias")]
public string Alias { get; set; }

/// <summary>
/// Gets the artifact definition reference.
/// </summary>
[JsonProperty("definitionReference")]
public ReleaseArtifactDefinitionReference DefinitionReference { get; set; }

/// <summary>
/// Gets the IsPrimary.
/// </summary>
[JsonProperty("isPrimary")]
public bool IsPrimary { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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.AspNet.WebHooks.Payloads
{
/// <summary>
/// Describes the artifact definition reference.
/// </summary>
public class ReleaseArtifactDefinitionReference
{
/// <summary>
/// Gets the Definition.
/// </summary>
[JsonProperty("Definition")]
public ReleaseArtifactDefinitionReferenceInfo Definition { get; set; }

/// <summary>
/// Gets the Project.
/// </summary>
[JsonProperty("Project")]
public ReleaseArtifactDefinitionReferenceInfo Project { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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.AspNet.WebHooks.Payloads
{
/// <summary>
/// Describes the artifact definition reference.
/// </summary>
public class ReleaseArtifactDefinitionReferenceInfo
{
/// <summary>
/// Gets the Id.
/// </summary>
[JsonProperty("id")]
public string Id { get; set; }

/// <summary>
/// Gets the Name.
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -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.AspNet.WebHooks.Payloads
{
/// <summary>
/// Describes the entire payload of event '<c>ms.vss-release.release-created-event</c>'.
/// </summary>
public class ReleaseCreatedPayload : BasePayload<ReleaseCreatedResource>
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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.AspNet.WebHooks.Payloads
{
/// <summary>
/// Describes the resource that associated with <see cref="ReleaseCreatedPayload"/>
/// </summary>
public class ReleaseCreatedResource : BaseResource
{
/// <summary>
/// The Release.
/// </summary>
[JsonProperty("release")]
public Release Release { get; set; }

/// <summary>
/// The project.
/// </summary>
[JsonProperty("project")]
public Project Project { get; set; }
}
}
Loading