From 4d4defc416d056a0219593856a46f30e1fddef16 Mon Sep 17 00:00:00 2001 From: Brad Date: Sun, 8 Jun 2014 23:59:23 -0700 Subject: [PATCH] re-added code to read/write websocket data. added to amber templates --- server/handler/site.go | 13 ++++++++++++- server/main.go | 5 +++++ server/queue/worker.go | 10 +++++----- server/session/session.go | 8 ++++---- server/static/scripts/commit_updates.js | 1 - server/template/html/repo_branch.html | 6 ++++++ server/template/html/repo_commit.html | 21 ++++++++------------- server/template/html/repo_feed.html | 8 ++++++-- server/template/repo_branch.amber | 8 +++++++- server/template/repo_commit.amber | 20 +++++++------------- server/template/repo_feed.amber | 5 ++++- 11 files changed, 64 insertions(+), 41 deletions(-) diff --git a/server/handler/site.go b/server/handler/site.go index ad05264d4..2e431aa12 100644 --- a/server/handler/site.go +++ b/server/handler/site.go @@ -3,6 +3,7 @@ package handler import ( "net/http" + "github.com/drone/drone/server/channel" "github.com/drone/drone/server/render" "github.com/drone/drone/server/resource/commit" "github.com/drone/drone/server/resource/perm" @@ -94,12 +95,17 @@ func (s *SiteHandler) GetRepo(w http.ResponseWriter, r *http.Request) error { User *user.User Repo *repo.Repo Branch string - Token string + Channel string + Stream string Branches []*commit.Commit Commits []*commit.Commit Commit *commit.Commit }{User: usr, Repo: arepo} + // generate a token for connecting to the streaming server + // to get notified of feed items. + data.Channel = channel.Create(host + "/" + owner + "/" + name + "/") + // if commit details are provided we should retrieve the build details // and serve the build page. if len(sha) != 0 { @@ -107,6 +113,11 @@ func (s *SiteHandler) GetRepo(w http.ResponseWriter, r *http.Request) error { if err != nil { return s.render(w, "404.html", nil) } + + // generate a token for connecting to the streaming server + // to get notified of feed items. + data.Stream = channel.Create(host + "/" + owner + "/" + name + "/" + branch + "/" + sha) + return s.render(w, "repo_commit.html", &data) } diff --git a/server/main.go b/server/main.go index 8c868eb0c..318575f5f 100644 --- a/server/main.go +++ b/server/main.go @@ -6,6 +6,8 @@ import ( "html/template" "net/http" + "code.google.com/p/go.net/websocket" + "github.com/drone/drone/server/channel" "github.com/drone/drone/server/database" "github.com/drone/drone/server/handler" "github.com/drone/drone/server/render" @@ -93,6 +95,9 @@ func main() { // TODO we need to replace this with go.rice http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) + // server websocket data + http.Handle("/feed", websocket.Handler(channel.Read)) + // register the router // TODO we disabled nosurf because it was impacting API calls. // we need to disable nosurf for api calls (ie not coming from website). diff --git a/server/queue/worker.go b/server/queue/worker.go index 2aa5de709..58b752d33 100644 --- a/server/queue/worker.go +++ b/server/queue/worker.go @@ -85,15 +85,15 @@ func (w *worker) execute(task *BuildTask) error { // make sure a channel exists for the repository, // the commit, and the commit output (TODO) reposlug := fmt.Sprintf("%s/%s/%s", task.Repo.Host, task.Repo.Owner, task.Repo.Name) - commitslug := fmt.Sprintf("%s/%s/%s/commit/%s/%s", task.Repo.Host, task.Repo.Owner, task.Repo.Name, task.Commit.Branch, task.Commit.Sha) - consoleslug := fmt.Sprintf("%s/%s/%s/commit/%s/%s/console", task.Repo.Host, task.Repo.Owner, task.Repo.Name, task.Commit.Branch, task.Commit.Sha) + //commitslug := fmt.Sprintf("%s/%s/%s/%s/%s", task.Repo.Host, task.Repo.Owner, task.Repo.Name, task.Commit.Branch, task.Commit.Sha) + consoleslug := fmt.Sprintf("%s/%s/%s/%s/%s", task.Repo.Host, task.Repo.Owner, task.Repo.Name, task.Commit.Branch, task.Commit.Sha) channel.Create(reposlug) - channel.Create(commitslug) + //channel.Create(commitslug) channel.CreateStream(consoleslug) // notify the channels that the commit and build started channel.SendJSON(reposlug, task.Commit) - channel.SendJSON(commitslug, task.Commit) + //channel.SendJSON(commitslug, task.Commit) var buf = &bufferWrapper{channel: consoleslug} @@ -145,7 +145,7 @@ func (w *worker) execute(task *BuildTask) error { // notify the channels that the commit and build finished channel.SendJSON(reposlug, task.Commit) - channel.SendJSON(commitslug, task.Commit) + //channel.SendJSON(commitslug, task.Commit) channel.Close(consoleslug) // send all "finished" notifications diff --git a/server/session/session.go b/server/session/session.go index 9bb61445f..458dc2158 100644 --- a/server/session/session.go +++ b/server/session/session.go @@ -32,10 +32,10 @@ func NewSession(users user.UserManager) Session { // User gets the currently authenticated user from the secure cookie session. func (s *session) User(r *http.Request) *user.User { - if true { - user, _ := s.users.Find(1) - return user - } + //if true { + // user, _ := s.users.Find(1) + // return user + //} switch { case r.FormValue("access_token") == "": diff --git a/server/static/scripts/commit_updates.js b/server/static/scripts/commit_updates.js index 6493f3550..d8fd83fd7 100644 --- a/server/static/scripts/commit_updates.js +++ b/server/static/scripts/commit_updates.js @@ -76,7 +76,6 @@ if(typeof(Drone) === 'undefined') { Drone = {}; } onClose: function(e) { console.log('output websocket closed: ' + JSON.stringify(e)); - window.location.reload(); } }; diff --git a/server/template/html/repo_branch.html b/server/template/html/repo_branch.html index 9edbb7f25..aa5d06ab8 100644 --- a/server/template/html/repo_branch.html +++ b/server/template/html/repo_branch.html @@ -73,5 +73,11 @@ $(".timeago").timeago(); }); + diff --git a/server/template/html/repo_commit.html b/server/template/html/repo_commit.html index 0b5a52c13..28b530498 100644 --- a/server/template/html/repo_commit.html +++ b/server/template/html/repo_commit.html @@ -80,23 +80,18 @@ $(".timeago").timeago(); }); {{$__amber_38 := .Build.Status}}{{$__amber_39 := __amber_eql $__amber_38 "Pending"}}{{$__amber_40 := .Build.Status}}{{$__amber_41 := __amber_eql $__amber_40 "Started"}}{{$__amber_42 := or $__amber_41 $__amber_39}}{{if $__amber_42}} + {{else}} {{$__amber_50 := .Repo.Active}}{{if $__amber_50}} - {{else}} + {{else}}