Skip to content

Commit b44b70f

Browse files
authored
Add webhook processor for projects_v2_item and more payload schema (#658)
* Add webhook processor for projects_v2_item * Add new properties to projects_v2_item changes
1 parent bab0a9c commit b44b70f

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

src/Octokit.Webhooks/Models/ProjectsV2ItemEvent/ChangesFieldValue.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,16 @@ public sealed record ChangesFieldValue
99

1010
[JsonPropertyName("field_node_id")]
1111
public string FieldNodeId { get; init; } = null!;
12+
13+
[JsonPropertyName("field_name")]
14+
public string FieldName { get; init; } = null!;
15+
16+
[JsonPropertyName("project_number")]
17+
public long ProjectNumber { get; init; }
18+
19+
[JsonPropertyName("from")]
20+
public ChangesFieldValueChange From { get; init; } = null!;
21+
22+
[JsonPropertyName("to")]
23+
public ChangesFieldValueChange To { get; init; } = null!;
1224
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace Octokit.Webhooks.Models.ProjectsV2ItemEvent;
2+
3+
[PublicAPI]
4+
public sealed record ChangesFieldValueChange
5+
{
6+
[JsonPropertyName("id")]
7+
public string Id { get; init; } = null!;
8+
9+
[JsonPropertyName("name")]
10+
public string Name { get; init; } = null!;
11+
12+
[JsonPropertyName("color")]
13+
public string Color { get; init; } = null!;
14+
15+
[JsonPropertyName("description")]
16+
public string Description { get; init; } = null!;
17+
}

src/Octokit.Webhooks/WebhookEventProcessor.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ namespace Octokit.Webhooks;
3939
using Octokit.Webhooks.Events.Project;
4040
using Octokit.Webhooks.Events.ProjectCard;
4141
using Octokit.Webhooks.Events.ProjectColumn;
42+
using Octokit.Webhooks.Events.ProjectsV2Item;
4243
using Octokit.Webhooks.Events.PullRequest;
4344
using Octokit.Webhooks.Events.PullRequestReview;
4445
using Octokit.Webhooks.Events.PullRequestReviewComment;
@@ -125,6 +126,7 @@ MarketplacePurchaseEvent marketplacePurchaseEvent
125126
ProjectEvent projectEvent => this.ProcessProjectWebhookAsync(headers, projectEvent),
126127
ProjectCardEvent projectCardEvent => this.ProcessProjectCardWebhookAsync(headers, projectCardEvent),
127128
ProjectColumnEvent projectColumnEvent => this.ProcessProjectColumnWebhookAsync(headers, projectColumnEvent),
129+
ProjectsV2ItemEvent projectsV2ItemEvent => this.ProcessProjectsV2ItemWebhookAsync(headers, projectsV2ItemEvent),
128130
PublicEvent publicEvent => this.ProcessPublicWebhookAsync(headers, publicEvent),
129131
PullRequestEvent pullRequestEvent => this.ProcessPullRequestWebhookAsync(headers, pullRequestEvent),
130132
PullRequestReviewEvent pullRequestReviewEvent => this.ProcessPullRequestReviewWebhookAsync(headers, pullRequestReviewEvent),
@@ -888,6 +890,23 @@ protected virtual Task ProcessProjectColumnWebhookAsync(
888890
ProjectColumnEvent projectColumnEvent,
889891
ProjectColumnAction action) => Task.CompletedTask;
890892

893+
[PublicAPI]
894+
protected virtual Task ProcessProjectsV2ItemWebhookAsync(WebhookHeaders headers, ProjectsV2ItemEvent projectsV2ItemEvent, ProjectsV2ItemAction action)
895+
=> Task.CompletedTask;
896+
897+
private Task ProcessProjectsV2ItemWebhookAsync(WebhookHeaders headers, ProjectsV2ItemEvent projectsV2ItemEvent) =>
898+
projectsV2ItemEvent.Action switch
899+
{
900+
ProjectsV2ItemActionValue.Created => this.ProcessProjectsV2ItemWebhookAsync(headers, projectsV2ItemEvent, ProjectsV2ItemAction.Created),
901+
ProjectsV2ItemActionValue.Deleted => this.ProcessProjectsV2ItemWebhookAsync(headers, projectsV2ItemEvent, ProjectsV2ItemAction.Deleted),
902+
ProjectsV2ItemActionValue.Edited => this.ProcessProjectsV2ItemWebhookAsync(headers, projectsV2ItemEvent, ProjectsV2ItemAction.Edited),
903+
ProjectsV2ItemActionValue.Archived => this.ProcessProjectsV2ItemWebhookAsync(headers, projectsV2ItemEvent, ProjectsV2ItemAction.Archived),
904+
ProjectsV2ItemActionValue.Converted => this.ProcessProjectsV2ItemWebhookAsync(headers, projectsV2ItemEvent, ProjectsV2ItemAction.Converted),
905+
ProjectsV2ItemActionValue.Restored => this.ProcessProjectsV2ItemWebhookAsync(headers, projectsV2ItemEvent, ProjectsV2ItemAction.Restored),
906+
ProjectsV2ItemActionValue.Reordered => this.ProcessProjectsV2ItemWebhookAsync(headers, projectsV2ItemEvent, ProjectsV2ItemAction.Reordered),
907+
_ => Task.CompletedTask,
908+
};
909+
891910
[PublicAPI]
892911
protected virtual Task ProcessPublicWebhookAsync(WebhookHeaders headers, PublicEvent publicEvent) => Task.CompletedTask;
893912

test/Octokit.Webhooks.Test/Resources/projects_v2_item/edited.payload.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,21 @@
3333
"changes": {
3434
"field_value": {
3535
"field_node_id": "PVTF_lADOAWcTxs07G84AAali",
36-
"field_type": "single_select"
36+
"field_type": "single_select",
37+
"field_name": "Status",
38+
"project_number": 18,
39+
"from": {
40+
"id": "f75ad846",
41+
"name": "Todo",
42+
"color": "GREEN",
43+
"description": "This item hasn't been started"
44+
},
45+
"to": {
46+
"id": "47fc9ee4",
47+
"name": "In Progress",
48+
"color": "YELLOW",
49+
"description": "This is actively being worked on"
50+
}
3751
}
3852
},
3953
"organization": {

0 commit comments

Comments
 (0)