Skip to content

Commit

Permalink
Add check for supported Github events
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-nguyen committed Jul 7, 2018
1 parent 42a4313 commit 544168d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
17 changes: 14 additions & 3 deletions daemon/inertiad/webhook/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ type GithubPushEvent struct {
type GithubPushEventRepository struct {
FullName string `json:"full_name"`
GitURL string `json:"clone_url"`
SSHURL string `json:"ssh_url"`
}

func parseGithubEvent(r *http.Request, event string) (Payload, error) {
// TODO: Can switch on different event types here
fmt.Printf("Type: %s", event)
payload := GithubPushEvent{eventType: event}
var payload Payload
switch event {
case "push":
fmt.Println("Push event")
payload = GithubPushEvent{eventType: event}
default:
return nil, errors.New("Unsupported Github event")
}

err := json.NewDecoder(r.Body).Decode(&payload)
if err != nil {
Expand Down Expand Up @@ -54,3 +60,8 @@ func (g GithubPushEvent) GetRef() string {
func (g GithubPushEvent) GetGitURL() string {
return g.Repo.GitURL
}

// GetSSHURL returns the ssh URL
func (g GithubPushEvent) GetSSHURL() string {
return g.Repo.SSHURL
}
3 changes: 2 additions & 1 deletion daemon/inertiad/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Payload interface {
GetRepoName() string
GetRef() string
GetGitURL() string
GetSSHURL() string
}

func parse(r *http.Request) (Payload, error) {
Expand All @@ -28,7 +29,7 @@ func parse(r *http.Request) (Payload, error) {
githubEventHeader := r.Header.Get("x-github-event")
if len(githubEventHeader) > 0 {
fmt.Println("Github webhook received")
return nil, nil
return parseGithubEvent(r, githubEventHeader)
}

// Try Gitlab
Expand Down

0 comments on commit 544168d

Please sign in to comment.