From 3d0583df0f1704bc0e1c0d1348f2054515680fed Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sat, 8 Aug 2015 01:04:12 +0800 Subject: [PATCH] fix private repo cannot trigger hook by SSH --- cmd/web.go | 6 ++++-- gogs.go | 2 +- routers/repo/setting.go | 21 ++++++++++++++++++++- templates/.VERSION | 2 +- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/cmd/web.go b/cmd/web.go index 9e35698a4d..708ff59e70 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -461,7 +461,6 @@ func runWeb(ctx *cli.Context) { m.Get("/branches", repo.Branches) m.Get("/archive/*", repo.Download) m.Get("/pulls2/", repo.PullRequest2) - m.Head("/hooks/trigger", repo.TriggerHook) m.Group("", func() { m.Get("/src/*", repo.Home) @@ -479,7 +478,10 @@ func runWeb(ctx *cli.Context) { m.Get(".git", repo.Home) }, ignSignIn, middleware.RepoAssignment(true, true), middleware.RepoRef()) - m.Any("/:reponame/*", ignSignInAndCsrf, repo.Http) + m.Group("/:reponame", func() { + m.Any("/*", ignSignInAndCsrf, repo.Http) + m.Head("/hooks/trigger", repo.TriggerHook) + }) }) // robots.txt diff --git a/gogs.go b/gogs.go index 3ceb3001cd..ad52f2552c 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.6.4.0806 Beta" +const APP_VER = "0.6.4.0808 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 8f6ef1787b..05881a67ef 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -586,7 +586,26 @@ func getOrgRepoCtx(ctx *middleware.Context) (*OrgRepoCtx, error) { } func TriggerHook(ctx *middleware.Context) { - models.HookQueue.AddRepoID(ctx.Repo.Repository.Id) + u, err := models.GetUserByName(ctx.Params(":username")) + if err != nil { + if models.IsErrUserNotExist(err) { + ctx.Handle(404, "GetUserByName", err) + } else { + ctx.Handle(500, "GetUserByName", err) + } + return + } + + repo, err := models.GetRepositoryByName(u.Id, ctx.Params(":reponame")) + if err != nil { + if models.IsErrRepoNotExist(err) { + ctx.Handle(404, "GetRepositoryByName", err) + } else { + ctx.Handle(500, "GetRepositoryByName", err) + } + return + } + models.HookQueue.AddRepoID(repo.Id) } func GitHooks(ctx *middleware.Context) { diff --git a/templates/.VERSION b/templates/.VERSION index 8a54eae634..1fd1eb7418 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.6.4.0806 Beta \ No newline at end of file +0.6.4.0808 Beta \ No newline at end of file