diff --git a/pkg/handler/commits.go b/pkg/handler/commits.go index 5ac30cf11..15f82bc87 100644 --- a/pkg/handler/commits.go +++ b/pkg/handler/commits.go @@ -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) diff --git a/pkg/model/settings.go b/pkg/model/settings.go index 3112d1d4b..e794fbd9e 100644 --- a/pkg/model/settings.go +++ b/pkg/model/settings.go @@ -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 + } +}