From eaf63ae1d5c8e961c291c916f8288d3107c7602a Mon Sep 17 00:00:00 2001 From: Gusted Date: Mon, 3 Jan 2022 03:04:24 +0100 Subject: [PATCH] Remove unused route - Couldn't find any reference of this route being used. --- routers/web/repo/pull.go | 39 ------------------------------------- routers/web/repo/setting.go | 25 ------------------------ routers/web/web.go | 2 -- 3 files changed, 66 deletions(-) diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 1a6a5e55e611f..37826abfb4bc3 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -7,7 +7,6 @@ package repo import ( - "crypto/subtle" "errors" "fmt" "html" @@ -1208,44 +1207,6 @@ func CompareAndPullRequestPost(ctx *context.Context) { ctx.Redirect(pullIssue.Link()) } -// TriggerTask response for a trigger task request -func TriggerTask(ctx *context.Context) { - pusherID := ctx.FormInt64("pusher") - branch := ctx.FormString("branch") - secret := ctx.FormString("secret") - if len(branch) == 0 || len(secret) == 0 || pusherID <= 0 { - ctx.Error(http.StatusNotFound) - log.Trace("TriggerTask: branch or secret is empty, or pusher ID is not valid") - return - } - owner, repo := parseOwnerAndRepo(ctx) - if ctx.Written() { - return - } - got := []byte(base.EncodeMD5(owner.Salt)) - want := []byte(secret) - if subtle.ConstantTimeCompare(got, want) != 1 { - ctx.Error(http.StatusNotFound) - log.Trace("TriggerTask [%s/%s]: invalid secret", owner.Name, repo.Name) - return - } - - pusher, err := user_model.GetUserByID(pusherID) - if err != nil { - if user_model.IsErrUserNotExist(err) { - ctx.Error(http.StatusNotFound) - } else { - ctx.ServerError("GetUserByID", err) - } - return - } - - log.Trace("TriggerTask '%s/%s' by %s", repo.Name, branch, pusher.Name) - - go pull_service.AddTestPullRequestTask(pusher, repo.ID, branch, true, "", "") - ctx.Status(202) -} - // CleanUpPullRequest responses for delete merged branch when PR has been merged func CleanUpPullRequest(ctx *context.Context) { issue := checkPullInfo(ctx) diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go index 7ff83cc3d76b5..b7269b67186ca 100644 --- a/routers/web/repo/setting.go +++ b/routers/web/repo/setting.go @@ -994,31 +994,6 @@ func DeleteTeam(ctx *context.Context) { }) } -// parseOwnerAndRepo get repos by owner -func parseOwnerAndRepo(ctx *context.Context) (*user_model.User, *repo_model.Repository) { - owner, err := user_model.GetUserByName(ctx.Params(":username")) - if err != nil { - if user_model.IsErrUserNotExist(err) { - ctx.NotFound("GetUserByName", err) - } else { - ctx.ServerError("GetUserByName", err) - } - return nil, nil - } - - repo, err := repo_model.GetRepositoryByName(owner.ID, ctx.Params(":reponame")) - if err != nil { - if repo_model.IsErrRepoNotExist(err) { - ctx.NotFound("GetRepositoryByName", err) - } else { - ctx.ServerError("GetRepositoryByName", err) - } - return nil, nil - } - - return owner, repo -} - // GitHooks hooks of a repository func GitHooks(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.settings.githooks") diff --git a/routers/web/web.go b/routers/web/web.go index 3589ec9bd6637..2796904cee4aa 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1064,8 +1064,6 @@ func RegisterRoutes(m *web.Route) { m.GetOptions("/objects/pack/pack-{file:[0-9a-f]{40}}.pack", repo.GetPackFile) m.GetOptions("/objects/pack/pack-{file:[0-9a-f]{40}}.idx", repo.GetIdxFile) }, ignSignInAndCsrf) - - m.Head("/tasks/trigger", repo.TriggerTask) }) }) // ***** END: Repository *****