1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-11-24 08:02:18 +02:00

added validation for settings

This commit is contained in:
Brad Rydzewski 2014-02-21 15:25:05 -07:00
parent 3c25a4a00a
commit 6410bdbe9d
2 changed files with 18 additions and 2 deletions

View File

@ -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)

View File

@ -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
}
}