Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlejandro Rodríguez <alejorro70@gmail.com>2017-01-06 06:00:31 +0300
committerAlejandro Rodríguez <alejorro70@gmail.com>2017-01-11 17:18:21 +0300
commit5c610227aeb10ce18bce08fd640156d65cfe8462 (patch)
tree01a9294ae4ab15f824787d0c49fa9f1484ce7069
parent8ed72a7cff2c6afc7e10196be429fc7dc812485a (diff)
Add handler for post-receive notificationpost-receive-handler
-rw-r--r--handler/post_receive.go10
-rw-r--r--handler/post_receive_test.go30
-rw-r--r--router/router.go1
3 files changed, 41 insertions, 0 deletions
diff --git a/handler/post_receive.go b/handler/post_receive.go
new file mode 100644
index 000000000..e656d1962
--- /dev/null
+++ b/handler/post_receive.go
@@ -0,0 +1,10 @@
+package handler
+
+import (
+ "net/http"
+)
+
+func PostReceive(w http.ResponseWriter, r *http.Request) {
+ // TODO: Invalidate info-refs cache. For now, just return 200
+ w.WriteHeader(http.StatusOK)
+}
diff --git a/handler/post_receive_test.go b/handler/post_receive_test.go
new file mode 100644
index 000000000..b7b5578b4
--- /dev/null
+++ b/handler/post_receive_test.go
@@ -0,0 +1,30 @@
+package handler
+
+import (
+ "bytes"
+ "net/http"
+ "net/http/httptest"
+ "net/url"
+ "strconv"
+ "testing"
+)
+
+func TestGetPostReceive(t *testing.T) {
+ recorder := httptest.NewRecorder()
+ data := url.Values{}
+ data.Set("project", "foo/bar.git")
+ data.Set("changes", "0000000000000000000000000000000000000000 92d0970eefd7acb6d548878925ce2208cfe2d2ec refs/heads/branch4")
+
+ req, err := http.NewRequest("POST", "/post-receive", bytes.NewBufferString(data.Encode()))
+ if err != nil {
+ t.Fatal("Creating 'POST /post-receive' request failed!")
+ }
+ req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
+ req.Header.Add("Content-Length", strconv.Itoa(len(data.Encode())))
+
+ http.HandlerFunc(PostReceive).ServeHTTP(recorder, req)
+
+ if recorder.Code != http.StatusOK {
+ t.Fatal("Server error: Returned ", recorder.Code, " instead of ", http.StatusOK)
+ }
+}
diff --git a/router/router.go b/router/router.go
index 0c929cb21..996fdaac9 100644
--- a/router/router.go
+++ b/router/router.go
@@ -14,6 +14,7 @@ func NewRouter() http.Handler {
r := mux.NewRouter()
r.HandleFunc("/", handler.Home)
+ r.HandleFunc("/post-receive", handler.PostReceive)
return handlers.LoggingHandler(os.Stdout, r)
}