Remove unused route "/tasks/trigger" (#18160)

ref: https://github.com/go-gitea/gitea/pull/18160#issuecomment-1004091325
This commit is contained in:
Gusted 2022-01-03 17:23:43 +00:00 committed by GitHub
parent 48aab263d1
commit 650a50a7ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 0 additions and 66 deletions

View File

@ -7,7 +7,6 @@
package repo package repo
import ( import (
"crypto/subtle"
"errors" "errors"
"fmt" "fmt"
"html" "html"
@ -1208,44 +1207,6 @@ func CompareAndPullRequestPost(ctx *context.Context) {
ctx.Redirect(pullIssue.Link()) 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 // CleanUpPullRequest responses for delete merged branch when PR has been merged
func CleanUpPullRequest(ctx *context.Context) { func CleanUpPullRequest(ctx *context.Context) {
issue := checkPullInfo(ctx) issue := checkPullInfo(ctx)

View File

@ -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 // GitHooks hooks of a repository
func GitHooks(ctx *context.Context) { func GitHooks(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings.githooks") ctx.Data["Title"] = ctx.Tr("repo.settings.githooks")

View File

@ -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}}.pack", repo.GetPackFile)
m.GetOptions("/objects/pack/pack-{file:[0-9a-f]{40}}.idx", repo.GetIdxFile) m.GetOptions("/objects/pack/pack-{file:[0-9a-f]{40}}.idx", repo.GetIdxFile)
}, ignSignInAndCsrf) }, ignSignInAndCsrf)
m.Head("/tasks/trigger", repo.TriggerTask)
}) })
}) })
// ***** END: Repository ***** // ***** END: Repository *****