Skip to content

Commit

Permalink
feat: add installation_target event (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMagee authored Apr 10, 2023
1 parent 04030ee commit 27b767c
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Octokit.Webhooks.Events.InstallationTarget;

[PublicAPI]
public sealed record InstallationTargetAction : WebhookEventAction
{
public static readonly InstallationTargetAction Renamed = new(InstallationTargetActionValue.Renamed);

private InstallationTargetAction(string value)
: base(value)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Octokit.Webhooks.Events.InstallationTarget;

public static class InstallationTargetActionValue
{
public const string Renamed = "renamed";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Octokit.Webhooks.Events.InstallationTarget;

using Octokit.Webhooks.Models.InstallationTargetEvent;

[PublicAPI]
[WebhookActionType(InstallationTargetActionValue.Renamed)]
public sealed record InstallationTargetRenamedEvent : InstallationTargetEvent
{
[JsonPropertyName("action")]
public override string Action => InstallationTargetActionValue.Renamed;

[JsonPropertyName("account")]
public User Account { get; init; } = null!;

[JsonPropertyName("changes")]
public Changes Changes { get; init; } = null!;

[JsonPropertyName("target_type")]
public InstallationTargetType TargetType { get; init; }
}
6 changes: 6 additions & 0 deletions src/Octokit.Webhooks/Events/InstallationTargetEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Octokit.Webhooks.Events;

[PublicAPI]
[WebhookEventType(WebhookEventType.InstallationTarget)]
[JsonConverter(typeof(WebhookConverter<InstallationTargetEvent>))]
public abstract record InstallationTargetEvent : WebhookEvent;
11 changes: 11 additions & 0 deletions src/Octokit.Webhooks/Models/InstallationTargetEvent/Changes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Octokit.Webhooks.Models.InstallationTargetEvent;

[PublicAPI]
public sealed record Changes
{
[JsonPropertyName("login")]
public ChangesLogin? Login { get; init; }

[JsonPropertyName("slug")]
public ChangesSlug? Slug { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Octokit.Webhooks.Models.InstallationTargetEvent;

[PublicAPI]
public record ChangesLogin
{
[JsonPropertyName("from")]
public string From { get; init; } = null!;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Octokit.Webhooks.Models.InstallationTargetEvent;

[PublicAPI]
public sealed record ChangesSlug
{
[JsonPropertyName("from")]
public string From { get; init; } = null!;
}
1 change: 1 addition & 0 deletions src/Octokit.Webhooks/WebHookEventType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static class WebhookEventType
public const string Gollum = "gollum";
public const string Installation = "installation";
public const string InstallationRepositories = "installation_repositories";
public const string InstallationTarget = "installation_target";
public const string Issues = "issues";
public const string IssueComment = "issue_comment";
public const string Label = "label";
Expand Down
23 changes: 23 additions & 0 deletions src/Octokit.Webhooks/WebhookEventProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Octokit.Webhooks.Events.GithubAppAuthorization;
using Octokit.Webhooks.Events.Installation;
using Octokit.Webhooks.Events.InstallationRepositories;
using Octokit.Webhooks.Events.InstallationTarget;
using Octokit.Webhooks.Events.IssueComment;
using Octokit.Webhooks.Events.Issues;
using Octokit.Webhooks.Events.Label;
Expand Down Expand Up @@ -90,6 +91,8 @@ GithubAppAuthorizationEvent githubAppAuthorizationEvent
InstallationEvent installationEvent => this.ProcessInstallationWebhookAsync(headers, installationEvent),
InstallationRepositoriesEvent installationRepositoriesEvent
=> this.ProcessInstallationRepositoriesWebhookAsync(headers, installationRepositoriesEvent),
InstallationTargetEvent installationTargetEvent
=> this.ProcessInstallationTargetWebhookAsync(headers, installationTargetEvent),
IssueCommentEvent issueCommentEvent => this.ProcessIssueCommentWebhookAsync(headers, issueCommentEvent),
IssuesEvent issuesEvent => this.ProcessIssuesWebhookAsync(headers, issuesEvent),
LabelEvent labelEvent => this.ProcessLabelWebhookAsync(headers, labelEvent),
Expand Down Expand Up @@ -161,6 +164,7 @@ public virtual WebhookEvent DeserializeWebhookEvent(WebhookHeaders headers, stri
WebhookEventType.Gollum => JsonSerializer.Deserialize<GollumEvent>(body)!,
WebhookEventType.Installation => JsonSerializer.Deserialize<InstallationEvent>(body)!,
WebhookEventType.InstallationRepositories => JsonSerializer.Deserialize<InstallationRepositoriesEvent>(body)!,
WebhookEventType.InstallationTarget => JsonSerializer.Deserialize<InstallationTargetEvent>(body)!,
WebhookEventType.IssueComment => JsonSerializer.Deserialize<IssueCommentEvent>(body)!,
WebhookEventType.Issues => JsonSerializer.Deserialize<IssuesEvent>(body)!,
WebhookEventType.Label => JsonSerializer.Deserialize<LabelEvent>(body)!,
Expand Down Expand Up @@ -485,6 +489,25 @@ private Task ProcessInstallationRepositoriesWebhookAsync(
_ => Task.CompletedTask,
};

[PublicAPI]
protected virtual Task ProcessInstallationTargetWebhookAsync(
WebhookHeaders headers,
InstallationTargetEvent installationTargetEvent,
InstallationTargetAction action) => Task.CompletedTask;

private Task ProcessInstallationTargetWebhookAsync(
WebhookHeaders headers,
InstallationTargetEvent installationTargetEvent) =>
installationTargetEvent.Action switch
{
InstallationTargetActionValue.Renamed
=> this.ProcessInstallationTargetWebhookAsync(
headers,
installationTargetEvent,
InstallationTargetAction.Renamed),
_ => Task.CompletedTask,
};

[PublicAPI]
protected virtual Task ProcessInstallationRepositoriesWebhookAsync(
WebhookHeaders headers,
Expand Down

0 comments on commit 27b767c

Please sign in to comment.