-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
241 additions
and
79 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Package webhook contains Inertia's webhook parsing code | ||
package webhook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package webhook | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"net/http" | ||
) | ||
|
||
// x-github-event header values | ||
var ( | ||
GithubPushHeader = "push" | ||
// GithubPullHeader = "pull" | ||
) | ||
|
||
// GithubPushEvent represents a push to a Github repository | ||
// see https://developer.github.com/v3/activity/events/types/#pushevent | ||
type GithubPushEvent struct { | ||
eventType string | ||
Ref string `json:"ref"` | ||
Repo GithubPushEventRepository `json:"repository"` | ||
} | ||
|
||
// GithubPushEventRepository represents the repository object in a Github PushEvent | ||
// see https://developer.github.com/v3/activity/events/types/#pushevent | ||
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) { | ||
dec := json.NewDecoder(r.Body) | ||
|
||
switch event { | ||
case GithubPushHeader: | ||
payload := GithubPushEvent{eventType: PushEvent} | ||
|
||
if err := dec.Decode(&payload); err != nil { | ||
return nil, errors.New("Error parsing PushEvent") | ||
} | ||
|
||
return payload, nil | ||
default: | ||
return nil, errors.New("Unsupported Github event") | ||
} | ||
} | ||
|
||
// GetEventType returns the event type of the webhook | ||
func (g GithubPushEvent) GetEventType() string { | ||
return g.eventType | ||
} | ||
|
||
// GetRepoName returns the full repo name | ||
func (g GithubPushEvent) GetRepoName() string { | ||
return g.Repo.FullName | ||
} | ||
|
||
// GetRef returns the full ref | ||
func (g GithubPushEvent) GetRef() string { | ||
return g.Ref | ||
} | ||
|
||
// GetGitURL returns the git clone URL | ||
func (g GithubPushEvent) GetGitURL() string { | ||
return g.Repo.GitURL | ||
} | ||
|
||
// GetSSHURL returns the ssh URL | ||
func (g GithubPushEvent) GetSSHURL() string { | ||
return g.Repo.SSHURL | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package webhook | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"net/http" | ||
) | ||
|
||
// x-gitlab-event header values | ||
var ( | ||
GitlabPushHeader = "Push Hook" | ||
) | ||
|
||
// GitlabPushEvent represents a push to a Gitlab repository | ||
// see https://docs.gitlab.com/ee/user/project/integrations/webhooks.html#push-events | ||
type GitlabPushEvent struct { | ||
eventType string | ||
Ref string `json:"ref"` | ||
Repo GitlabPushEventRepository `json:"repository"` | ||
} | ||
|
||
// GitlabPushEventRepository represents the repository object in a Gitlab PushEvent | ||
// see https://docs.gitlab.com/ee/user/project/integrations/webhooks.html#push-events | ||
type GitlabPushEventRepository struct { | ||
Name string `json:"name"` | ||
GitURL string `json:"git_http_url"` | ||
SSHURL string `json:"git_ssh_url"` | ||
} | ||
|
||
func parseGitlabEvent(r *http.Request, event string) (Payload, error) { | ||
dec := json.NewDecoder(r.Body) | ||
|
||
switch event { | ||
case GitlabPushHeader: | ||
payload := GitlabPushEvent{eventType: PushEvent} | ||
|
||
if err := dec.Decode(&payload); err != nil { | ||
return nil, errors.New("Error parsing PushEvent") | ||
} | ||
|
||
return payload, nil | ||
default: | ||
return nil, errors.New("Unsupported Gitlab event") | ||
} | ||
} | ||
|
||
// GetEventType returns the event type of the webhook | ||
func (g GitlabPushEvent) GetEventType() string { | ||
return g.eventType | ||
} | ||
|
||
// GetRepoName returns the repo name | ||
func (g GitlabPushEvent) GetRepoName() string { | ||
return g.Repo.Name | ||
} | ||
|
||
// GetRef returns the full ref | ||
func (g GitlabPushEvent) GetRef() string { | ||
return g.Ref | ||
} | ||
|
||
// GetGitURL returns the git clone URL | ||
func (g GitlabPushEvent) GetGitURL() string { | ||
return g.Repo.GitURL | ||
} | ||
|
||
// GetSSHURL returns the ssh URL | ||
func (g GitlabPushEvent) GetSSHURL() string { | ||
return g.Repo.SSHURL | ||
} |
Oops, something went wrong.