Skip to content

Commit ae03c3c

Browse files
authored
Support for SubIssues events and AlertRule schema fix (#754)
1 parent 6263bfb commit ae03c3c

File tree

10 files changed

+113
-1
lines changed

10 files changed

+113
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace Octokit.Webhooks.Events.SubIssues;
2+
3+
[PublicAPI]
4+
public sealed record SubIssuesAction : WebhookEventAction
5+
{
6+
public static readonly SubIssuesAction ParentIssueAdded = new(SubIssuesActionValue.ParentIssueAdded);
7+
8+
public static readonly SubIssuesAction ParentIssueRemoved = new(SubIssuesActionValue.ParentIssueRemoved);
9+
10+
public static readonly SubIssuesAction SubIssueAdded = new(SubIssuesActionValue.SubIssueAdded);
11+
12+
public static readonly SubIssuesAction SubIssueRemoved = new(SubIssuesActionValue.SubIssueRemoved);
13+
14+
private SubIssuesAction(string value)
15+
: base(value)
16+
{
17+
}
18+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Octokit.Webhooks.Events.SubIssues;
2+
3+
public static class SubIssuesActionValue
4+
{
5+
public const string ParentIssueAdded = "parent_issue_added";
6+
7+
public const string ParentIssueRemoved = "parent_issue_removed";
8+
9+
public const string SubIssueAdded = "sub_issue_added";
10+
11+
public const string SubIssueRemoved = "sub_issue_removed";
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Octokit.Webhooks.Events.SubIssues;
2+
3+
[PublicAPI]
4+
[WebhookActionType(SubIssuesActionValue.ParentIssueAdded)]
5+
public sealed record SubIssuesParentIssueAddedEvent : SubIssuesEvent
6+
{
7+
[JsonPropertyName("action")]
8+
public override string Action => SubIssuesAction.ParentIssueAdded;
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Octokit.Webhooks.Events.SubIssues;
2+
3+
[PublicAPI]
4+
[WebhookActionType(SubIssuesActionValue.ParentIssueRemoved)]
5+
public sealed record SubIssuesParentIssueRemovedEvent : SubIssuesEvent
6+
{
7+
[JsonPropertyName("action")]
8+
public override string Action => SubIssuesAction.ParentIssueRemoved;
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Octokit.Webhooks.Events.SubIssues;
2+
3+
[PublicAPI]
4+
[WebhookActionType(SubIssuesActionValue.SubIssueAdded)]
5+
public sealed record SubIssuesSubIssueAddedEvent : SubIssuesEvent
6+
{
7+
[JsonPropertyName("action")]
8+
public override string Action => SubIssuesAction.SubIssueAdded;
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Octokit.Webhooks.Events.SubIssues;
2+
3+
[PublicAPI]
4+
[WebhookActionType(SubIssuesActionValue.SubIssueRemoved)]
5+
public sealed record SubIssuesSubIssueRemovedEvent : SubIssuesEvent
6+
{
7+
[JsonPropertyName("action")]
8+
public override string Action => SubIssuesAction.SubIssueRemoved;
9+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
namespace Octokit.Webhooks.Events;
2+
3+
[PublicAPI]
4+
[WebhookEventType(WebhookEventType.SubIssues)]
5+
[JsonConverter(typeof(WebhookConverter<SubIssuesEvent>))]
6+
public abstract record SubIssuesEvent : WebhookEvent
7+
{
8+
[JsonPropertyName("parent_issue_id")]
9+
public long ParentIssueId { get; init; }
10+
11+
[JsonPropertyName("parent_issue")]
12+
public Issue ParentIssue { get; init; } = null!;
13+
14+
[JsonPropertyName("parent_issue_repo")]
15+
public Models.Repository? ParentIssueRepo { get; init; } = null!;
16+
17+
[JsonPropertyName("sub_issue_id")]
18+
public long SubIssueId { get; init; }
19+
20+
[JsonPropertyName("sub_issue")]
21+
public Issue SubIssue { get; init; } = null!;
22+
23+
[JsonPropertyName("sub_issue_repo")]
24+
public Models.Repository? SubIssueRepo { get; init; }
25+
}

src/Octokit.Webhooks/Models/CodeScanningAlertEvent/AlertRule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public sealed record AlertRule
1717
public string FullDescription { get; init; } = null!;
1818

1919
[JsonPropertyName("tags")]
20-
public string Tags { get; init; } = null!;
20+
public IEnumerable<string> Tags { get; init; } = null!;
2121

2222
[JsonPropertyName("help")]
2323
public string Help { get; init; } = null!;

src/Octokit.Webhooks/WebHookEventType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public static class WebhookEventType
6666
public const string Sponsorship = "sponsorship";
6767
public const string Star = "star";
6868
public const string Status = "status";
69+
public const string SubIssues = "sub_issues";
6970
public const string Team = "team";
7071
public const string TeamAdd = "team_add";
7172
public const string Watch = "watch";

src/Octokit.Webhooks/WebhookEventProcessor.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ namespace Octokit.Webhooks;
5757
using Octokit.Webhooks.Events.SecurityAdvisory;
5858
using Octokit.Webhooks.Events.Sponsorship;
5959
using Octokit.Webhooks.Events.Star;
60+
using Octokit.Webhooks.Events.SubIssues;
6061
using Octokit.Webhooks.Events.Team;
6162
using Octokit.Webhooks.Events.Watch;
6263
using Octokit.Webhooks.Events.WorkflowJob;
@@ -154,6 +155,7 @@ SecretScanningAlertLocationEvent secretScanningAlertLocationEvent
154155
SponsorshipEvent sponsorshipEvent => this.ProcessSponsorshipWebhookAsync(headers, sponsorshipEvent, cancellationToken),
155156
StarEvent starEvent => this.ProcessStarWebhookAsync(headers, starEvent, cancellationToken),
156157
StatusEvent statusEvent => this.ProcessStatusWebhookAsync(headers, statusEvent, cancellationToken),
158+
SubIssuesEvent subIssuesEvent => this.ProcessSubIssuesWebhookAsync(headers, subIssuesEvent, cancellationToken),
157159
TeamEvent teamEvent => this.ProcessTeamWebhookAsync(headers, teamEvent, cancellationToken),
158160
TeamAddEvent teamAddEvent => this.ProcessTeamAddWebhookAsync(headers, teamAddEvent, cancellationToken),
159161
WatchEvent watchEvent => this.ProcessWatchWebhookAsync(headers, watchEvent, cancellationToken),
@@ -229,6 +231,7 @@ public virtual WebhookEvent DeserializeWebhookEvent(WebhookHeaders headers, stri
229231
WebhookEventType.Sponsorship => JsonSerializer.Deserialize<SponsorshipEvent>(body)!,
230232
WebhookEventType.Star => JsonSerializer.Deserialize<StarEvent>(body)!,
231233
WebhookEventType.Status => JsonSerializer.Deserialize<StatusEvent>(body)!,
234+
WebhookEventType.SubIssues => JsonSerializer.Deserialize<SubIssuesEvent>(body)!,
232235
WebhookEventType.Team => JsonSerializer.Deserialize<TeamEvent>(body)!,
233236
WebhookEventType.TeamAdd => JsonSerializer.Deserialize<TeamAddEvent>(body)!,
234237
WebhookEventType.Watch => JsonSerializer.Deserialize<WatchEvent>(body)!,
@@ -1353,6 +1356,23 @@ protected virtual ValueTask ProcessStarWebhookAsync(WebhookHeaders headers, Star
13531356
[PublicAPI]
13541357
protected virtual ValueTask ProcessStatusWebhookAsync(WebhookHeaders headers, StatusEvent statusEvent, CancellationToken cancellationToken = default) => ValueTask.CompletedTask;
13551358

1359+
private ValueTask ProcessSubIssuesWebhookAsync(WebhookHeaders headers, SubIssuesEvent subIssuesEvent, CancellationToken cancellationToken = default) =>
1360+
subIssuesEvent.Action switch
1361+
{
1362+
SubIssuesActionValue.ParentIssueAdded => this.ProcessSubIssuesWebhookAsync(headers, subIssuesEvent, SubIssuesAction.ParentIssueAdded, cancellationToken),
1363+
SubIssuesActionValue.ParentIssueRemoved => this.ProcessSubIssuesWebhookAsync(headers, subIssuesEvent, SubIssuesAction.ParentIssueRemoved, cancellationToken),
1364+
SubIssuesActionValue.SubIssueAdded => this.ProcessSubIssuesWebhookAsync(headers, subIssuesEvent, SubIssuesAction.SubIssueAdded, cancellationToken),
1365+
SubIssuesActionValue.SubIssueRemoved => this.ProcessSubIssuesWebhookAsync(headers, subIssuesEvent, SubIssuesAction.SubIssueRemoved, cancellationToken),
1366+
_ => ValueTask.CompletedTask,
1367+
};
1368+
1369+
[PublicAPI]
1370+
protected virtual ValueTask ProcessSubIssuesWebhookAsync(
1371+
WebhookHeaders headers,
1372+
SubIssuesEvent subIssuesEvent,
1373+
SubIssuesAction action,
1374+
CancellationToken cancellationToken = default) => ValueTask.CompletedTask;
1375+
13561376
private ValueTask ProcessTeamWebhookAsync(WebhookHeaders headers, TeamEvent teamEvent, CancellationToken cancellationToken = default) =>
13571377
teamEvent.Action switch
13581378
{

0 commit comments

Comments
 (0)