From 601e3e6d48b864bad8d3f4fe9b4f2885255dbfe1 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Wed, 22 Oct 2014 00:41:25 -0700 Subject: [PATCH] slightly altered the URL token format --- plugin/remote/gitlab/gitlab.go | 2 +- server/handler/hook.go | 2 +- server/handler/repo.go | 2 +- server/router/router.go | 8 ++++++++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/plugin/remote/gitlab/gitlab.go b/plugin/remote/gitlab/gitlab.go index 86028e646..61423297f 100644 --- a/plugin/remote/gitlab/gitlab.go +++ b/plugin/remote/gitlab/gitlab.go @@ -135,7 +135,7 @@ func (r *Gitlab) Activate(user *model.User, repo *model.Repo, link string) error // append the repo owner / name to the hook url since gitlab // doesn't send this detail in the post-commit hook - link += "&owner=" + repo.Owner + "&name=" + repo.Name + link += "?owner=" + repo.Owner + "&name=" + repo.Name // add the hook return client.AddProjectHook(path, link, true, false, true) diff --git a/server/handler/hook.go b/server/handler/hook.go index f3b18663d..66735fcef 100644 --- a/server/handler/hook.go +++ b/server/handler/hook.go @@ -25,7 +25,7 @@ import ( func PostHook(c web.C, w http.ResponseWriter, r *http.Request) { var ctx = context.FromC(c) var host = c.URLParams["host"] - var token = r.FormValue("token") + var token = c.URLParams["token"] var remote = remote.Lookup(host) if remote == nil { w.WriteHeader(http.StatusNotFound) diff --git a/server/handler/repo.go b/server/handler/repo.go index 54896b9fa..be7662437 100644 --- a/server/handler/repo.go +++ b/server/handler/repo.go @@ -99,7 +99,7 @@ func PostRepo(c web.C, w http.ResponseWriter, r *http.Request) { // setup the post-commit hook with the remote system and // if necessary, register the public key - var hook = fmt.Sprintf("%s/api/hook/%s?token=%s", httputil.GetURL(r), repo.Remote, repo.Token) + var hook = fmt.Sprintf("%s/api/hook/%s/%s", httputil.GetURL(r), repo.Remote, repo.Token) if err := remote.Activate(user, repo, hook); err != nil { w.WriteHeader(http.StatusInternalServerError) return diff --git a/server/router/router.go b/server/router/router.go index ec8bd40b6..418256d19 100644 --- a/server/router/router.go +++ b/server/router/router.go @@ -15,9 +15,17 @@ func New() *web.Mux { mux.Post("/api/auth/:host", handler.GetLogin) mux.Get("/api/badge/:host/:owner/:name/status.svg", handler.GetBadge) mux.Get("/api/badge/:host/:owner/:name/cc.xml", handler.GetCC) + mux.Get("/api/hook/:host/:token", handler.PostHook) + mux.Put("/api/hook/:host/:token", handler.PostHook) + mux.Post("/api/hook/:host/:token", handler.PostHook) + + // these routes are here for backward compatibility + // to help people troubleshoot why their upgrade isn't + // working correctly. remove at some point mux.Get("/api/hook/:host", handler.PostHook) mux.Put("/api/hook/:host", handler.PostHook) mux.Post("/api/hook/:host", handler.PostHook) + //// streams := web.New() streams.Get("/api/stream/stdout/:id", handler.WsConsole)