From 70d2872ff23cb6b0668a44a0bd9111355f14d807 Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Tue, 4 Jun 2024 13:07:45 +0000 Subject: [PATCH 01/11] agit flow add refs/for-review/ support Signed-off-by: a1012112796 <1012112796@qq.com> --- cmd/serv.go | 3 +- modules/git/git.go | 6 + modules/git/ref.go | 9 +- modules/private/manager.go | 23 +++ routers/private/hook_pre_receive.go | 75 ++++++++ routers/web/misc/misc.go | 2 +- services/agit/agit.go | 164 +++++++++++------- services/pull/edits.go | 5 + .../repo/issue/view_content/sidebar.tmpl | 2 +- tests/integration/git_test.go | 42 +++++ 10 files changed, 265 insertions(+), 66 deletions(-) diff --git a/cmd/serv.go b/cmd/serv.go index 2bfd1110617e5..b3b9cac0c592d 100644 --- a/cmd/serv.go +++ b/cmd/serv.go @@ -181,7 +181,8 @@ func runServ(c *cli.Context) error { if git.DefaultFeatures().SupportProcReceive { // for AGit Flow if cmd == "ssh_info" { - fmt.Print(`{"type":"gitea","version":1}`) + data := private.GetSshInfo(ctx) + fmt.Print(data) return nil } } diff --git a/modules/git/git.go b/modules/git/git.go index 05ca260855535..b2bfea88acee3 100644 --- a/modules/git/git.go +++ b/modules/git/git.go @@ -259,10 +259,16 @@ func syncGitConfig() (err error) { if err := configAddNonExist("receive.procReceiveRefs", "refs/for"); err != nil { return err } + if err := configAddNonExist("receive.procReceiveRefs", "refs/for-review"); err != nil { + return err + } } else { if err := configUnsetAll("receive.procReceiveRefs", "refs/for"); err != nil { return err } + if err := configUnsetAll("receive.procReceiveRefs", "refs/for-review"); err != nil { + return err + } } // Due to CVE-2022-24765, git now denies access to git directories which are not owned by current user. diff --git a/modules/git/ref.go b/modules/git/ref.go index 2db630e2ea9ad..3ebcdfe359a84 100644 --- a/modules/git/ref.go +++ b/modules/git/ref.go @@ -67,7 +67,8 @@ func (ref *Reference) RefGroup() string { // or refs/for/ -o topic='' const ForPrefix = "refs/for/" -// TODO: /refs/for-review for suggest change interface +// ForReviewPrefix special ref to update a pull request: refs/for-review/ +const ForReviewPrefix = "refs/for-review/" // RefName represents a full git reference name type RefName string @@ -104,6 +105,12 @@ func (ref RefName) IsFor() bool { return strings.HasPrefix(string(ref), ForPrefix) } +var forReviewPattern = regexp.MustCompile(ForReviewPrefix + `[1-9][0-9]*`) + +func (ref RefName) IsForReview() bool { + return forReviewPattern.MatchString(string(ref)) +} + func (ref RefName) nameWithoutPrefix(prefix string) string { if strings.HasPrefix(string(ref), prefix) { return strings.TrimPrefix(string(ref), prefix) diff --git a/modules/private/manager.go b/modules/private/manager.go index 6055e553bd0f0..66709acea0cf8 100644 --- a/modules/private/manager.go +++ b/modules/private/manager.go @@ -36,6 +36,29 @@ func ReloadTemplates(ctx context.Context) ResponseExtra { return requestJSONClientMsg(req, "Reloaded") } +// Shutdown calls the internal shutdown function +func GetSshInfo(ctx context.Context) string { + reqURL := setting.LocalURL + "ssh_info" + req := newInternalRequest(ctx, reqURL, "GET") + + resp, err := req.Response() + if err != nil { + return "" + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + return "" + } + + content, err := io.ReadAll(resp.Body) + if err != nil { + return "" + } + + return string(content) +} + // FlushOptions represents the options for the flush call type FlushOptions struct { Timeout time.Duration diff --git a/routers/private/hook_pre_receive.go b/routers/private/hook_pre_receive.go index 0a3c8e2559afa..7ed8de6497647 100644 --- a/routers/private/hook_pre_receive.go +++ b/routers/private/hook_pre_receive.go @@ -7,6 +7,8 @@ import ( "fmt" "net/http" "os" + "strconv" + "strings" "code.gitea.io/gitea/models" asymkey_model "code.gitea.io/gitea/models/asymkey" @@ -124,6 +126,8 @@ func HookPreReceive(ctx *gitea_context.PrivateContext) { preReceiveTag(ourCtx, refFullName) case git.DefaultFeatures().SupportProcReceive && refFullName.IsFor(): preReceiveFor(ourCtx, refFullName) + case git.DefaultFeatures().SupportProcReceive && refFullName.IsForReview(): + preReceiveForReview(ourCtx, refFullName) default: ourCtx.AssertCanWriteCode() } @@ -447,6 +451,77 @@ func preReceiveFor(ctx *preReceiveContext, refFullName git.RefName) { } } +func canUpdateAgitPull(ctx *preReceiveContext, pull *issues_model.PullRequest) bool { + if pull.Flow != issues_model.PullRequestFlowAGit { + return false + } + + if ctx.opts.UserID == pull.Issue.PosterID { + return true + } + + if !pull.AllowMaintainerEdit { + return false + } + + if !ctx.loadPusherAndPermission() { + return false + } + + return ctx.userPerm.CanWrite(unit.TypeCode) +} + +func preReceiveForReview(ctx *preReceiveContext, refFullName git.RefName) { + if !ctx.AssertCreatePullRequest() { + return + } + + if ctx.Repo.Repository.IsEmpty { + ctx.JSON(http.StatusForbidden, private.Response{ + UserMsg: "Can't create pull request for an empty repository.", + }) + return + } + + if ctx.opts.IsWiki { + ctx.JSON(http.StatusForbidden, private.Response{ + UserMsg: "Pull requests are not supported on the wiki.", + }) + return + } + + pullIndex, err := strconv.ParseInt(strings.TrimPrefix(string(refFullName), git.ForReviewPrefix), 10, 64) + if err != nil { + ctx.JSON(http.StatusForbidden, private.Response{ + UserMsg: "Unknow pull request index.", + }) + return + } + pull, err := issues_model.GetPullRequestByIndex(ctx, ctx.Repo.Repository.ID, pullIndex) + if err != nil { + log.Error("preReceiveForReview: GetPullRequestByIndex: err: %v", err) + ctx.JSON(http.StatusForbidden, private.Response{ + UserMsg: "Unknow pull request index.", + }) + return + } + err = pull.LoadIssue(ctx) + if err != nil { + log.Error("preReceiveForReview: pull.LoadIssue: err: %v", err) + ctx.JSON(http.StatusForbidden, private.Response{ + UserMsg: "Unknow pull request.", + }) + return + } + + if !canUpdateAgitPull(ctx, pull) { + ctx.JSON(http.StatusForbidden, private.Response{ + UserMsg: "Unknow pull request.", + }) + return + } +} + func generateGitEnv(opts *private.HookOptions) (env []string) { env = os.Environ() if opts.GitAlternativeObjectDirectories != "" { diff --git a/routers/web/misc/misc.go b/routers/web/misc/misc.go index caaca7f5211c8..8cfbb078d65ed 100644 --- a/routers/web/misc/misc.go +++ b/routers/web/misc/misc.go @@ -20,7 +20,7 @@ func SSHInfo(rw http.ResponseWriter, req *http.Request) { return } rw.Header().Set("content-type", "text/json;charset=UTF-8") - _, err := rw.Write([]byte(`{"type":"gitea","version":1}`)) + _, err := rw.Write([]byte(`{"type":"gitea","version":2}`)) if err != nil { log.Error("fail to write result: err: %v", err) rw.WriteHeader(http.StatusInternalServerError) diff --git a/services/agit/agit.go b/services/agit/agit.go index 52a70469e0c0f..6e6d5157c0a5c 100644 --- a/services/agit/agit.go +++ b/services/agit/agit.go @@ -36,6 +36,75 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git. return nil, fmt.Errorf("failed to get user. Error: %w", err) } + updateExistPull := func(pr *issues_model.PullRequest, i int) error { + // update exist pull request + if err := pr.LoadBaseRepo(ctx); err != nil { + return fmt.Errorf("unable to load base repository for PR[%d] Error: %w", pr.ID, err) + } + + oldCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName()) + if err != nil { + return fmt.Errorf("unable to get ref commit id in base repository for PR[%d] Error: %w", pr.ID, err) + } + + if oldCommitID == opts.NewCommitIDs[i] { + results = append(results, private.HookProcReceiveRefResult{ + OriginalRef: opts.RefFullNames[i], + OldOID: opts.OldCommitIDs[i], + NewOID: opts.NewCommitIDs[i], + Err: "new commit is same with old commit", + }) + return nil + } + + if !forcePush { + output, _, err := git.NewCommand(ctx, "rev-list", "--max-count=1"). + AddDynamicArguments(oldCommitID, "^"+opts.NewCommitIDs[i]). + RunStdString(&git.RunOpts{Dir: repo.RepoPath(), Env: os.Environ()}) + if err != nil { + return fmt.Errorf("failed to detect force push: %w", err) + } else if len(output) > 0 { + results = append(results, private.HookProcReceiveRefResult{ + OriginalRef: opts.RefFullNames[i], + OldOID: opts.OldCommitIDs[i], + NewOID: opts.NewCommitIDs[i], + Err: "request `force-push` push option", + }) + return nil + } + } + + pr.HeadCommitID = opts.NewCommitIDs[i] + if err = pull_service.UpdateRef(ctx, pr); err != nil { + return fmt.Errorf("failed to update pull ref. Error: %w", err) + } + + pull_service.AddToTaskQueue(ctx, pr) + err = pr.LoadIssue(ctx) + if err != nil { + return fmt.Errorf("failed to load pull issue. Error: %w", err) + } + comment, err := pull_service.CreatePushPullComment(ctx, pusher, pr, oldCommitID, opts.NewCommitIDs[i]) + if err == nil && comment != nil { + notify_service.PullRequestPushCommits(ctx, pusher, pr, comment) + } + notify_service.PullRequestSynchronized(ctx, pusher, pr) + isForcePush := comment != nil && comment.IsForcePush + + results = append(results, private.HookProcReceiveRefResult{ + OldOID: oldCommitID, + NewOID: opts.NewCommitIDs[i], + Ref: pr.GetGitRefName(), + OriginalRef: opts.RefFullNames[i], + IsForcePush: isForcePush, + IsCreatePR: false, + URL: fmt.Sprintf("%s/pulls/%d", repo.HTMLURL(), pr.Index), + ShouldShowMessage: setting.Git.PullRequestPushMessage && repo.AllowsPulls(ctx), + }) + + return nil + } + for i := range opts.OldCommitIDs { if opts.NewCommitIDs[i] == objectFormat.EmptyObjectID().String() { results = append(results, private.HookProcReceiveRefResult{ @@ -47,6 +116,37 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git. continue } + if opts.RefFullNames[i].IsForReview() { + // try match refs/for-review/ + pullIndex, err := strconv.ParseInt(strings.TrimPrefix(string(opts.RefFullNames[i]), git.ForReviewPrefix), 10, 64) + if err != nil { + results = append(results, private.HookProcReceiveRefResult{ + OriginalRef: opts.RefFullNames[i], + OldOID: opts.OldCommitIDs[i], + NewOID: opts.NewCommitIDs[i], + Err: "Unknow pull request index", + }) + continue + } + pull, err := issues_model.GetPullRequestByIndex(ctx, repo.ID, pullIndex) + if err != nil { + results = append(results, private.HookProcReceiveRefResult{ + OriginalRef: opts.RefFullNames[i], + OldOID: opts.OldCommitIDs[i], + NewOID: opts.NewCommitIDs[i], + Err: "Unknow pull request index", + }) + continue + } + + err = updateExistPull(pull, i) + if err != nil { + return nil, err + } + + continue + } + if !opts.RefFullNames[i].IsFor() { results = append(results, private.HookProcReceiveRefResult{ IsNotMatched: true, @@ -158,70 +258,10 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git. continue } - // update exist pull request - if err := pr.LoadBaseRepo(ctx); err != nil { - return nil, fmt.Errorf("unable to load base repository for PR[%d] Error: %w", pr.ID, err) - } - - oldCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName()) - if err != nil { - return nil, fmt.Errorf("unable to get ref commit id in base repository for PR[%d] Error: %w", pr.ID, err) - } - - if oldCommitID == opts.NewCommitIDs[i] { - results = append(results, private.HookProcReceiveRefResult{ - OriginalRef: opts.RefFullNames[i], - OldOID: opts.OldCommitIDs[i], - NewOID: opts.NewCommitIDs[i], - Err: "new commit is same with old commit", - }) - continue - } - - if !forcePush { - output, _, err := git.NewCommand(ctx, "rev-list", "--max-count=1"). - AddDynamicArguments(oldCommitID, "^"+opts.NewCommitIDs[i]). - RunStdString(&git.RunOpts{Dir: repo.RepoPath(), Env: os.Environ()}) - if err != nil { - return nil, fmt.Errorf("failed to detect force push: %w", err) - } else if len(output) > 0 { - results = append(results, private.HookProcReceiveRefResult{ - OriginalRef: opts.RefFullNames[i], - OldOID: opts.OldCommitIDs[i], - NewOID: opts.NewCommitIDs[i], - Err: "request `force-push` push option", - }) - continue - } - } - - pr.HeadCommitID = opts.NewCommitIDs[i] - if err = pull_service.UpdateRef(ctx, pr); err != nil { - return nil, fmt.Errorf("failed to update pull ref. Error: %w", err) - } - - pull_service.AddToTaskQueue(ctx, pr) - err = pr.LoadIssue(ctx) + err = updateExistPull(pr, i) if err != nil { - return nil, fmt.Errorf("failed to load pull issue. Error: %w", err) + return nil, err } - comment, err := pull_service.CreatePushPullComment(ctx, pusher, pr, oldCommitID, opts.NewCommitIDs[i]) - if err == nil && comment != nil { - notify_service.PullRequestPushCommits(ctx, pusher, pr, comment) - } - notify_service.PullRequestSynchronized(ctx, pusher, pr) - isForcePush := comment != nil && comment.IsForcePush - - results = append(results, private.HookProcReceiveRefResult{ - OldOID: oldCommitID, - NewOID: opts.NewCommitIDs[i], - Ref: pr.GetGitRefName(), - OriginalRef: opts.RefFullNames[i], - IsForcePush: isForcePush, - IsCreatePR: false, - URL: fmt.Sprintf("%s/pulls/%d", repo.HTMLURL(), pr.Index), - ShouldShowMessage: setting.Git.PullRequestPushMessage && repo.AllowsPulls(ctx), - }) } return results, nil diff --git a/services/pull/edits.go b/services/pull/edits.go index c7550dcb07394..368092b5fa2ed 100644 --- a/services/pull/edits.go +++ b/services/pull/edits.go @@ -22,6 +22,11 @@ func SetAllowEdits(ctx context.Context, doer *user_model.User, pr *issues_model. return ErrUserHasNoPermissionForAction } + if doer.ID == pr.Issue.PosterID { + pr.AllowMaintainerEdit = allow + return issues_model.UpdateAllowEdits(ctx, pr) + } + if err := pr.LoadHeadRepo(ctx); err != nil { return err } diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index bb0bb2cff3602..60621730da0c0 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -674,7 +674,7 @@ {{end}} {{if and .Issue.IsPull .IsIssuePoster (not .Issue.IsClosed) .Issue.PullRequest.HeadRepo}} - {{if and (not (eq .Issue.PullRequest.HeadRepo.FullName .Issue.PullRequest.BaseRepo.FullName)) .CanWriteToHeadRepo}} + {{if or (eq .SignedUserID .Issue.PosterID) (and (not (eq .Issue.PullRequest.HeadRepo.FullName .Issue.PullRequest.BaseRepo.FullName)) .CanWriteToHeadRepo)}}
Date: Wed, 5 Jun 2024 00:31:22 +0000 Subject: [PATCH 02/11] fix lint Signed-off-by: a1012112796 <1012112796@qq.com> --- cmd/serv.go | 2 +- modules/private/manager.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/serv.go b/cmd/serv.go index b3b9cac0c592d..9640ee03599f7 100644 --- a/cmd/serv.go +++ b/cmd/serv.go @@ -181,7 +181,7 @@ func runServ(c *cli.Context) error { if git.DefaultFeatures().SupportProcReceive { // for AGit Flow if cmd == "ssh_info" { - data := private.GetSshInfo(ctx) + data := private.GetSSHInfo(ctx) fmt.Print(data) return nil } diff --git a/modules/private/manager.go b/modules/private/manager.go index 66709acea0cf8..e2c607bc96b95 100644 --- a/modules/private/manager.go +++ b/modules/private/manager.go @@ -37,7 +37,7 @@ func ReloadTemplates(ctx context.Context) ResponseExtra { } // Shutdown calls the internal shutdown function -func GetSshInfo(ctx context.Context) string { +func GetSSHInfo(ctx context.Context) string { reqURL := setting.LocalURL + "ssh_info" req := newInternalRequest(ctx, reqURL, "GET") From e371a21b956fc74342fba7a508e020bd5a4dfa6b Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Wed, 9 Oct 2024 18:37:00 +0800 Subject: [PATCH 03/11] split updateExistPull Signed-off-by: a1012112796 <1012112796@qq.com> --- services/agit/agit.go | 173 +++++++++++++++++++++++++----------------- 1 file changed, 102 insertions(+), 71 deletions(-) diff --git a/services/agit/agit.go b/services/agit/agit.go index 6e6d5157c0a5c..f3a65cb12cb7d 100644 --- a/services/agit/agit.go +++ b/services/agit/agit.go @@ -21,6 +21,84 @@ import ( pull_service "code.gitea.io/gitea/services/pull" ) +type updateExistPullOption struct { + ctx context.Context + pr *issues_model.PullRequest + gitRepo *git.Repository + repo *repo_model.Repository + forcePush bool + pusher *user_model.User + + RefFullName git.RefName + OldCommitID string + NewCommitID string +} + +func updateExistPull(opts *updateExistPullOption) (*private.HookProcReceiveRefResult, error) { + // update exist pull request + if err := opts.pr.LoadBaseRepo(opts.ctx); err != nil { + return nil, fmt.Errorf("unable to load base repository for PR[%d] Error: %w", opts.pr.ID, err) + } + + oldCommitID, err := opts.gitRepo.GetRefCommitID(opts.pr.GetGitRefName()) + if err != nil { + return nil, fmt.Errorf("unable to get ref commit id in base repository for PR[%d] Error: %w", opts.pr.ID, err) + } + + if oldCommitID == opts.NewCommitID { + return &private.HookProcReceiveRefResult{ + OriginalRef: opts.RefFullName, + OldOID: opts.OldCommitID, + NewOID: opts.NewCommitID, + Err: "new commit is same with old commit", + }, nil + } + + if !opts.forcePush { + output, _, err := git.NewCommand(opts.ctx, "rev-list", "--max-count=1"). + AddDynamicArguments(oldCommitID, "^"+opts.NewCommitID). + RunStdString(&git.RunOpts{Dir: opts.repo.RepoPath(), Env: os.Environ()}) + if err != nil { + return nil, fmt.Errorf("failed to detect force push: %w", err) + } else if len(output) > 0 { + return &private.HookProcReceiveRefResult{ + OriginalRef: opts.RefFullName, + OldOID: opts.OldCommitID, + NewOID: opts.NewCommitID, + Err: "request `force-push` push option", + }, nil + } + } + + opts.pr.HeadCommitID = opts.NewCommitID + if err = pull_service.UpdateRef(opts.ctx, opts.pr); err != nil { + return nil, fmt.Errorf("failed to update pull ref. Error: %w", err) + } + + pull_service.AddToTaskQueue(opts.ctx, opts.pr) + err = opts.pr.LoadIssue(opts.ctx) + if err != nil { + return nil, fmt.Errorf("failed to load pull issue. Error: %w", err) + } + comment, err := pull_service.CreatePushPullComment(opts.ctx, opts.pusher, opts.pr, oldCommitID, opts.NewCommitID) + if err == nil && comment != nil { + notify_service.PullRequestPushCommits(opts.ctx, opts.pusher, opts.pr, comment) + } + notify_service.PullRequestSynchronized(opts.ctx, opts.pusher, opts.pr) + isForcePush := comment != nil && comment.IsForcePush + + return &private.HookProcReceiveRefResult{ + OldOID: oldCommitID, + NewOID: opts.NewCommitID, + Ref: opts.pr.GetGitRefName(), + OriginalRef: opts.RefFullName, + IsForcePush: isForcePush, + IsCreatePR: false, + URL: fmt.Sprintf("%s/pulls/%d", opts.repo.HTMLURL(), opts.pr.Index), + ShouldShowMessage: setting.Git.PullRequestPushMessage && opts.repo.AllowsPulls(opts.ctx), + }, nil +} + // ProcReceive handle proc receive work func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, opts *private.HookOptions) ([]private.HookProcReceiveRefResult, error) { results := make([]private.HookProcReceiveRefResult, 0, len(opts.OldCommitIDs)) @@ -36,75 +114,6 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git. return nil, fmt.Errorf("failed to get user. Error: %w", err) } - updateExistPull := func(pr *issues_model.PullRequest, i int) error { - // update exist pull request - if err := pr.LoadBaseRepo(ctx); err != nil { - return fmt.Errorf("unable to load base repository for PR[%d] Error: %w", pr.ID, err) - } - - oldCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName()) - if err != nil { - return fmt.Errorf("unable to get ref commit id in base repository for PR[%d] Error: %w", pr.ID, err) - } - - if oldCommitID == opts.NewCommitIDs[i] { - results = append(results, private.HookProcReceiveRefResult{ - OriginalRef: opts.RefFullNames[i], - OldOID: opts.OldCommitIDs[i], - NewOID: opts.NewCommitIDs[i], - Err: "new commit is same with old commit", - }) - return nil - } - - if !forcePush { - output, _, err := git.NewCommand(ctx, "rev-list", "--max-count=1"). - AddDynamicArguments(oldCommitID, "^"+opts.NewCommitIDs[i]). - RunStdString(&git.RunOpts{Dir: repo.RepoPath(), Env: os.Environ()}) - if err != nil { - return fmt.Errorf("failed to detect force push: %w", err) - } else if len(output) > 0 { - results = append(results, private.HookProcReceiveRefResult{ - OriginalRef: opts.RefFullNames[i], - OldOID: opts.OldCommitIDs[i], - NewOID: opts.NewCommitIDs[i], - Err: "request `force-push` push option", - }) - return nil - } - } - - pr.HeadCommitID = opts.NewCommitIDs[i] - if err = pull_service.UpdateRef(ctx, pr); err != nil { - return fmt.Errorf("failed to update pull ref. Error: %w", err) - } - - pull_service.AddToTaskQueue(ctx, pr) - err = pr.LoadIssue(ctx) - if err != nil { - return fmt.Errorf("failed to load pull issue. Error: %w", err) - } - comment, err := pull_service.CreatePushPullComment(ctx, pusher, pr, oldCommitID, opts.NewCommitIDs[i]) - if err == nil && comment != nil { - notify_service.PullRequestPushCommits(ctx, pusher, pr, comment) - } - notify_service.PullRequestSynchronized(ctx, pusher, pr) - isForcePush := comment != nil && comment.IsForcePush - - results = append(results, private.HookProcReceiveRefResult{ - OldOID: oldCommitID, - NewOID: opts.NewCommitIDs[i], - Ref: pr.GetGitRefName(), - OriginalRef: opts.RefFullNames[i], - IsForcePush: isForcePush, - IsCreatePR: false, - URL: fmt.Sprintf("%s/pulls/%d", repo.HTMLURL(), pr.Index), - ShouldShowMessage: setting.Git.PullRequestPushMessage && repo.AllowsPulls(ctx), - }) - - return nil - } - for i := range opts.OldCommitIDs { if opts.NewCommitIDs[i] == objectFormat.EmptyObjectID().String() { results = append(results, private.HookProcReceiveRefResult{ @@ -139,10 +148,21 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git. continue } - err = updateExistPull(pull, i) + result, err := updateExistPull(&updateExistPullOption{ + ctx: ctx, + pr: pull, + gitRepo: gitRepo, + repo: repo, + forcePush: forcePush, + pusher: pusher, + RefFullName: opts.RefFullNames[i], + OldCommitID: opts.OldCommitIDs[i], + NewCommitID: opts.NewCommitIDs[i], + }) if err != nil { return nil, err } + results = append(results, *result) continue } @@ -258,10 +278,21 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git. continue } - err = updateExistPull(pr, i) + result, err := updateExistPull(&updateExistPullOption{ + ctx: ctx, + pr: pr, + gitRepo: gitRepo, + repo: repo, + forcePush: forcePush, + pusher: pusher, + RefFullName: opts.RefFullNames[i], + OldCommitID: opts.OldCommitIDs[i], + NewCommitID: opts.NewCommitIDs[i], + }) if err != nil { return nil, err } + results = append(results, *result) } return results, nil From bd501a625c4544f5d7d746fd4cd00db586c0ce76 Mon Sep 17 00:00:00 2001 From: hiifong Date: Thu, 9 Jan 2025 15:06:52 +0800 Subject: [PATCH 04/11] Update forReiewPattern --- modules/git/ref.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/git/ref.go b/modules/git/ref.go index 3ebcdfe359a84..e7b2ca0cc9c6f 100644 --- a/modules/git/ref.go +++ b/modules/git/ref.go @@ -105,7 +105,7 @@ func (ref RefName) IsFor() bool { return strings.HasPrefix(string(ref), ForPrefix) } -var forReviewPattern = regexp.MustCompile(ForReviewPrefix + `[1-9][0-9]*`) +var forReviewPattern = regexp.MustCompile(ForReviewPrefix + `^[1-9][0-9]\d*$`) func (ref RefName) IsForReview() bool { return forReviewPattern.MatchString(string(ref)) From cab9bbccf292801707203afb2a86607fca95c540 Mon Sep 17 00:00:00 2001 From: hiifong Date: Thu, 9 Jan 2025 22:00:16 +0800 Subject: [PATCH 05/11] fix --- modules/git/config.go | 20 +- modules/git/git.go | 185 ------------------ services/agit/agit.go | 37 +--- .../issue/sidebar/allow_maintainer_edit.tmpl | 2 +- 4 files changed, 16 insertions(+), 228 deletions(-) diff --git a/modules/git/config.go b/modules/git/config.go index 9c36cf16540d7..5e4fd2753ddbd 100644 --- a/modules/git/config.go +++ b/modules/git/config.go @@ -40,35 +40,41 @@ func syncGitConfig() (err error) { } // Set git some configurations - these must be set to these values for gitea to work correctly - if err := configSet("core.quotePath", "false"); err != nil { + if err = configSet("core.quotePath", "false"); err != nil { return err } if DefaultFeatures().CheckVersionAtLeast("2.10") { - if err := configSet("receive.advertisePushOptions", "true"); err != nil { + if err = configSet("receive.advertisePushOptions", "true"); err != nil { return err } } if DefaultFeatures().CheckVersionAtLeast("2.18") { - if err := configSet("core.commitGraph", "true"); err != nil { + if err = configSet("core.commitGraph", "true"); err != nil { return err } - if err := configSet("gc.writeCommitGraph", "true"); err != nil { + if err = configSet("gc.writeCommitGraph", "true"); err != nil { return err } - if err := configSet("fetch.writeCommitGraph", "true"); err != nil { + if err = configSet("fetch.writeCommitGraph", "true"); err != nil { return err } } if DefaultFeatures().SupportProcReceive { // set support for AGit flow - if err := configAddNonExist("receive.procReceiveRefs", "refs/for"); err != nil { + if err = configAddNonExist("receive.procReceiveRefs", "refs/for"); err != nil { + return err + } + if err = configAddNonExist("receive.procReceiveRefs", "refs/for-review"); err != nil { return err } } else { - if err := configUnsetAll("receive.procReceiveRefs", "refs/for"); err != nil { + if err = configUnsetAll("receive.procReceiveRefs", "refs/for"); err != nil { + return err + } + if err = configUnsetAll("receive.procReceiveRefs", "refs/for-review"); err != nil { return err } } diff --git a/modules/git/git.go b/modules/git/git.go index 5908dacf82e44..e3e5b832747cd 100644 --- a/modules/git/git.go +++ b/modules/git/git.go @@ -11,7 +11,6 @@ import ( "os" "os/exec" "path/filepath" - "regexp" "runtime" "strings" "time" @@ -219,187 +218,3 @@ func InitFull(ctx context.Context) (err error) { return syncGitConfig() } - -// syncGitConfig only modifies gitconfig, won't change global variables (otherwise there will be data-race problem) -func syncGitConfig() (err error) { - if err = os.MkdirAll(HomeDir(), os.ModePerm); err != nil { - return fmt.Errorf("unable to prepare git home directory %s, err: %w", HomeDir(), err) - } - - // first, write user's git config options to git config file - // user config options could be overwritten by builtin values later, because if a value is builtin, it must have some special purposes - for k, v := range setting.GitConfig.Options { - if err = configSet(strings.ToLower(k), v); err != nil { - return err - } - } - - // Git requires setting user.name and user.email in order to commit changes - old comment: "if they're not set just add some defaults" - // TODO: need to confirm whether users really need to change these values manually. It seems that these values are dummy only and not really used. - // If these values are not really used, then they can be set (overwritten) directly without considering about existence. - for configKey, defaultValue := range map[string]string{ - "user.name": "Gitea", - "user.email": "gitea@fake.local", - } { - if err := configSetNonExist(configKey, defaultValue); err != nil { - return err - } - } - - // Set git some configurations - these must be set to these values for gitea to work correctly - if err := configSet("core.quotePath", "false"); err != nil { - return err - } - - if DefaultFeatures().CheckVersionAtLeast("2.10") { - if err := configSet("receive.advertisePushOptions", "true"); err != nil { - return err - } - } - - if DefaultFeatures().CheckVersionAtLeast("2.18") { - if err := configSet("core.commitGraph", "true"); err != nil { - return err - } - if err := configSet("gc.writeCommitGraph", "true"); err != nil { - return err - } - if err := configSet("fetch.writeCommitGraph", "true"); err != nil { - return err - } - } - - if DefaultFeatures().SupportProcReceive { - // set support for AGit flow - if err := configAddNonExist("receive.procReceiveRefs", "refs/for"); err != nil { - return err - } - if err := configAddNonExist("receive.procReceiveRefs", "refs/for-review"); err != nil { - return err - } - } else { - if err := configUnsetAll("receive.procReceiveRefs", "refs/for"); err != nil { - return err - } - if err := configUnsetAll("receive.procReceiveRefs", "refs/for-review"); err != nil { - return err - } - } - - // Due to CVE-2022-24765, git now denies access to git directories which are not owned by current user. - // However, some docker users and samba users find it difficult to configure their systems correctly, - // so that Gitea's git repositories are owned by the Gitea user. - // (Possibly Windows Service users - but ownership in this case should really be set correctly on the filesystem.) - // See issue: https://github.com/go-gitea/gitea/issues/19455 - // As Gitea now always use its internal git config file, and access to the git repositories is managed through Gitea, - // it is now safe to set "safe.directory=*" for internal usage only. - // Although this setting is only supported by some new git versions, it is also tolerated by earlier versions - if err := configAddNonExist("safe.directory", "*"); err != nil { - return err - } - - if runtime.GOOS == "windows" { - if err := configSet("core.longpaths", "true"); err != nil { - return err - } - if setting.Git.DisableCoreProtectNTFS { - err = configSet("core.protectNTFS", "false") - } else { - err = configUnsetAll("core.protectNTFS", "false") - } - if err != nil { - return err - } - } - - // By default partial clones are disabled, enable them from git v2.22 - if !setting.Git.DisablePartialClone && DefaultFeatures().CheckVersionAtLeast("2.22") { - if err = configSet("uploadpack.allowfilter", "true"); err != nil { - return err - } - err = configSet("uploadpack.allowAnySHA1InWant", "true") - } else { - if err = configUnsetAll("uploadpack.allowfilter", "true"); err != nil { - return err - } - err = configUnsetAll("uploadpack.allowAnySHA1InWant", "true") - } - - return err -} - -func configSet(key, value string) error { - stdout, _, err := NewCommand(DefaultContext, "config", "--global", "--get").AddDynamicArguments(key).RunStdString(nil) - if err != nil && !IsErrorExitCode(err, 1) { - return fmt.Errorf("failed to get git config %s, err: %w", key, err) - } - - currValue := strings.TrimSpace(stdout) - if currValue == value { - return nil - } - - _, _, err = NewCommand(DefaultContext, "config", "--global").AddDynamicArguments(key, value).RunStdString(nil) - if err != nil { - return fmt.Errorf("failed to set git global config %s, err: %w", key, err) - } - - return nil -} - -func configSetNonExist(key, value string) error { - _, _, err := NewCommand(DefaultContext, "config", "--global", "--get").AddDynamicArguments(key).RunStdString(nil) - if err == nil { - // already exist - return nil - } - if IsErrorExitCode(err, 1) { - // not exist, set new config - _, _, err = NewCommand(DefaultContext, "config", "--global").AddDynamicArguments(key, value).RunStdString(nil) - if err != nil { - return fmt.Errorf("failed to set git global config %s, err: %w", key, err) - } - return nil - } - - return fmt.Errorf("failed to get git config %s, err: %w", key, err) -} - -func configAddNonExist(key, value string) error { - _, _, err := NewCommand(DefaultContext, "config", "--global", "--get").AddDynamicArguments(key, regexp.QuoteMeta(value)).RunStdString(nil) - if err == nil { - // already exist - return nil - } - if IsErrorExitCode(err, 1) { - // not exist, add new config - _, _, err = NewCommand(DefaultContext, "config", "--global", "--add").AddDynamicArguments(key, value).RunStdString(nil) - if err != nil { - return fmt.Errorf("failed to add git global config %s, err: %w", key, err) - } - return nil - } - return fmt.Errorf("failed to get git config %s, err: %w", key, err) -} - -func configUnsetAll(key, value string) error { - _, _, err := NewCommand(DefaultContext, "config", "--global", "--get").AddDynamicArguments(key).RunStdString(nil) - if err == nil { - // exist, need to remove - _, _, err = NewCommand(DefaultContext, "config", "--global", "--unset-all").AddDynamicArguments(key, regexp.QuoteMeta(value)).RunStdString(nil) - if err != nil { - return fmt.Errorf("failed to unset git global config %s, err: %w", key, err) - } - return nil - } - if IsErrorExitCode(err, 1) { - // not exist - return nil - } - return fmt.Errorf("failed to get git config %s, err: %w", key, err) -} - -// Fsck verifies the connectivity and validity of the objects in the database -func Fsck(ctx context.Context, repoPath string, timeout time.Duration, args TrustedCmdArgs) error { - return NewCommand(ctx, "fsck").AddArguments(args...).Run(&RunOpts{Timeout: timeout, Dir: repoPath}) -} diff --git a/services/agit/agit.go b/services/agit/agit.go index 7faac36d62314..dcfb2ea6a2735 100644 --- a/services/agit/agit.go +++ b/services/agit/agit.go @@ -153,7 +153,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git. pr: pull, gitRepo: gitRepo, repo: repo, - forcePush: forcePush, + forcePush: forcePush.Value(), pusher: pusher, RefFullName: opts.RefFullNames[i], OldCommitID: opts.OldCommitIDs[i], @@ -287,46 +287,13 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git. pr: pr, gitRepo: gitRepo, repo: repo, - forcePush: forcePush, + forcePush: forcePush.Value(), pusher: pusher, RefFullName: opts.RefFullNames[i], OldCommitID: opts.OldCommitIDs[i], NewCommitID: opts.NewCommitIDs[i], }) if err != nil { - return nil, fmt.Errorf("unable to get ref commit id in base repository for PR[%d] Error: %w", pr.ID, err) - } - - if oldCommitID == opts.NewCommitIDs[i] { - results = append(results, private.HookProcReceiveRefResult{ - OriginalRef: opts.RefFullNames[i], - OldOID: opts.OldCommitIDs[i], - NewOID: opts.NewCommitIDs[i], - Err: "new commit is same with old commit", - }) - continue - } - - if !forcePush.Value() { - output, _, err := git.NewCommand(ctx, "rev-list", "--max-count=1"). - AddDynamicArguments(oldCommitID, "^"+opts.NewCommitIDs[i]). - RunStdString(&git.RunOpts{Dir: repo.RepoPath(), Env: os.Environ()}) - if err != nil { - return nil, fmt.Errorf("failed to detect force push: %w", err) - } else if len(output) > 0 { - results = append(results, private.HookProcReceiveRefResult{ - OriginalRef: opts.RefFullNames[i], - OldOID: opts.OldCommitIDs[i], - NewOID: opts.NewCommitIDs[i], - Err: "request `force-push` push option", - }) - continue - } - } - - pr.HeadCommitID = opts.NewCommitIDs[i] - if err = pull_service.UpdateRef(ctx, pr); err != nil { - return nil, fmt.Errorf("failed to update pull ref. Error: %w", err) return nil, err } results = append(results, *result) diff --git a/templates/repo/issue/sidebar/allow_maintainer_edit.tmpl b/templates/repo/issue/sidebar/allow_maintainer_edit.tmpl index ad4ce96a47552..0d73d756b3133 100644 --- a/templates/repo/issue/sidebar/allow_maintainer_edit.tmpl +++ b/templates/repo/issue/sidebar/allow_maintainer_edit.tmpl @@ -1,5 +1,5 @@ {{if and .Issue.IsPull .IsIssuePoster (not .Issue.IsClosed) .Issue.PullRequest.HeadRepo}} - {{if and (not (eq .Issue.PullRequest.HeadRepo.FullName .Issue.PullRequest.BaseRepo.FullName)) .CanWriteToHeadRepo}} + {{if or (eq .SignedUserID .Issue.PosterID) (and (not (eq .Issue.PullRequest.HeadRepo.FullName .Issue.PullRequest.BaseRepo.FullName)) .CanWriteToHeadRepo)}}
Date: Thu, 9 Jan 2025 22:51:27 +0800 Subject: [PATCH 06/11] Update --- routers/private/hook_pre_receive.go | 20 ++++++++++++-------- services/agit/agit.go | 1 + 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/routers/private/hook_pre_receive.go b/routers/private/hook_pre_receive.go index 8c2c97590f316..41bd1f2931d84 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 dcfb2ea6a2735..9f6d85d5e4e87 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{ From b99fe1cf7945cbdc3d8cdb8830a3be40bc90c275 Mon Sep 17 00:00:00 2001 From: hiifong Date: Fri, 10 Jan 2025 10:45:32 +0800 Subject: [PATCH 07/11] Update --- cmd/serv.go | 2 +- modules/private/manager.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/serv.go b/cmd/serv.go index dc8d11cfe1384..1c99f25dbbd6f 100644 --- a/cmd/serv.go +++ b/cmd/serv.go @@ -237,7 +237,7 @@ func runServ(c *cli.Context) error { // for AGit Flow if cmd == "ssh_info" { data := private.GetSSHInfo(ctx) - fmt.Print(data) + fmt.Println(data) return nil } } diff --git a/modules/private/manager.go b/modules/private/manager.go index e2c607bc96b95..ec7ee39eee870 100644 --- a/modules/private/manager.go +++ b/modules/private/manager.go @@ -12,6 +12,7 @@ import ( "strconv" "time" + "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" ) @@ -43,16 +44,19 @@ func GetSSHInfo(ctx context.Context) string { resp, err := req.Response() if err != nil { + log.Error("GetSSHInfo Error: %v", err) return "" } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { + log.Error("response status code is not OK, code: %d", resp.StatusCode) return "" } content, err := io.ReadAll(resp.Body) if err != nil { + log.Error("read body error: %v", err) return "" } From 1660737ec8234d73a5234da4ae0da2e2ecdace0a Mon Sep 17 00:00:00 2001 From: hiifong Date: Sat, 11 Jan 2025 15:48:13 +0800 Subject: [PATCH 08/11] Fix --- modules/git/ref.go | 2 +- modules/git/ref_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/git/ref.go b/modules/git/ref.go index 25a89c57c8fa8..4b4876243f41d 100644 --- a/modules/git/ref.go +++ b/modules/git/ref.go @@ -105,7 +105,7 @@ func (ref RefName) IsFor() bool { return strings.HasPrefix(string(ref), ForPrefix) } -var forReviewPattern = regexp.MustCompile(ForReviewPrefix + `^[1-9][0-9]\d*$`) +var forReviewPattern = regexp.MustCompile(ForReviewPrefix + `[1-9]\d*$`) func (ref RefName) IsForReview() bool { return forReviewPattern.MatchString(string(ref)) diff --git a/modules/git/ref_test.go b/modules/git/ref_test.go index 58f679b7d6ee8..a1580ce912898 100644 --- a/modules/git/ref_test.go +++ b/modules/git/ref_test.go @@ -26,6 +26,17 @@ func TestRefName(t *testing.T) { assert.Equal(t, "main", RefName("refs/for/main").ForBranchName()) assert.Equal(t, "my/branch", RefName("refs/for/my/branch").ForBranchName()) + // Test for review name + assert.Equal(t, false, RefName("refs/for-review/-1").IsForReview()) + assert.Equal(t, false, RefName("refs/for-review/0").IsForReview()) + assert.Equal(t, false, RefName("refs/for-review/01").IsForReview()) + assert.Equal(t, true, RefName("refs/for-review/1").IsForReview()) + assert.Equal(t, true, RefName("refs/for-review/10").IsForReview()) + assert.Equal(t, true, RefName("refs/for-review/10999").IsForReview()) + assert.Equal(t, false, RefName("refs/for-review/a10").IsForReview()) + assert.Equal(t, false, RefName("refs/for-review/10a").IsForReview()) + assert.Equal(t, false, RefName("refs/for-review/abc").IsForReview()) + // Test commit hashes. assert.Equal(t, "c0ffee", RefName("c0ffee").ShortName()) } From 30713a63705997daefd4549c1e16d166e25b9142 Mon Sep 17 00:00:00 2001 From: hiifong Date: Sat, 11 Jan 2025 15:54:34 +0800 Subject: [PATCH 09/11] Fix --- modules/git/ref_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/git/ref_test.go b/modules/git/ref_test.go index a1580ce912898..9a93083031a6a 100644 --- a/modules/git/ref_test.go +++ b/modules/git/ref_test.go @@ -27,6 +27,7 @@ func TestRefName(t *testing.T) { assert.Equal(t, "my/branch", RefName("refs/for/my/branch").ForBranchName()) // Test for review name + assert.Equal(t, false, RefName("refs/for-review/").IsForReview()) assert.Equal(t, false, RefName("refs/for-review/-1").IsForReview()) assert.Equal(t, false, RefName("refs/for-review/0").IsForReview()) assert.Equal(t, false, RefName("refs/for-review/01").IsForReview()) From a0410579095c1e7506220fa4e2024d46dd2208ca Mon Sep 17 00:00:00 2001 From: hiifong Date: Sat, 11 Jan 2025 16:03:43 +0800 Subject: [PATCH 10/11] Fix --- modules/git/ref_test.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/git/ref_test.go b/modules/git/ref_test.go index 9a93083031a6a..e79eb735d13fc 100644 --- a/modules/git/ref_test.go +++ b/modules/git/ref_test.go @@ -27,16 +27,16 @@ func TestRefName(t *testing.T) { assert.Equal(t, "my/branch", RefName("refs/for/my/branch").ForBranchName()) // Test for review name - assert.Equal(t, false, RefName("refs/for-review/").IsForReview()) - assert.Equal(t, false, RefName("refs/for-review/-1").IsForReview()) - assert.Equal(t, false, RefName("refs/for-review/0").IsForReview()) - assert.Equal(t, false, RefName("refs/for-review/01").IsForReview()) - assert.Equal(t, true, RefName("refs/for-review/1").IsForReview()) - assert.Equal(t, true, RefName("refs/for-review/10").IsForReview()) - assert.Equal(t, true, RefName("refs/for-review/10999").IsForReview()) - assert.Equal(t, false, RefName("refs/for-review/a10").IsForReview()) - assert.Equal(t, false, RefName("refs/for-review/10a").IsForReview()) - assert.Equal(t, false, RefName("refs/for-review/abc").IsForReview()) + assert.False(t, RefName("refs/for-review/").IsForReview()) + assert.False(t, RefName("refs/for-review/-1").IsForReview()) + assert.False(t, RefName("refs/for-review/0").IsForReview()) + assert.False(t, RefName("refs/for-review/01").IsForReview()) + assert.True(t, RefName("refs/for-review/1").IsForReview()) + assert.True(t, RefName("refs/for-review/10").IsForReview()) + assert.True(t, RefName("refs/for-review/10999").IsForReview()) + assert.False(t, RefName("refs/for-review/a10").IsForReview()) + assert.False(t, RefName("refs/for-review/10a").IsForReview()) + assert.False(t, RefName("refs/for-review/abc").IsForReview()) // Test commit hashes. assert.Equal(t, "c0ffee", RefName("c0ffee").ShortName()) From 56b13519e4ad452e536189fe0dd4936293c2a780 Mon Sep 17 00:00:00 2001 From: hiifong Date: Sun, 12 Jan 2025 13:09:08 +0800 Subject: [PATCH 11/11] Remove --- services/pull/edits.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/services/pull/edits.go b/services/pull/edits.go index 368092b5fa2ed..c7550dcb07394 100644 --- a/services/pull/edits.go +++ b/services/pull/edits.go @@ -22,11 +22,6 @@ func SetAllowEdits(ctx context.Context, doer *user_model.User, pr *issues_model. return ErrUserHasNoPermissionForAction } - if doer.ID == pr.Issue.PosterID { - pr.AllowMaintainerEdit = allow - return issues_model.UpdateAllowEdits(ctx, pr) - } - if err := pr.LoadHeadRepo(ctx); err != nil { return err }