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 'repository_import' event #2364

Merged
merged 2 commits into from
May 16, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions github/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ func (e *Event) ParsePayload() (payload interface{}, err error) {
payload = &RepositoryEvent{}
case "RepositoryDispatchEvent":
payload = &RepositoryDispatchEvent{}
case "RepositoryImportEvent":
payload = &RepositoryImportEvent{}
case "RepositoryVulnerabilityAlertEvent":
payload = &RepositoryVulnerabilityAlertEvent{}
case "SecretScanningAlertEvent":
Expand Down
19 changes: 15 additions & 4 deletions github/event_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,8 +945,8 @@ type HeadCommit struct {
Modified []string `json:"modified,omitempty"`
}

func (p HeadCommit) String() string {
return Stringify(p)
func (h HeadCommit) String() string {
return Stringify(h)
}

// PushEventRepository represents the repo object in a PushEvent payload.
Expand Down Expand Up @@ -1051,17 +1051,28 @@ type RepositoryDispatchEvent struct {
Installation *Installation `json:"installation,omitempty"`
}

// RepositoryImportEvent represents the activity related to a repository being imported to GitHub.
//
// GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#repository_import
type RepositoryImportEvent struct {
// Status represents the final state of the import. This can be one of "success", "cancelled", or "failure".
Status *string `json:"status,omitempty"`
ldez marked this conversation as resolved.
Show resolved Hide resolved
Repo *Repository `json:"repository,omitempty"`
Org *Organization `json:"organization,omitempty"`
Sender *User `json:"sender,omitempty"`
}

// RepositoryVulnerabilityAlertEvent is triggered when a security alert is created, dismissed, or resolved.
//
// GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#repository_vulnerability_alert
type RepositoryVulnerabilityAlertEvent struct {
// Action is the action that was performed. Possible values are: "create", "dismiss", "resolve".
Action *string `json:"action,omitempty"`

//The security alert of the vulnerable dependency.
// The security alert of the vulnerable dependency.
Alert *RepositoryVulnerabilityAlert `json:"alert,omitempty"`

//The repository of the vulnerable dependency.
// The repository of the vulnerable dependency.
Repository *Repository `json:"repository,omitempty"`

// The following fields are only populated by Webhook events.
Expand Down
86 changes: 86 additions & 0 deletions github/event_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6745,6 +6745,92 @@ func TestRepositoryDispatchEvent_Marshal(t *testing.T) {
testJSONMarshal(t, u, want)
}

func TestRepositoryImportEvent_Marshal(t *testing.T) {
testJSONMarshal(t, &RepositoryImportEvent{}, "{}")

u := &RepositoryImportEvent{
Status: String("success"),
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"),
},
}

want := `{
"status": "success",
"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"
}
}`

testJSONMarshal(t, u, want)
}

func TestRepositoryEvent_Marshal(t *testing.T) {
testJSONMarshal(t, &RepositoryEvent{}, "{}")

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

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

31 changes: 31 additions & 0 deletions github/github-accessors_test.go

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

1 change: 1 addition & 0 deletions github/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ var (
"push": "PushEvent",
"repository": "RepositoryEvent",
"repository_dispatch": "RepositoryDispatchEvent",
"repository_import": "RepositoryImportEvent",
"repository_vulnerability_alert": "RepositoryVulnerabilityAlertEvent",
"release": "ReleaseEvent",
"secret_scanning_alert": "SecretScanningAlertEvent",
Expand Down
4 changes: 4 additions & 0 deletions github/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,10 @@ func TestParseWebHook(t *testing.T) {
payload: &WatchEvent{},
messageType: "watch",
},
{
payload: &RepositoryImportEvent{},
messageType: "repository_import",
},
{
payload: &RepositoryDispatchEvent{},
messageType: "repository_dispatch",
Expand Down
1 change: 1 addition & 0 deletions github/repos_hooks_deliveries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ var hookDeliveryPayloadTypeToStruct = map[string]interface{}{
"release": &ReleaseEvent{},
"repository": &RepositoryEvent{},
"repository_dispatch": &RepositoryDispatchEvent{},
"repository_import": &RepositoryImportEvent{},
"repository_vulnerability_alert": &RepositoryVulnerabilityAlertEvent{},
"secret_scanning_alert": &SecretScanningAlertEvent{},
"star": &StarEvent{},
Expand Down