added validation for settings
This commit is contained in:
parent
3c25a4a00a
commit
6410bdbe9d
2 changed files with 18 additions and 2 deletions
|
@ -48,8 +48,8 @@ func CommitShow(w http.ResponseWriter, r *http.Request, u *User, repo *Repo) err
|
|||
|
||||
// generate a token to connect with the websocket
|
||||
// handler and stream output, if the build is running.
|
||||
data.Token = channel.CreateStream(fmt.Sprintf(
|
||||
"%s/commit/%s/builds/%s", repo.Slug, commit.Hash, builds[0].Slug))
|
||||
data.Token = channel.Token(fmt.Sprintf(
|
||||
"%s/%s/%s/commit/%s/builds/%s", repo.Host, repo.Owner, repo.Name, commit.Hash, builds[0].Slug))
|
||||
|
||||
// render the repository template.
|
||||
return RenderTemplate(w, "repo_commit.html", &data)
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrInvalidGitHubTrailingSlash = errors.New("GitHub URL should not have a trailing slash")
|
||||
)
|
||||
|
||||
type Settings struct {
|
||||
|
@ -38,3 +44,13 @@ func (s *Settings) URL() *url.URL {
|
|||
Scheme: s.Scheme,
|
||||
Host: s.Domain}
|
||||
}
|
||||
|
||||
// Validate verifies all required fields are correctly populated.
|
||||
func (s *Settings) Validate() error {
|
||||
switch {
|
||||
case strings.HasSuffix(s.GitHubApiUrl, "/"):
|
||||
return ErrInvalidGitHubTrailingSlash
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue