Skip to content

Commit

Permalink
feat!: new events/updates (#277)
Browse files Browse the repository at this point in the history
* fix: `pull_request.head.repo` can be `null`

* feat: new `secret_scanning_alert.revoked` event

* fix!: `pull_request.queued` was renamed to `pull_request.enqueued`

* feat: new `secret_scanning_alert_location` event

* feat: new `require_last_push_approval` rule for `branch_protection_rule`

* fix: `SecretScanningAlertLocationCreatedEvent` inherits from `SecretScanningAlertLocationEvent`

* test: update sample payloads
  • Loading branch information
JamieMagee authored Jun 1, 2023
1 parent 9d170dc commit ba0b8f2
Show file tree
Hide file tree
Showing 24 changed files with 335 additions and 572 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public sealed record PullRequestAction : WebhookEventAction

public static readonly PullRequestAction Opened = new(PullRequestActionValue.Opened);

public static readonly PullRequestAction Queued = new(PullRequestActionValue.Queued);
public static readonly PullRequestAction Enqueued = new(PullRequestActionValue.Enqueued);

public static readonly PullRequestAction ReadyForReview = new(PullRequestActionValue.ReadyForReview);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static class PullRequestActionValue

public const string Opened = "opened";

public const string Queued = "queued";
public const string Enqueued = "enqueued";

public const string ReadyForReview = "ready_for_review";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Octokit.Webhooks.Events.PullRequest;

[PublicAPI]
[WebhookActionType(PullRequestActionValue.Enqueued)]
public sealed record PullRequestEnqueuedEvent : PullRequestEvent
{
[JsonPropertyName("action")]
public override string Action => PullRequestAction.Enqueued;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public sealed record SecretScanningAlertAction : WebhookEventAction

public static readonly SecretScanningAlertAction Resolved = new(SecretScanningAlertActionValue.Resolved);

public static readonly SecretScanningAlertAction Revoked = new(SecretScanningAlertActionValue.Revoked);

private SecretScanningAlertAction(string value)
: base(value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ public static class SecretScanningAlertActionValue
public const string Reopened = "reopened";

public const string Resolved = "resolved";

public const string Revoked = "revoked";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Octokit.Webhooks.Events.SecretScanningAlert;

[PublicAPI]
[WebhookActionType(SecretScanningAlertActionValue.Revoked)]
public sealed record SecretScanningAlertRevokedEvent : SecretScanningAlertEvent
{
[JsonPropertyName("action")]
public override string Action => SecretScanningAlertAction.Revoked;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Octokit.Webhooks.Events.SecretScanningAlertLocation;

[PublicAPI]
public sealed record SecretScanningAlertLocationAction : WebhookEventAction
{
public static readonly SecretScanningAlertLocationAction Created = new(SecretScanningAlertLocationActionValue.Created);

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

public static class SecretScanningAlertLocationActionValue
{
public const string Created = "created";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Octokit.Webhooks.Events.SecretScanningAlertLocation;

[PublicAPI]
[WebhookActionType(SecretScanningAlertLocationActionValue.Created)]
public sealed record SecretScanningAlertLocationCreatedEvent : SecretScanningAlertLocationEvent
{
[JsonPropertyName("action")]
public override string Action => SecretScanningAlertLocationAction.Created;
}
12 changes: 12 additions & 0 deletions src/Octokit.Webhooks/Events/SecretScanningAlertLocationEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Octokit.Webhooks.Events;

using Octokit.Webhooks.Models.SecretScanningAlertEvent;

[PublicAPI]
[WebhookEventType(WebhookEventType.SecretScanningAlertLocation)]
[JsonConverter(typeof(WebhookConverter<SecretScanningAlertLocationEvent>))]
public abstract record SecretScanningAlertLocationEvent : WebhookEvent
{
[JsonPropertyName("alert")]
public Alert Alert { get; init; } = null!;
}
3 changes: 3 additions & 0 deletions src/Octokit.Webhooks/Models/BranchProtectionRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public sealed record BranchProtectionRule
[JsonPropertyName("require_code_owner_review")]
public bool RequireCodeOwnerReview { get; init; }

[JsonPropertyName("require_last_push_approval")]
public bool RequireLastPushApproval { get; init; }

[JsonPropertyName("required_approving_review_count")]
public long RequiredApprovingReviewCount { get; init; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ public sealed record PullRequestHead
public User User { get; init; } = null!;

[JsonPropertyName("repo")]
public Repository Repo { get; init; } = null!;
public Repository? Repo { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Octokit.Webhooks.Models.SecretScanningAlertLocationEvent;

[PublicAPI]
public sealed record SecretScanningLocation
{
[JsonPropertyName("type")]
public SecretScanningLocationType Type { get; init; }

// TODO: type union with SecretScanningLocationCommit, SecretScanningLocationIssueBody, etc.
[JsonPropertyName("details")]
public dynamic Details { get; init; } = null!;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace Octokit.Webhooks.Models.SecretScanningAlertLocationEvent;

[PublicAPI]
public sealed record SecretScanningLocationCommit
{
[JsonPropertyName("path")]
public string Path { get; init; } = null!;

[JsonPropertyName("start_line")]
public long StartLine { get; init; }

[JsonPropertyName("end_line")]
public long EndLine { get; init; }

[JsonPropertyName("start_column")]
public long StartColumn { get; init; }

[JsonPropertyName("end_column")]
public long EndColumn { get; init; }

[JsonPropertyName("blob_sha")]
public string BlobSha { get; init; } = null!;

[JsonPropertyName("blob_url")]
public string BlobUrl { get; init; } = null!;

[JsonPropertyName("commit_sha")]
public string CommitSha { get; init; } = null!;

[JsonPropertyName("commit_url")]
public string CommitUrl { get; init; } = null!;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Octokit.Webhooks.Models.SecretScanningAlertLocationEvent;

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

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

[PublicAPI]
public sealed record SecretScanningLocationIssueTitle
{
[JsonPropertyName("issue_title_url")]
public string IssueTitleUrl { get; init; } = null!;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Octokit.Webhooks.Models.SecretScanningAlertLocationEvent;

[PublicAPI]
[JsonConverter(typeof(JsonStringEnumMemberConverterWithFallback))]
public enum SecretScanningLocationType
{
Unknown = -1,
[EnumMember(Value = "commit")]
Commit,
[EnumMember(Value = "issue_title")]
IssueTitle,
[EnumMember(Value = "issue_body")]
IssueBody,
[EnumMember(Value = "issue_comment")]
IssueComment,
}
23 changes: 21 additions & 2 deletions src/Octokit.Webhooks/WebhookEventProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
using Octokit.Webhooks.Events.RepositoryDispatch;
using Octokit.Webhooks.Events.RepositoryVulnerabilityAlert;
using Octokit.Webhooks.Events.SecretScanningAlert;
using Octokit.Webhooks.Events.SecretScanningAlertLocation;
using Octokit.Webhooks.Events.SecurityAdvisory;
using Octokit.Webhooks.Events.Sponsorship;
using Octokit.Webhooks.Events.Star;
Expand Down Expand Up @@ -132,6 +133,8 @@ RepositoryVulnerabilityAlertEvent repositoryVulnerabilityAlertEvent
=> this.ProcessRepositoryVulnerabilityAlertWebhookAsync(headers, repositoryVulnerabilityAlertEvent),
SecretScanningAlertEvent secretScanningAlertEvent
=> this.ProcessSecretScanningAlertWebhookAsync(headers, secretScanningAlertEvent),
SecretScanningAlertLocationEvent secretScanningAlertLocationEvent
=> this.ProcessSecretScanningAlertLocationWebhookAsync(headers, secretScanningAlertLocationEvent),
SecurityAdvisoryEvent securityAdvisoryEvent => this.ProcessSecurityAdvisoryWebhookAsync(headers, securityAdvisoryEvent),
SponsorshipEvent sponsorshipEvent => this.ProcessSponsorshipWebhookAsync(headers, sponsorshipEvent),
StarEvent starEvent => this.ProcessStarWebhookAsync(headers, starEvent),
Expand Down Expand Up @@ -815,8 +818,8 @@ private Task ProcessPullRequestWebhookAsync(WebhookHeaders headers, PullRequestE
PullRequestActionValue.Locked => this.ProcessPullRequestWebhookAsync(headers, pullRequestEvent, PullRequestAction.Locked),
PullRequestActionValue.Milestoned => this.ProcessPullRequestWebhookAsync(headers, pullRequestEvent, PullRequestAction.Milestoned),
PullRequestActionValue.Opened => this.ProcessPullRequestWebhookAsync(headers, pullRequestEvent, PullRequestAction.Opened),
PullRequestActionValue.Queued
=> this.ProcessPullRequestWebhookAsync(headers, pullRequestEvent, PullRequestAction.Queued),
PullRequestActionValue.Enqueued
=> this.ProcessPullRequestWebhookAsync(headers, pullRequestEvent, PullRequestAction.Enqueued),
PullRequestActionValue.ReadyForReview
=> this.ProcessPullRequestWebhookAsync(headers, pullRequestEvent, PullRequestAction.ReadyForReview),
PullRequestActionValue.Reopened
Expand Down Expand Up @@ -1034,6 +1037,8 @@ private Task ProcessSecretScanningAlertWebhookAsync(WebhookHeaders headers, Secr
=> this.ProcessSecretScanningAlertWebhookAsync(headers, secretScanningAlertEvent, SecretScanningAlertAction.Reopened),
SecretScanningAlertActionValue.Resolved
=> this.ProcessSecretScanningAlertWebhookAsync(headers, secretScanningAlertEvent, SecretScanningAlertAction.Resolved),
SecretScanningAlertActionValue.Revoked
=> this.ProcessSecretScanningAlertWebhookAsync(headers, secretScanningAlertEvent, SecretScanningAlertAction.Revoked),
_ => Task.CompletedTask,
};

Expand All @@ -1043,6 +1048,20 @@ protected virtual Task ProcessSecretScanningAlertWebhookAsync(
SecretScanningAlertEvent secretScanningAlertEvent,
SecretScanningAlertAction action) => Task.CompletedTask;

private Task ProcessSecretScanningAlertLocationWebhookAsync(WebhookHeaders headers, SecretScanningAlertLocationEvent secretScanningAlertLocationEvent) =>
secretScanningAlertLocationEvent.Action switch
{
SecretScanningAlertLocationActionValue.Created
=> this.ProcessSecretScanningAlertLocationWebhookAsync(headers, secretScanningAlertLocationEvent, SecretScanningAlertLocationAction.Created),
_ => Task.CompletedTask,
};

[PublicAPI]
protected virtual Task ProcessSecretScanningAlertLocationWebhookAsync(
WebhookHeaders headers,
SecretScanningAlertLocationEvent secretScanningAlertLocationEvent,
SecretScanningAlertLocationAction action) => Task.CompletedTask;

private Task ProcessSecurityAdvisoryWebhookAsync(WebhookHeaders headers, SecurityAdvisoryEvent securityAdvisoryEvent) =>
securityAdvisoryEvent.Action switch
{
Expand Down
Loading

0 comments on commit ba0b8f2

Please sign in to comment.