Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions internal/validate/install/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ type Insight struct {
DeleteWhenDone bool `yaml:"deleteWhenDone"`
}

type Smtp struct {
Enabled bool `yaml:"enabled"`
To string `yaml:"to"`
}

type ValidationSpec struct {
// Search queries used for validation testing, e.g. "repo:^github\\.com/gorilla/mux$ Router".
SearchQuery []string `yaml:"searchQuery"`
Expand All @@ -61,6 +66,9 @@ type ValidationSpec struct {

// Insight used for validation testing.
Insight Insight `yaml:"insight"`

//Test SMTP configuration
Smtp Smtp `yaml:"smtp"`
}

// DefaultConfig returns a default configuration to be used for testing.
Expand Down Expand Up @@ -108,6 +116,10 @@ func DefaultConfig() *ValidationSpec {
},
DeleteWhenDone: true,
},
Smtp: Smtp{
Enabled: false,
To: "example@domain.com",
},
}
}

Expand Down
38 changes: 38 additions & 0 deletions internal/validate/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,23 @@ func Validate(ctx context.Context, client api.Client, config *ValidationSpec) er
}
}

if config.Smtp.Enabled {
log.Printf("%s validating smtp connection", validate.EmojiFingerPointRight)

smtpQuery := `mutation sendTestEmail($to: String!) {
sendTestEmail(to: $to)
}`
smtpVars := map[string]interface{}{
"to": config.Smtp.To,
}

result, err := checkSmtp(ctx, client, smtpQuery, smtpVars)
if err != nil {
return err
}
log.Printf("%s '%s'", validate.SuccessEmoji, result)
}

if config.Insight.Title != "" {
log.Printf("%s validating code insight", validate.EmojiFingerPointRight)

Expand Down Expand Up @@ -130,6 +147,27 @@ func searchMatchCount(ctx context.Context, client api.Client, searchExpr string)
return result.Search.Results.MatchCount, nil
}

func checkSmtp(ctx context.Context, client api.Client, query string, variables map[string]interface{}) (string, error) {
q := clientQuery{
opName: "CheckSmtpConfig",
query: query,
variables: variables,
}

var result struct {
SendTestEmail string `json:"sendTestEmail"`
}

ok, err := client.NewRequest(q.query, q.variables).Do(ctx, &result)
if err != nil {
return "", errors.Wrap(err, "sendTestEmail failed")
}
if !ok {
return "", errors.New("sendTestEmail failed, no data to unmarshal")
}
return result.SendTestEmail, nil
}

func repoCloneTimeout(ctx context.Context, client api.Client, repo string, srv ExternalService) (bool, error) {
for i := 0; i < srv.MaxRetries; i++ {
repos, err := listClonedRepos(ctx, client, []string{repo})
Expand Down