diff --git a/routers/private/hook_pre_receive.go b/routers/private/hook_pre_receive.go index 8c2c97590f..41bd1f2931 100644 --- a/routers/private/hook_pre_receive.go +++ b/routers/private/hook_pre_receive.go @@ -4,6 +4,7 @@ package private import ( + "errors" "fmt" "net/http" "os" @@ -472,24 +473,27 @@ func preReceiveFor(ctx *preReceiveContext, refFullName git.RefName) { } } -func canUpdateAgitPull(ctx *preReceiveContext, pull *issues_model.PullRequest) bool { +func canUpdateAgitPull(ctx *preReceiveContext, pull *issues_model.PullRequest) error { if pull.Flow != issues_model.PullRequestFlowAGit { - return false + return errors.New("Pull request that are not created through agit cannot be updated using agit") } if ctx.opts.UserID == pull.Issue.PosterID { - return true + return nil } if !pull.AllowMaintainerEdit { - return false + return fmt.Errorf("The author does not allow maintainers to edit this pull request") } if !ctx.loadPusherAndPermission() { - return false + return fmt.Errorf("Internal Server Error (no specific error)") } - return ctx.userPerm.CanWrite(unit.TypeCode) + if ctx.userPerm.CanWrite(unit.TypeCode) { + return errors.New("You have no permission to update this pull request") + } + return nil } func preReceiveForReview(ctx *preReceiveContext, refFullName git.RefName) { @@ -535,9 +539,9 @@ func preReceiveForReview(ctx *preReceiveContext, refFullName git.RefName) { return } - if !canUpdateAgitPull(ctx, pull) { + if err := canUpdateAgitPull(ctx, pull); err != nil { ctx.JSON(http.StatusForbidden, private.Response{ - UserMsg: "Unknow pull request.", + UserMsg: err.Error(), }) return } diff --git a/services/agit/agit.go b/services/agit/agit.go index dcfb2ea6a2..9f6d85d5e4 100644 --- a/services/agit/agit.go +++ b/services/agit/agit.go @@ -137,6 +137,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git. }) continue } + log.Trace("Pull request index: %d", pullIndex) pull, err := issues_model.GetPullRequestByIndex(ctx, repo.ID, pullIndex) if err != nil { results = append(results, private.HookProcReceiveRefResult{