Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions routers/private/hook_post_receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package private
import (
"fmt"
"net/http"
"strconv"
"strings"

"code.gitea.io/gitea/models"
Expand Down Expand Up @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the PR doesn't exist, I think we could return an error response (maybe an error log is enough?), in case some PRs are really deleted in database.

And the below code also ignores the error if a PR doesn't exist.

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)
Expand Down