mirror of
https://github.com/google/go-github.git
synced 2026-10-28 16:34:37 +08:00
Add merge_group webhook event via MergeGroupEvent and MergeGroup structs (#2556)
This commit is contained in:
1 parent
020d9ae4fb
commit
16cdd7dcf4
7 files changed
+510
No files matched your search
@@ -76,6 +76,8 @@ func (e *Event) ParsePayload() (payload interface{}, err error) {
|
||||
payload = &MemberEvent{}
|
||||
case "MembershipEvent":
|
||||
payload = &MembershipEvent{}
|
||||
case "MergeGroupEvent":
|
||||
payload = &MergeGroupEvent{}
|
||||
case "MetaEvent":
|
||||
payload = &MetaEvent{}
|
||||
case "MilestoneEvent":
|
||||
|
||||
@@ -559,6 +559,37 @@ type MembershipEvent struct {
|
||||
Installation *Installation `json:"installation,omitempty"`
|
||||
}
|
||||
|
||||
// MergeGroup represents the merge group in a merge queue.
|
||||
type MergeGroup struct {
|
||||
// The SHA of the merge group.
|
||||
HeadSHA *string `json:"head_sha,omitempty"`
|
||||
// The full ref of the merge group.
|
||||
HeadRef *string `json:"head_ref,omitempty"`
|
||||
// The SHA of the merge group's parent commit.
|
||||
BaseSHA *string `json:"base_sha,omitempty"`
|
||||
// The full ref of the branch the merge group will be merged into.
|
||||
BaseRef *string `json:"base_ref,omitempty"`
|
||||
// An expanded representation of the head_sha commit.
|
||||
HeadCommit *Commit `json:"head_commit,omitempty"`
|
||||
}
|
||||
|
||||
// MergeGroupEvent represents activity related to merge groups in a merge queue. The type of activity is specified
|
||||
// in the action property of the payload object.
|
||||
//
|
||||
// GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#merge_group
|
||||
type MergeGroupEvent struct {
|
||||
// The action that was performed. Currently, can only be checks_requested.
|
||||
Action *string `json:"action,omitempty"`
|
||||
// The merge group.
|
||||
MergeGroup *MergeGroup `json:"merge_group,omitempty"`
|
||||
|
||||
// The following fields are only populated by Webhook events.
|
||||
Repo *Repository `json:"repository,omitempty"`
|
||||
Org *Organization `json:"organization,omitempty"`
|
||||
Installation *Installation `json:"installation,omitempty"`
|
||||
Sender *User `json:"sender,omitempty"`
|
||||
}
|
||||
|
||||
// MetaEvent is triggered when the webhook that this event is configured on is deleted.
|
||||
// This event will only listen for changes to the particular hook the event is installed on.
|
||||
// Therefore, it must be selected for each hook that you'd like to receive meta events for.
|
||||
|
||||
@@ -8233,6 +8233,298 @@ func TestMembershipEvent_Marshal(t *testing.T) {
|
||||
testJSONMarshal(t, u, want)
|
||||
}
|
||||
|
||||
func TestMergeGroupEvent_Marshal(t *testing.T) {
|
||||
testJSONMarshal(t, &MergeGroupEvent{}, "{}")
|
||||
|
||||
u := &MergeGroupEvent{
|
||||
Action: String("a"),
|
||||
MergeGroup: &MergeGroup{
|
||||
HeadSHA: String("hs"),
|
||||
HeadRef: String("hr"),
|
||||
BaseSHA: String("bs"),
|
||||
BaseRef: String("br"),
|
||||
HeadCommit: &Commit{NodeID: String("nid")},
|
||||
},
|
||||
Repo: &Repository{
|
||||
ID: Int64(1),
|
||||
URL: String("s"),
|
||||
Name: String("n"),
|
||||
},
|
||||
Org: &Organization{
|
||||
BillingEmail: String("be"),
|
||||
Blog: String("b"),
|
||||
Company: String("c"),
|
||||
Email: String("e"),
|
||||
TwitterUsername: String("tu"),
|
||||
Location: String("loc"),
|
||||
Name: String("n"),
|
||||
Description: String("d"),
|
||||
IsVerified: Bool(true),
|
||||
HasOrganizationProjects: Bool(true),
|
||||
HasRepositoryProjects: Bool(true),
|
||||
DefaultRepoPermission: String("drp"),
|
||||
MembersCanCreateRepos: Bool(true),
|
||||
MembersCanCreateInternalRepos: Bool(true),
|
||||
MembersCanCreatePrivateRepos: Bool(true),
|
||||
MembersCanCreatePublicRepos: Bool(false),
|
||||
MembersAllowedRepositoryCreationType: String("marct"),
|
||||
MembersCanCreatePages: Bool(true),
|
||||
MembersCanCreatePublicPages: Bool(false),
|
||||
MembersCanCreatePrivatePages: Bool(true),
|
||||
},
|
||||
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",
|
||||
"merge_group": {
|
||||
"head_sha": "hs",
|
||||
"head_ref": "hr",
|
||||
"base_sha": "bs",
|
||||
"base_ref": "br",
|
||||
"head_commit": {
|
||||
"node_id": "nid"
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"id": 1,
|
||||
"name": "n",
|
||||
"url": "s"
|
||||
},
|
||||
"organization": {
|
||||
"name": "n",
|
||||
"company": "c",
|
||||
"blog": "b",
|
||||
"location": "loc",
|
||||
"email": "e",
|
||||
"twitter_username": "tu",
|
||||
"description": "d",
|
||||
"billing_email": "be",
|
||||
"is_verified": true,
|
||||
"has_organization_projects": true,
|
||||
"has_repository_projects": true,
|
||||
"default_repository_permission": "drp",
|
||||
"members_can_create_repositories": true,
|
||||
"members_can_create_public_repositories": false,
|
||||
"members_can_create_private_repositories": true,
|
||||
"members_can_create_internal_repositories": true,
|
||||
"members_allowed_repository_creation_type": "marct",
|
||||
"members_can_create_pages": true,
|
||||
"members_can_create_public_pages": false,
|
||||
"members_can_create_private_pages": true
|
||||
},
|
||||
"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 TestOrgBlockEvent_Marshal(t *testing.T) {
|
||||
testJSONMarshal(t, &OrgBlockEvent{}, "{}")
|
||||
|
||||
|
||||
@@ -8870,6 +8870,94 @@ func (m *MembershipEvent) GetTeam() *Team {
|
||||
return m.Team
|
||||
}
|
||||
|
||||
// GetBaseRef returns the BaseRef field if it's non-nil, zero value otherwise.
|
||||
func (m *MergeGroup) GetBaseRef() string {
|
||||
if m == nil || m.BaseRef == nil {
|
||||
return ""
|
||||
}
|
||||
return *m.BaseRef
|
||||
}
|
||||
|
||||
// GetBaseSHA returns the BaseSHA field if it's non-nil, zero value otherwise.
|
||||
func (m *MergeGroup) GetBaseSHA() string {
|
||||
if m == nil || m.BaseSHA == nil {
|
||||
return ""
|
||||
}
|
||||
return *m.BaseSHA
|
||||
}
|
||||
|
||||
// GetHeadCommit returns the HeadCommit field.
|
||||
func (m *MergeGroup) GetHeadCommit() *Commit {
|
||||
if m == nil {
|
||||
return nil
|
||||
}
|
||||
return m.HeadCommit
|
||||
}
|
||||
|
||||
// GetHeadRef returns the HeadRef field if it's non-nil, zero value otherwise.
|
||||
func (m *MergeGroup) GetHeadRef() string {
|
||||
if m == nil || m.HeadRef == nil {
|
||||
return ""
|
||||
}
|
||||
return *m.HeadRef
|
||||
}
|
||||
|
||||
// GetHeadSHA returns the HeadSHA field if it's non-nil, zero value otherwise.
|
||||
func (m *MergeGroup) GetHeadSHA() string {
|
||||
if m == nil || m.HeadSHA == nil {
|
||||
return ""
|
||||
}
|
||||
return *m.HeadSHA
|
||||
}
|
||||
|
||||
// GetAction returns the Action field if it's non-nil, zero value otherwise.
|
||||
func (m *MergeGroupEvent) GetAction() string {
|
||||
if m == nil || m.Action == nil {
|
||||
return ""
|
||||
}
|
||||
return *m.Action
|
||||
}
|
||||
|
||||
// GetInstallation returns the Installation field.
|
||||
func (m *MergeGroupEvent) GetInstallation() *Installation {
|
||||
if m == nil {
|
||||
return nil
|
||||
}
|
||||
return m.Installation
|
||||
}
|
||||
|
||||
// GetMergeGroup returns the MergeGroup field.
|
||||
func (m *MergeGroupEvent) GetMergeGroup() *MergeGroup {
|
||||
if m == nil {
|
||||
return nil
|
||||
}
|
||||
return m.MergeGroup
|
||||
}
|
||||
|
||||
// GetOrg returns the Org field.
|
||||
func (m *MergeGroupEvent) GetOrg() *Organization {
|
||||
if m == nil {
|
||||
return nil
|
||||
}
|
||||
return m.Org
|
||||
}
|
||||
|
||||
// GetRepo returns the Repo field.
|
||||
func (m *MergeGroupEvent) GetRepo() *Repository {
|
||||
if m == nil {
|
||||
return nil
|
||||
}
|
||||
return m.Repo
|
||||
}
|
||||
|
||||
// GetSender returns the Sender field.
|
||||
func (m *MergeGroupEvent) GetSender() *User {
|
||||
if m == nil {
|
||||
return nil
|
||||
}
|
||||
return m.Sender
|
||||
}
|
||||
|
||||
// GetText returns the Text field if it's non-nil, zero value otherwise.
|
||||
func (m *Message) GetText() string {
|
||||
if m == nil || m.Text == nil {
|
||||
|
||||
@@ -10389,6 +10389,98 @@ func TestMembershipEvent_GetTeam(tt *testing.T) {
|
||||
m.GetTeam()
|
||||
}
|
||||
|
||||
func TestMergeGroup_GetBaseRef(tt *testing.T) {
|
||||
var zeroValue string
|
||||
m := &MergeGroup{BaseRef: &zeroValue}
|
||||
m.GetBaseRef()
|
||||
m = &MergeGroup{}
|
||||
m.GetBaseRef()
|
||||
m = nil
|
||||
m.GetBaseRef()
|
||||
}
|
||||
|
||||
func TestMergeGroup_GetBaseSHA(tt *testing.T) {
|
||||
var zeroValue string
|
||||
m := &MergeGroup{BaseSHA: &zeroValue}
|
||||
m.GetBaseSHA()
|
||||
m = &MergeGroup{}
|
||||
m.GetBaseSHA()
|
||||
m = nil
|
||||
m.GetBaseSHA()
|
||||
}
|
||||
|
||||
func TestMergeGroup_GetHeadCommit(tt *testing.T) {
|
||||
m := &MergeGroup{}
|
||||
m.GetHeadCommit()
|
||||
m = nil
|
||||
m.GetHeadCommit()
|
||||
}
|
||||
|
||||
func TestMergeGroup_GetHeadRef(tt *testing.T) {
|
||||
var zeroValue string
|
||||
m := &MergeGroup{HeadRef: &zeroValue}
|
||||
m.GetHeadRef()
|
||||
m = &MergeGroup{}
|
||||
m.GetHeadRef()
|
||||
m = nil
|
||||
m.GetHeadRef()
|
||||
}
|
||||
|
||||
func TestMergeGroup_GetHeadSHA(tt *testing.T) {
|
||||
var zeroValue string
|
||||
m := &MergeGroup{HeadSHA: &zeroValue}
|
||||
m.GetHeadSHA()
|
||||
m = &MergeGroup{}
|
||||
m.GetHeadSHA()
|
||||
m = nil
|
||||
m.GetHeadSHA()
|
||||
}
|
||||
|
||||
func TestMergeGroupEvent_GetAction(tt *testing.T) {
|
||||
var zeroValue string
|
||||
m := &MergeGroupEvent{Action: &zeroValue}
|
||||
m.GetAction()
|
||||
m = &MergeGroupEvent{}
|
||||
m.GetAction()
|
||||
m = nil
|
||||
m.GetAction()
|
||||
}
|
||||
|
||||
func TestMergeGroupEvent_GetInstallation(tt *testing.T) {
|
||||
m := &MergeGroupEvent{}
|
||||
m.GetInstallation()
|
||||
m = nil
|
||||
m.GetInstallation()
|
||||
}
|
||||
|
||||
func TestMergeGroupEvent_GetMergeGroup(tt *testing.T) {
|
||||
m := &MergeGroupEvent{}
|
||||
m.GetMergeGroup()
|
||||
m = nil
|
||||
m.GetMergeGroup()
|
||||
}
|
||||
|
||||
func TestMergeGroupEvent_GetOrg(tt *testing.T) {
|
||||
m := &MergeGroupEvent{}
|
||||
m.GetOrg()
|
||||
m = nil
|
||||
m.GetOrg()
|
||||
}
|
||||
|
||||
func TestMergeGroupEvent_GetRepo(tt *testing.T) {
|
||||
m := &MergeGroupEvent{}
|
||||
m.GetRepo()
|
||||
m = nil
|
||||
m.GetRepo()
|
||||
}
|
||||
|
||||
func TestMergeGroupEvent_GetSender(tt *testing.T) {
|
||||
m := &MergeGroupEvent{}
|
||||
m.GetSender()
|
||||
m = nil
|
||||
m.GetSender()
|
||||
}
|
||||
|
||||
func TestMessage_GetText(tt *testing.T) {
|
||||
var zeroValue string
|
||||
m := &Message{Text: &zeroValue}
|
||||
|
||||
@@ -68,6 +68,7 @@ var (
|
||||
"marketplace_purchase": "MarketplacePurchaseEvent",
|
||||
"member": "MemberEvent",
|
||||
"membership": "MembershipEvent",
|
||||
"merge_group": "MergeGroupEvent",
|
||||
"meta": "MetaEvent",
|
||||
"milestone": "MilestoneEvent",
|
||||
"organization": "OrganizationEvent",
|
||||
|
||||
@@ -353,6 +353,10 @@ func TestParseWebHook(t *testing.T) {
|
||||
payload: &MembershipEvent{},
|
||||
messageType: "membership",
|
||||
},
|
||||
{
|
||||
payload: &MergeGroupEvent{},
|
||||
messageType: "merge_group",
|
||||
},
|
||||
{
|
||||
payload: &MetaEvent{},
|
||||
messageType: "meta",
|
||||
|
||||
Reference in new issue
Block a user