Skip to content

Commit

Permalink
Merge branch 'master' into fix-repo-rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Osama Faqhruldin authored Jul 17, 2023
2 parents 889737e + bedd4e3 commit 5632ccb
Show file tree
Hide file tree
Showing 9 changed files with 814 additions and 15 deletions.
2 changes: 2 additions & 0 deletions github/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ func (e *Event) ParsePayload() (payload interface{}, err error) {
payload = &PackageEvent{}
case "PageBuildEvent":
payload = &PageBuildEvent{}
case "PersonalAccessTokenRequestEvent":
payload = &PersonalAccessTokenRequestEvent{}
case "PingEvent":
payload = &PingEvent{}
case "ProjectEvent":
Expand Down
68 changes: 68 additions & 0 deletions github/event_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,74 @@ type PageBuildEvent struct {
Installation *Installation `json:"installation,omitempty"`
}

// PersonalAccessTokenRequestEvent occurs when there is activity relating to a
// request for a fine-grained personal access token to access resources that
// belong to a resource owner that requires approval for token access.
// The webhook event name is "personal_access_token_request".
//
// GitHub API docs: https://docs.github.com/en/webhooks-and-events/webhooks/webhook-events-and-payloads#personal_access_token_request
type PersonalAccessTokenRequestEvent struct {
// Action is the action that was performed. Possible values are:
// "approved", "cancelled", "created" or "denied"
Action *string `json:"action,omitempty"`
PersonalAccessTokenRequest *PersonalAccessTokenRequest `json:"personal_access_token_request,omitempty"`
Org *Organization `json:"organization,omitempty"`
Sender *User `json:"sender,omitempty"`
Installation *Installation `json:"installation,omitempty"`
}

// PersonalAccessTokenRequest contains the details of a PersonalAccessTokenRequestEvent.
type PersonalAccessTokenRequest struct {
// Unique identifier of the request for access via fine-grained personal
// access token. Used as the pat_request_id parameter in the list and review
// API calls.
ID *int64 `json:"id,omitempty"`
Owner *User `json:"owner,omitempty"`

// New requested permissions, categorized by type of permission.
PermissionsAdded *PersonalAccessTokenPermissions `json:"permissions_added,omitempty"`

// Requested permissions that elevate access for a previously approved
// request for access, categorized by type of permission.
PermissionsUpgraded *PersonalAccessTokenPermissions `json:"permissions_upgraded,omitempty"`

// Permissions requested, categorized by type of permission.
// This field incorporates permissions_added and permissions_upgraded.
PermissionsResult *PersonalAccessTokenPermissions `json:"permissions_result,omitempty"`

// Type of repository selection requested. Possible values are:
// "none", "all" or "subset"
RepositorySelection *string `json:"repository_selection,omitempty"`

// The number of repositories the token is requesting access to.
// This field is only populated when repository_selection is subset.
RepositoryCount *int64 `json:"repository_count,omitempty"`

// An array of repository objects the token is requesting access to.
// This field is only populated when repository_selection is subset.
Repositories []*Repository `json:"repositories,omitempty"`

// Date and time when the request for access was created.
CreatedAt *Timestamp `json:"created_at,omitempty"`

// Whether the associated fine-grained personal access token has expired.
TokenExpired *bool `json:"token_expired,omitempty"`

// Date and time when the associated fine-grained personal access token expires.
TokenExpiresAt *Timestamp `json:"token_expires_at,omitempty"`

// Date and time when the associated fine-grained personal access token was last used for authentication.
TokenLastUsedAt *Timestamp `json:"token_last_used_at,omitempty"`
}

// PersonalAccessTokenPermissions represents the original or newly requested
// scope of permissions for a fine-grained personal access token within a PersonalAccessTokenRequest.
type PersonalAccessTokenPermissions struct {
Org map[string]string `json:"organization,omitempty"`
Repo map[string]string `json:"repository,omitempty"`
Other map[string]string `json:"other,omitempty"`
}

// PingEvent is triggered when a Webhook is added to GitHub.
//
// GitHub API docs: https://developer.github.com/webhooks/#ping-event
Expand Down
74 changes: 74 additions & 0 deletions github/event_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7089,6 +7089,80 @@ func TestPackageEvent_Marshal(t *testing.T) {
testJSONMarshal(t, u, want)
}

func TestPersonalAccessTokenRequestEvent_Marshal(t *testing.T) {
testJSONMarshal(t, &PersonalAccessTokenRequestEvent{}, "{}")

event := &PersonalAccessTokenRequestEvent{
Action: String("a"),
PersonalAccessTokenRequest: &PersonalAccessTokenRequest{
ID: Int64(1),
Owner: &User{Login: String("l")},
PermissionsAdded: &PersonalAccessTokenPermissions{
Org: map[string]string{"organization_events": "read"},
Repo: map[string]string{"security_events": "write"},
},
CreatedAt: &Timestamp{referenceTime},
TokenExpired: Bool(false),
TokenExpiresAt: &Timestamp{referenceTime},
TokenLastUsedAt: &Timestamp{referenceTime},
RepositoryCount: Int64(1),
RepositorySelection: String("rs"),
Repositories: []*Repository{
{
Name: String("n"),
},
},
},
Org: &Organization{Name: String("n")},
Sender: &User{
Login: String("l"),
},
Installation: &Installation{
ID: Int64(1),
},
}

want := `{
"action": "a",
"personal_access_token_request": {
"id": 1,
"owner": {
"login": "l"
},
"permissions_added": {
"organization": {
"organization_events": "read"
},
"repository": {
"security_events": "write"
}
},
"created_at": ` + referenceTimeStr + `,
"token_expired": false,
"token_expires_at": ` + referenceTimeStr + `,
"token_last_used_at": ` + referenceTimeStr + `,
"repository_count": 1,
"repository_selection": "rs",
"repositories": [
{
"name": "n"
}
]
},
"organization": {
"name": "n"
},
"sender": {
"login": "l"
},
"installation": {
"id": 1
}
}`

testJSONMarshal(t, event, want)
}

func TestPingEvent_Marshal(t *testing.T) {
testJSONMarshal(t, &PingEvent{}, "{}")

Expand Down
164 changes: 162 additions & 2 deletions github/github-accessors.go

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

Loading

0 comments on commit 5632ccb

Please sign in to comment.