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 support for the pull request review thread event #2326

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions github/event.go
Expand Up @@ -102,6 +102,8 @@ func (e *Event) ParsePayload() (payload interface{}, err error) {
payload = &PullRequestReviewEvent{}
case "PullRequestReviewCommentEvent":
payload = &PullRequestReviewCommentEvent{}
case "PullRequestReviewThreadEvent":
payload = &PullRequestReviewThreadEvent{}
case "PullRequestTargetEvent":
payload = &PullRequestTargetEvent{}
case "PushEvent":
Expand Down
18 changes: 18 additions & 0 deletions github/event_types.go
Expand Up @@ -830,6 +830,24 @@ type PullRequestReviewCommentEvent struct {
Installation *Installation `json:"installation,omitempty"`
}

// PullRequestReviewThreadEvent is triggered when a comment made as part of a
// review of a pull request is marked resolved or unresolved.
// The Webhook event name is "pull_request_review_thread".
//
// GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#pull_request_review_thread
type PullRequestReviewThreadEvent struct {
// Action is the action that was performed on the comment.
// Possible values are: "resolved", "unresolved".
Action *string `json:"action,omitempty"`
Thread *PullRequestThread `json:"thread,omitempty"`
PullRequest *PullRequest `json:"pull_request,omitempty"`

// The following fields are only populated by Webhook events.
Repo *Repository `json:"repository,omitempty"`
Sender *User `json:"sender,omitempty"`
Installation *Installation `json:"installation,omitempty"`
}

// PullRequestTargetEvent is triggered when a pull request is assigned, unassigned, labeled,
// unlabeled, opened, edited, closed, reopened, synchronize, ready_for_review,
// locked, unlocked, a pull request review is requested, or a review request is removed.
Expand Down
249 changes: 249 additions & 0 deletions github/event_types_test.go
Expand Up @@ -13061,6 +13061,255 @@ func TestPullRequestReviewCommentEvent_Marshal(t *testing.T) {
testJSONMarshal(t, u, want)
}

func TestPullRequestReviewThreadEvent_Marshal(t *testing.T) {
testJSONMarshal(t, &PullRequestReviewThreadEvent{}, "{}")

u := &PullRequestReviewThreadEvent{
Action: String("a"),
PullRequest: &PullRequest{ID: Int64(1)},
Thread: &PullRequestThread{
Comments: []*PullRequestComment{{ID: Int64(1)}, {ID: Int64(2)}},
},
Repo: &Repository{
ID: Int64(1),
URL: String("s"),
Name: String("n"),
},
Sender: &User{
Login: String("l"),
ID: Int64(1),
NodeID: String("n"),
URL: String("u"),
ReposURL: String("r"),
EventsURL: String("e"),
AvatarURL: String("a"),
},
Installation: &Installation{
ID: Int64(1),
NodeID: String("nid"),
AppID: Int64(1),
AppSlug: String("as"),
TargetID: Int64(1),
Account: &User{
Login: String("l"),
ID: Int64(1),
URL: String("u"),
AvatarURL: String("a"),
GravatarID: String("g"),
Name: String("n"),
Company: String("c"),
Blog: String("b"),
Location: String("l"),
Email: String("e"),
Hireable: Bool(true),
Bio: String("b"),
TwitterUsername: String("t"),
PublicRepos: Int(1),
Followers: Int(1),
Following: Int(1),
CreatedAt: &Timestamp{referenceTime},
SuspendedAt: &Timestamp{referenceTime},
},
AccessTokensURL: String("atu"),
RepositoriesURL: String("ru"),
HTMLURL: String("hu"),
TargetType: String("tt"),
SingleFileName: String("sfn"),
RepositorySelection: String("rs"),
Events: []string{"e"},
SingleFilePaths: []string{"s"},
Permissions: &InstallationPermissions{
Actions: String("a"),
Administration: String("ad"),
Checks: String("c"),
Contents: String("co"),
ContentReferences: String("cr"),
Deployments: String("d"),
Environments: String("e"),
Issues: String("i"),
Metadata: String("md"),
Members: String("m"),
OrganizationAdministration: String("oa"),
OrganizationHooks: String("oh"),
OrganizationPlan: String("op"),
OrganizationPreReceiveHooks: String("opr"),
OrganizationProjects: String("op"),
OrganizationSecrets: String("os"),
OrganizationSelfHostedRunners: String("osh"),
OrganizationUserBlocking: String("oub"),
Packages: String("pkg"),
Pages: String("pg"),
PullRequests: String("pr"),
RepositoryHooks: String("rh"),
RepositoryProjects: String("rp"),
RepositoryPreReceiveHooks: String("rprh"),
Secrets: String("s"),
SecretScanningAlerts: String("ssa"),
SecurityEvents: String("se"),
SingleFile: String("sf"),
Statuses: String("s"),
TeamDiscussions: String("td"),
VulnerabilityAlerts: String("va"),
Workflows: String("w"),
},
CreatedAt: &Timestamp{referenceTime},
UpdatedAt: &Timestamp{referenceTime},
HasMultipleSingleFiles: Bool(false),
SuspendedBy: &User{
Login: String("l"),
ID: Int64(1),
URL: String("u"),
AvatarURL: String("a"),
GravatarID: String("g"),
Name: String("n"),
Company: String("c"),
Blog: String("b"),
Location: String("l"),
Email: String("e"),
Hireable: Bool(true),
Bio: String("b"),
TwitterUsername: String("t"),
PublicRepos: Int(1),
Followers: Int(1),
Following: Int(1),
CreatedAt: &Timestamp{referenceTime},
SuspendedAt: &Timestamp{referenceTime},
},
SuspendedAt: &Timestamp{referenceTime},
},
}

want := `{
"action": "a",
"pull_request": {
"id": 1
},
"thread": {
"comments": [
{
"id": 1
},
{
"id": 2
}
]
},
"repository": {
"id": 1,
"name": "n",
"url": "s"
},
"sender": {
"login": "l",
"id": 1,
"node_id": "n",
"avatar_url": "a",
"url": "u",
"events_url": "e",
"repos_url": "r"
},
"installation": {
"id": 1,
"node_id": "nid",
"app_id": 1,
"app_slug": "as",
"target_id": 1,
"account": {
"login": "l",
"id": 1,
"avatar_url": "a",
"gravatar_id": "g",
"name": "n",
"company": "c",
"blog": "b",
"location": "l",
"email": "e",
"hireable": true,
"bio": "b",
"twitter_username": "t",
"public_repos": 1,
"followers": 1,
"following": 1,
"created_at": ` + referenceTimeStr + `,
"suspended_at": ` + referenceTimeStr + `,
"url": "u"
},
"access_tokens_url": "atu",
"repositories_url": "ru",
"html_url": "hu",
"target_type": "tt",
"single_file_name": "sfn",
"repository_selection": "rs",
"events": [
"e"
],
"single_file_paths": [
"s"
],
"permissions": {
"actions": "a",
"administration": "ad",
"checks": "c",
"contents": "co",
"content_references": "cr",
"deployments": "d",
"environments": "e",
"issues": "i",
"metadata": "md",
"members": "m",
"organization_administration": "oa",
"organization_hooks": "oh",
"organization_plan": "op",
"organization_pre_receive_hooks": "opr",
"organization_projects": "op",
"organization_secrets": "os",
"organization_self_hosted_runners": "osh",
"organization_user_blocking": "oub",
"packages": "pkg",
"pages": "pg",
"pull_requests": "pr",
"repository_hooks": "rh",
"repository_projects": "rp",
"repository_pre_receive_hooks": "rprh",
"secrets": "s",
"secret_scanning_alerts": "ssa",
"security_events": "se",
"single_file": "sf",
"statuses": "s",
"team_discussions": "td",
"vulnerability_alerts": "va",
"workflows": "w"
},
"created_at": ` + referenceTimeStr + `,
"updated_at": ` + referenceTimeStr + `,
"has_multiple_single_files": false,
"suspended_by": {
"login": "l",
"id": 1,
"avatar_url": "a",
"gravatar_id": "g",
"name": "n",
"company": "c",
"blog": "b",
"location": "l",
"email": "e",
"hireable": true,
"bio": "b",
"twitter_username": "t",
"public_repos": 1,
"followers": 1,
"following": 1,
"created_at": ` + referenceTimeStr + `,
"suspended_at": ` + referenceTimeStr + `,
"url": "u"
},
"suspended_at": ` + referenceTimeStr + `
}
}`

testJSONMarshal(t, u, want)
}

func TestPullRequestTargetEvent_Marshal(t *testing.T) {
testJSONMarshal(t, &PullRequestTargetEvent{}, "{}")

Expand Down
64 changes: 64 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.