Skip to content

Commit 16cdd7d

Browse files
Add merge_group webhook event via MergeGroupEvent and MergeGroup structs (#2556)
1 parent 020d9ae commit 16cdd7d

File tree

7 files changed

+510
-0
lines changed

7 files changed

+510
-0
lines changed

github/event.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ func (e *Event) ParsePayload() (payload interface{}, err error) {
7676
payload = &MemberEvent{}
7777
case "MembershipEvent":
7878
payload = &MembershipEvent{}
79+
case "MergeGroupEvent":
80+
payload = &MergeGroupEvent{}
7981
case "MetaEvent":
8082
payload = &MetaEvent{}
8183
case "MilestoneEvent":

github/event_types.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,37 @@ type MembershipEvent struct {
559559
Installation *Installation `json:"installation,omitempty"`
560560
}
561561

562+
// MergeGroup represents the merge group in a merge queue.
563+
type MergeGroup struct {
564+
// The SHA of the merge group.
565+
HeadSHA *string `json:"head_sha,omitempty"`
566+
// The full ref of the merge group.
567+
HeadRef *string `json:"head_ref,omitempty"`
568+
// The SHA of the merge group's parent commit.
569+
BaseSHA *string `json:"base_sha,omitempty"`
570+
// The full ref of the branch the merge group will be merged into.
571+
BaseRef *string `json:"base_ref,omitempty"`
572+
// An expanded representation of the head_sha commit.
573+
HeadCommit *Commit `json:"head_commit,omitempty"`
574+
}
575+
576+
// MergeGroupEvent represents activity related to merge groups in a merge queue. The type of activity is specified
577+
// in the action property of the payload object.
578+
//
579+
// GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#merge_group
580+
type MergeGroupEvent struct {
581+
// The action that was performed. Currently, can only be checks_requested.
582+
Action *string `json:"action,omitempty"`
583+
// The merge group.
584+
MergeGroup *MergeGroup `json:"merge_group,omitempty"`
585+
586+
// The following fields are only populated by Webhook events.
587+
Repo *Repository `json:"repository,omitempty"`
588+
Org *Organization `json:"organization,omitempty"`
589+
Installation *Installation `json:"installation,omitempty"`
590+
Sender *User `json:"sender,omitempty"`
591+
}
592+
562593
// MetaEvent is triggered when the webhook that this event is configured on is deleted.
563594
// This event will only listen for changes to the particular hook the event is installed on.
564595
// Therefore, it must be selected for each hook that you'd like to receive meta events for.

github/event_types_test.go

Lines changed: 292 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8233,6 +8233,298 @@ func TestMembershipEvent_Marshal(t *testing.T) {
82338233
testJSONMarshal(t, u, want)
82348234
}
82358235

8236+
func TestMergeGroupEvent_Marshal(t *testing.T) {
8237+
testJSONMarshal(t, &MergeGroupEvent{}, "{}")
8238+
8239+
u := &MergeGroupEvent{
8240+
Action: String("a"),
8241+
MergeGroup: &MergeGroup{
8242+
HeadSHA: String("hs"),
8243+
HeadRef: String("hr"),
8244+
BaseSHA: String("bs"),
8245+
BaseRef: String("br"),
8246+
HeadCommit: &Commit{NodeID: String("nid")},
8247+
},
8248+
Repo: &Repository{
8249+
ID: Int64(1),
8250+
URL: String("s"),
8251+
Name: String("n"),
8252+
},
8253+
Org: &Organization{
8254+
BillingEmail: String("be"),
8255+
Blog: String("b"),
8256+
Company: String("c"),
8257+
Email: String("e"),
8258+
TwitterUsername: String("tu"),
8259+
Location: String("loc"),
8260+
Name: String("n"),
8261+
Description: String("d"),
8262+
IsVerified: Bool(true),
8263+
HasOrganizationProjects: Bool(true),
8264+
HasRepositoryProjects: Bool(true),
8265+
DefaultRepoPermission: String("drp"),
8266+
MembersCanCreateRepos: Bool(true),
8267+
MembersCanCreateInternalRepos: Bool(true),
8268+
MembersCanCreatePrivateRepos: Bool(true),
8269+
MembersCanCreatePublicRepos: Bool(false),
8270+
MembersAllowedRepositoryCreationType: String("marct"),
8271+
MembersCanCreatePages: Bool(true),
8272+
MembersCanCreatePublicPages: Bool(false),
8273+
MembersCanCreatePrivatePages: Bool(true),
8274+
},
8275+
Sender: &User{
8276+
Login: String("l"),
8277+
ID: Int64(1),
8278+
NodeID: String("n"),
8279+
URL: String("u"),
8280+
ReposURL: String("r"),
8281+
EventsURL: String("e"),
8282+
AvatarURL: String("a"),
8283+
},
8284+
Installation: &Installation{
8285+
ID: Int64(1),
8286+
NodeID: String("nid"),
8287+
AppID: Int64(1),
8288+
AppSlug: String("as"),
8289+
TargetID: Int64(1),
8290+
Account: &User{
8291+
Login: String("l"),
8292+
ID: Int64(1),
8293+
URL: String("u"),
8294+
AvatarURL: String("a"),
8295+
GravatarID: String("g"),
8296+
Name: String("n"),
8297+
Company: String("c"),
8298+
Blog: String("b"),
8299+
Location: String("l"),
8300+
Email: String("e"),
8301+
Hireable: Bool(true),
8302+
Bio: String("b"),
8303+
TwitterUsername: String("t"),
8304+
PublicRepos: Int(1),
8305+
Followers: Int(1),
8306+
Following: Int(1),
8307+
CreatedAt: &Timestamp{referenceTime},
8308+
SuspendedAt: &Timestamp{referenceTime},
8309+
},
8310+
AccessTokensURL: String("atu"),
8311+
RepositoriesURL: String("ru"),
8312+
HTMLURL: String("hu"),
8313+
TargetType: String("tt"),
8314+
SingleFileName: String("sfn"),
8315+
RepositorySelection: String("rs"),
8316+
Events: []string{"e"},
8317+
SingleFilePaths: []string{"s"},
8318+
Permissions: &InstallationPermissions{
8319+
Actions: String("a"),
8320+
Administration: String("ad"),
8321+
Checks: String("c"),
8322+
Contents: String("co"),
8323+
ContentReferences: String("cr"),
8324+
Deployments: String("d"),
8325+
Environments: String("e"),
8326+
Issues: String("i"),
8327+
Metadata: String("md"),
8328+
Members: String("m"),
8329+
OrganizationAdministration: String("oa"),
8330+
OrganizationHooks: String("oh"),
8331+
OrganizationPlan: String("op"),
8332+
OrganizationPreReceiveHooks: String("opr"),
8333+
OrganizationProjects: String("op"),
8334+
OrganizationSecrets: String("os"),
8335+
OrganizationSelfHostedRunners: String("osh"),
8336+
OrganizationUserBlocking: String("oub"),
8337+
Packages: String("pkg"),
8338+
Pages: String("pg"),
8339+
PullRequests: String("pr"),
8340+
RepositoryHooks: String("rh"),
8341+
RepositoryProjects: String("rp"),
8342+
RepositoryPreReceiveHooks: String("rprh"),
8343+
Secrets: String("s"),
8344+
SecretScanningAlerts: String("ssa"),
8345+
SecurityEvents: String("se"),
8346+
SingleFile: String("sf"),
8347+
Statuses: String("s"),
8348+
TeamDiscussions: String("td"),
8349+
VulnerabilityAlerts: String("va"),
8350+
Workflows: String("w"),
8351+
},
8352+
CreatedAt: &Timestamp{referenceTime},
8353+
UpdatedAt: &Timestamp{referenceTime},
8354+
HasMultipleSingleFiles: Bool(false),
8355+
SuspendedBy: &User{
8356+
Login: String("l"),
8357+
ID: Int64(1),
8358+
URL: String("u"),
8359+
AvatarURL: String("a"),
8360+
GravatarID: String("g"),
8361+
Name: String("n"),
8362+
Company: String("c"),
8363+
Blog: String("b"),
8364+
Location: String("l"),
8365+
Email: String("e"),
8366+
Hireable: Bool(true),
8367+
Bio: String("b"),
8368+
TwitterUsername: String("t"),
8369+
PublicRepos: Int(1),
8370+
Followers: Int(1),
8371+
Following: Int(1),
8372+
CreatedAt: &Timestamp{referenceTime},
8373+
SuspendedAt: &Timestamp{referenceTime},
8374+
},
8375+
SuspendedAt: &Timestamp{referenceTime},
8376+
},
8377+
}
8378+
8379+
want := `{
8380+
"action": "a",
8381+
"merge_group": {
8382+
"head_sha": "hs",
8383+
"head_ref": "hr",
8384+
"base_sha": "bs",
8385+
"base_ref": "br",
8386+
"head_commit": {
8387+
"node_id": "nid"
8388+
}
8389+
},
8390+
"repository": {
8391+
"id": 1,
8392+
"name": "n",
8393+
"url": "s"
8394+
},
8395+
"organization": {
8396+
"name": "n",
8397+
"company": "c",
8398+
"blog": "b",
8399+
"location": "loc",
8400+
"email": "e",
8401+
"twitter_username": "tu",
8402+
"description": "d",
8403+
"billing_email": "be",
8404+
"is_verified": true,
8405+
"has_organization_projects": true,
8406+
"has_repository_projects": true,
8407+
"default_repository_permission": "drp",
8408+
"members_can_create_repositories": true,
8409+
"members_can_create_public_repositories": false,
8410+
"members_can_create_private_repositories": true,
8411+
"members_can_create_internal_repositories": true,
8412+
"members_allowed_repository_creation_type": "marct",
8413+
"members_can_create_pages": true,
8414+
"members_can_create_public_pages": false,
8415+
"members_can_create_private_pages": true
8416+
},
8417+
"sender": {
8418+
"login": "l",
8419+
"id": 1,
8420+
"node_id": "n",
8421+
"avatar_url": "a",
8422+
"url": "u",
8423+
"events_url": "e",
8424+
"repos_url": "r"
8425+
},
8426+
"installation": {
8427+
"id": 1,
8428+
"node_id": "nid",
8429+
"app_id": 1,
8430+
"app_slug": "as",
8431+
"target_id": 1,
8432+
"account": {
8433+
"login": "l",
8434+
"id": 1,
8435+
"avatar_url": "a",
8436+
"gravatar_id": "g",
8437+
"name": "n",
8438+
"company": "c",
8439+
"blog": "b",
8440+
"location": "l",
8441+
"email": "e",
8442+
"hireable": true,
8443+
"bio": "b",
8444+
"twitter_username": "t",
8445+
"public_repos": 1,
8446+
"followers": 1,
8447+
"following": 1,
8448+
"created_at": ` + referenceTimeStr + `,
8449+
"suspended_at": ` + referenceTimeStr + `,
8450+
"url": "u"
8451+
},
8452+
"access_tokens_url": "atu",
8453+
"repositories_url": "ru",
8454+
"html_url": "hu",
8455+
"target_type": "tt",
8456+
"single_file_name": "sfn",
8457+
"repository_selection": "rs",
8458+
"events": [
8459+
"e"
8460+
],
8461+
"single_file_paths": [
8462+
"s"
8463+
],
8464+
"permissions": {
8465+
"actions": "a",
8466+
"administration": "ad",
8467+
"checks": "c",
8468+
"contents": "co",
8469+
"content_references": "cr",
8470+
"deployments": "d",
8471+
"environments": "e",
8472+
"issues": "i",
8473+
"metadata": "md",
8474+
"members": "m",
8475+
"organization_administration": "oa",
8476+
"organization_hooks": "oh",
8477+
"organization_plan": "op",
8478+
"organization_pre_receive_hooks": "opr",
8479+
"organization_projects": "op",
8480+
"organization_secrets": "os",
8481+
"organization_self_hosted_runners": "osh",
8482+
"organization_user_blocking": "oub",
8483+
"packages": "pkg",
8484+
"pages": "pg",
8485+
"pull_requests": "pr",
8486+
"repository_hooks": "rh",
8487+
"repository_projects": "rp",
8488+
"repository_pre_receive_hooks": "rprh",
8489+
"secrets": "s",
8490+
"secret_scanning_alerts": "ssa",
8491+
"security_events": "se",
8492+
"single_file": "sf",
8493+
"statuses": "s",
8494+
"team_discussions": "td",
8495+
"vulnerability_alerts": "va",
8496+
"workflows": "w"
8497+
},
8498+
"created_at": ` + referenceTimeStr + `,
8499+
"updated_at": ` + referenceTimeStr + `,
8500+
"has_multiple_single_files": false,
8501+
"suspended_by": {
8502+
"login": "l",
8503+
"id": 1,
8504+
"avatar_url": "a",
8505+
"gravatar_id": "g",
8506+
"name": "n",
8507+
"company": "c",
8508+
"blog": "b",
8509+
"location": "l",
8510+
"email": "e",
8511+
"hireable": true,
8512+
"bio": "b",
8513+
"twitter_username": "t",
8514+
"public_repos": 1,
8515+
"followers": 1,
8516+
"following": 1,
8517+
"created_at": ` + referenceTimeStr + `,
8518+
"suspended_at": ` + referenceTimeStr + `,
8519+
"url": "u"
8520+
},
8521+
"suspended_at": ` + referenceTimeStr + `
8522+
}
8523+
}`
8524+
8525+
testJSONMarshal(t, u, want)
8526+
}
8527+
82368528
func TestOrgBlockEvent_Marshal(t *testing.T) {
82378529
testJSONMarshal(t, &OrgBlockEvent{}, "{}")
82388530

0 commit comments

Comments
 (0)