Skip to content
This repository was archived by the owner on Mar 10, 2023. It is now read-only.

Commit e53d306

Browse files
committed
Add id to repo/owner for GitHub
Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
1 parent 1f16c03 commit e53d306

2 files changed

Lines changed: 40 additions & 37 deletions

File tree

sdk/event.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package sdk
2+
3+
// Event info used to pass events between functions
4+
type Event struct {
5+
Service string `json:"service"`
6+
Owner string `json:"owner"`
7+
Repository string `json:"repository"`
8+
Image string `json:"image"`
9+
SHA string `json:"sha"`
10+
URL string `json:"url"`
11+
InstallationID int `json:"installationID"`
12+
Environment map[string]string `json:"environment"`
13+
Secrets []string `json:"secrets"`
14+
Private bool `json:"private"`
15+
SCM string `json:"scm"`
16+
}
17+
18+
// BuildEventFromPushEvent function to build Event from PushEvent
19+
func BuildEventFromPushEvent(pushEvent PushEvent) *Event {
20+
info := Event{}
21+
22+
info.Service = pushEvent.Repository.Name
23+
info.Owner = pushEvent.Repository.Owner.Login
24+
info.Repository = pushEvent.Repository.Name
25+
info.URL = pushEvent.Repository.CloneURL
26+
info.Private = pushEvent.Repository.Private
27+
28+
info.SHA = pushEvent.AfterCommitID
29+
info.InstallationID = pushEvent.Installation.ID
30+
31+
return &info
32+
}
Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,37 @@
11
package sdk
22

3-
// PushEvent as received from GitHub
4-
type PushEventInstallation struct {
5-
ID int `json:"id"`
6-
}
7-
3+
// PushEventRepository represents the repository from a push event
84
type PushEventRepository struct {
95
Name string `json:"name"`
106
FullName string `json:"full_name"`
117
CloneURL string `json:"clone_url"`
128
Private bool `json:"private"`
9+
ID int64 `json:"id"`
1310

1411
Owner Owner `json:"owner"`
1512
}
1613

14+
// PushEvent is received from GitHub's push event subscription
1715
type PushEvent struct {
18-
SCM string
1916
Ref string `json:"ref"`
2017
Repository PushEventRepository
2118
AfterCommitID string `json:"after"`
2219
Installation PushEventInstallation
20+
SCM string // SCM field is for internal use and not provided by GitHub
2321
}
2422

2523
// Owner is the owner of a GitHub repo
2624
type Owner struct {
2725
Login string `json:"login"`
2826
Email string `json:"email"`
27+
ID int64 `json:"id"`
2928
}
3029

31-
// Event info to pass/store events across functions
32-
type Event struct {
33-
Service string `json:"service"`
34-
Owner string `json:"owner"`
35-
Repository string `json:"repository"`
36-
Image string `json:"image"`
37-
SHA string `json:"sha"`
38-
URL string `json:"url"`
39-
InstallationID int `json:"installationID"`
40-
Environment map[string]string `json:"environment"`
41-
Secrets []string `json:"secrets"`
42-
Private bool `json:"private"`
43-
SCM string `json:"scm"`
30+
type PushEventInstallation struct {
31+
ID int `json:"id"`
4432
}
4533

46-
// PushEvent as received from GitLab
47-
34+
// GitLabPushEvent as received from GitLab's system hook event
4835
type GitLabPushEvent struct {
4936
Ref string `json:"ref"`
5037
UserUsername string `json:"user_username"`
@@ -72,19 +59,3 @@ type Customer struct {
7259
type Sender struct {
7360
Login string `json:"login"`
7461
}
75-
76-
// BuildEventFromPushEvent function to build Event from PushEvent
77-
func BuildEventFromPushEvent(pushEvent PushEvent) *Event {
78-
info := Event{}
79-
80-
info.Service = pushEvent.Repository.Name
81-
info.Owner = pushEvent.Repository.Owner.Login
82-
info.Repository = pushEvent.Repository.Name
83-
info.URL = pushEvent.Repository.CloneURL
84-
info.Private = pushEvent.Repository.Private
85-
86-
info.SHA = pushEvent.AfterCommitID
87-
info.InstallationID = pushEvent.Installation.ID
88-
89-
return &info
90-
}

0 commit comments

Comments
 (0)