diff --git a/pkg/vcs/client.go b/pkg/vcs/client.go index b5881fa1..1aeec323 100644 --- a/pkg/vcs/client.go +++ b/pkg/vcs/client.go @@ -9,6 +9,11 @@ import ( "github.com/zapier/kubechecks/pkg/repo" ) +const ( + DefaultVcsUsername = "kubechecks" + DefaultVcsEmail = "kubechecks@zapier.com" +) + var ( // ErrInvalidType is a sentinel error for use in client implementations ErrInvalidType = errors.New("invalid event type") diff --git a/pkg/vcs/github_client/client.go b/pkg/vcs/github_client/client.go index 09b14f99..f7c9ebef 100644 --- a/pkg/vcs/github_client/client.go +++ b/pkg/vcs/github_client/client.go @@ -69,12 +69,26 @@ func CreateGithubClient() (*Client, error) { return nil, errors.Wrap(err, "failed to get user") } - return &Client{ + client := &Client{ Client: googleClient, v4Client: shurcoolClient, - username: *user.Login, - email: *user.Email, - }, nil + } + if user != nil { + if user.Login != nil { + client.username = *user.Login + } + if user.Email != nil { + client.email = *user.Email + } + } + + if client.username == "" { + client.username = vcs.DefaultVcsUsername + } + if client.email == "" { + client.email = vcs.DefaultVcsEmail + } + return client, nil } func (c *Client) Username() string { return c.username } diff --git a/pkg/vcs/gitlab_client/client.go b/pkg/vcs/gitlab_client/client.go index 877562ab..f4dbc15e 100644 --- a/pkg/vcs/gitlab_client/client.go +++ b/pkg/vcs/gitlab_client/client.go @@ -55,7 +55,14 @@ func CreateGitlabClient() (*Client, error) { return nil, errors.Wrap(err, "failed to get current user") } - return &Client{Client: c, username: user.Username, email: user.Email}, nil + client := &Client{Client: c, username: user.Username, email: user.Email} + if client.username == "" { + client.username = vcs.DefaultVcsUsername + } + if client.email == "" { + client.email = vcs.DefaultVcsEmail + } + return client, nil } func (c *Client) Email() string { return c.email }