Skip to content

Commit

Permalink
Remove unused route "/tasks/trigger" (#18160)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gusted authored Jan 3, 2022
1 parent 48aab26 commit 650a50a
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 66 deletions.
39 changes: 0 additions & 39 deletions routers/web/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package repo

import (
"crypto/subtle"
"errors"
"fmt"
"html"
Expand Down Expand Up @@ -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)
Expand Down
25 changes: 0 additions & 25 deletions routers/web/repo/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 0 additions & 2 deletions routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 *****
Expand Down

0 comments on commit 650a50a

Please sign in to comment.