From 2e1636a846a6cc870c846b64536db5264a5729c5 Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Tue, 11 Jan 2022 22:53:59 +0800 Subject: [PATCH 1/2] show pull link for agit pull request also Signed-off-by: a1012112796 <1012112796@qq.com> --- routers/private/hook_post_receive.go | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/routers/private/hook_post_receive.go b/routers/private/hook_post_receive.go index 7124ae9e810b7..7a75a43bfe272 100644 --- a/routers/private/hook_post_receive.go +++ b/routers/private/hook_post_receive.go @@ -8,6 +8,7 @@ package private import ( "fmt" "net/http" + "strconv" "strings" "code.gitea.io/gitea/models" @@ -124,6 +125,40 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) { refFullName := opts.RefFullNames[i] newCommitID := opts.NewCommitIDs[i] + // post update for agit pull request + if git.SupportProcReceive && strings.HasPrefix(refFullName, git.PullPrefix) { + if repo == nil { + repo = loadRepository(ctx, ownerName, repoName) + if ctx.Written() { + return + } + } + + pullIndexStr := strings.TrimPrefix(refFullName, git.PullPrefix) + pullIndexStr = strings.Split(pullIndexStr, "/")[0] + pullIndex, _ := strconv.ParseInt(pullIndexStr, 10, 64) + if pullIndex <= 0 { + continue + } + + pr, err := models.GetPullRequestByIndex(repo.ID, pullIndex) + if err != nil { + log.Error("Failed to get PR by index %v Error: %v", pullIndex, err) + ctx.JSON(http.StatusInternalServerError, private.Response{ + Err: fmt.Sprintf("Failed to get PR by index %v Error: %v", pullIndex, err), + }) + return + } + + results = append(results, private.HookPostReceiveBranchResult{ + Message: setting.Git.PullRequestPushMessage && repo.AllowsPulls(), + Create: false, + Branch: "", + URL: fmt.Sprintf("%s/pulls/%d", repo.HTMLURL(), pr.Index), + }) + continue + } + branch := git.RefEndName(opts.RefFullNames[i]) // If we've pushed a branch (and not deleted it) From 54206cdb6172842f5343163fd491d85b83383e7f Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Fri, 14 Jan 2022 23:18:26 +0800 Subject: [PATCH 2/2] skip pull request not exist error --- routers/private/hook_post_receive.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/routers/private/hook_post_receive.go b/routers/private/hook_post_receive.go index 7a75a43bfe272..5e315ede478de 100644 --- a/routers/private/hook_post_receive.go +++ b/routers/private/hook_post_receive.go @@ -142,13 +142,16 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) { } pr, err := models.GetPullRequestByIndex(repo.ID, pullIndex) - if err != nil { + if err != nil && !models.IsErrPullRequestNotExist(err) { log.Error("Failed to get PR by index %v Error: %v", pullIndex, err) ctx.JSON(http.StatusInternalServerError, private.Response{ Err: fmt.Sprintf("Failed to get PR by index %v Error: %v", pullIndex, err), }) return } + if pr == nil { + continue + } results = append(results, private.HookPostReceiveBranchResult{ Message: setting.Git.PullRequestPushMessage && repo.AllowsPulls(),