Skip to content

Commit 35a2b9b

Browse files
committed
Update
1 parent cab9bbc commit 35a2b9b

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

routers/private/hook_pre_receive.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package private
55

66
import (
7+
"errors"
78
"fmt"
89
"net/http"
910
"os"
@@ -472,24 +473,27 @@ func preReceiveFor(ctx *preReceiveContext, refFullName git.RefName) {
472473
}
473474
}
474475

475-
func canUpdateAgitPull(ctx *preReceiveContext, pull *issues_model.PullRequest) bool {
476+
func canUpdateAgitPull(ctx *preReceiveContext, pull *issues_model.PullRequest) error {
476477
if pull.Flow != issues_model.PullRequestFlowAGit {
477-
return false
478+
return errors.New("Pull request that are not created through agit cannot be updated using agit")
478479
}
479480

480481
if ctx.opts.UserID == pull.Issue.PosterID {
481-
return true
482+
return nil
482483
}
483484

484485
if !pull.AllowMaintainerEdit {
485-
return false
486+
return fmt.Errorf("The author does not allow maintainers to edit this pull request")
486487
}
487488

488489
if !ctx.loadPusherAndPermission() {
489-
return false
490+
return fmt.Errorf("Internal Server Error (no specific error)")
490491
}
491492

492-
return ctx.userPerm.CanWrite(unit.TypeCode)
493+
if ctx.userPerm.CanWrite(unit.TypeCode) {
494+
return errors.New("You have no permission to update this pull request")
495+
}
496+
return nil
493497
}
494498

495499
func preReceiveForReview(ctx *preReceiveContext, refFullName git.RefName) {
@@ -535,9 +539,9 @@ func preReceiveForReview(ctx *preReceiveContext, refFullName git.RefName) {
535539
return
536540
}
537541

538-
if !canUpdateAgitPull(ctx, pull) {
542+
if err := canUpdateAgitPull(ctx, pull); err != nil {
539543
ctx.JSON(http.StatusForbidden, private.Response{
540-
UserMsg: "Unknow pull request.",
544+
UserMsg: err.Error(),
541545
})
542546
return
543547
}

services/agit/agit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
137137
})
138138
continue
139139
}
140+
log.Trace("Pull request index: %d", pullIndex)
140141
pull, err := issues_model.GetPullRequestByIndex(ctx, repo.ID, pullIndex)
141142
if err != nil {
142143
results = append(results, private.HookProcReceiveRefResult{

0 commit comments

Comments
 (0)