summaryrefslogtreecommitdiffstats
path: root/models/issues
diff options
context:
space:
mode:
authorsillyguodong <33891828+sillyguodong@users.noreply.github.com>2023-05-08 14:39:32 +0800
committerGitHub <noreply@github.com>2023-05-08 14:39:32 +0800
commite962ade99cfd0471273f3dcf956c7cd222472758 (patch)
treebcaa2aeaf79ee6dc314a6903cac8b5395087c691 /models/issues
parent80765aab8c71219ffd32689b3d15558157c25b85 (diff)
downloadgitea-e962ade99cfd0471273f3dcf956c7cd222472758.tar.gz
gitea-e962ade99cfd0471273f3dcf956c7cd222472758.zip
Refresh the refernce of the closed PR when reopening (#24231)
Close #24213 Replace #23830 #### Cause - Before, in order to making PR can get latest commit after reopening, the `ref`(${REPO_PATH}/refs/pull/${PR_INDEX}/head) of evrey closed PR will be updated when pushing commits to the `head branch` of the closed PR. #### Changes - For closed PR , won't perform these behavior: insert`comment`, push `notification` (UI and email), exectue [pushToBaseRepo](https://github.com/go-gitea/gitea/blob/74225033413dc0f2b308bbe069f6d185b551e364/services/pull/pull.go#L409) function and trigger `action` any more when pushing to the `head branch` of the closed PR. - Refresh the reference of the PR when reopening the closed PR (**even if the head branch has been deleted before**). Make the reference of PR consistent with the `head branch`.
Diffstat (limited to 'models/issues')
-rw-r--r--models/issues/pull.go4
-rw-r--r--models/issues/pull_list.go11
-rw-r--r--models/issues/pull_test.go2
3 files changed, 8 insertions, 9 deletions
diff --git a/models/issues/pull.go b/models/issues/pull.go
index a15ebec0b5..855d37867d 100644
--- a/models/issues/pull.go
+++ b/models/issues/pull.go
@@ -433,6 +433,10 @@ func (pr *PullRequest) GetGitRefName() string {
return fmt.Sprintf("%s%d/head", git.PullPrefix, pr.Index)
}
+func (pr *PullRequest) GetGitHeadBranchRefName() string {
+ return fmt.Sprintf("%s%s", git.BranchPrefix, pr.HeadBranch)
+}
+
// IsChecking returns true if this pull request is still checking conflict.
func (pr *PullRequest) IsChecking() bool {
return pr.Status == PullRequestStatusChecking
diff --git a/models/issues/pull_list.go b/models/issues/pull_list.go
index 9d361c5c5d..f2adac0701 100644
--- a/models/issues/pull_list.go
+++ b/models/issues/pull_list.go
@@ -51,16 +51,11 @@ func listPullRequestStatement(baseRepoID int64, opts *PullRequestsOptions) (*xor
}
// GetUnmergedPullRequestsByHeadInfo returns all pull requests that are open and has not been merged
-// by given head information (repo and branch).
-// arg `includeClosed` controls whether the SQL returns closed PRs
-func GetUnmergedPullRequestsByHeadInfo(repoID int64, branch string, includeClosed bool) ([]*PullRequest, error) {
+func GetUnmergedPullRequestsByHeadInfo(repoID int64, branch string) ([]*PullRequest, error) {
prs := make([]*PullRequest, 0, 2)
sess := db.GetEngine(db.DefaultContext).
Join("INNER", "issue", "issue.id = pull_request.issue_id").
- Where("head_repo_id = ? AND head_branch = ? AND has_merged = ? AND flow = ?", repoID, branch, false, PullRequestFlowGithub)
- if !includeClosed {
- sess.Where("issue.is_closed = ?", false)
- }
+ Where("head_repo_id = ? AND head_branch = ? AND has_merged = ? AND issue.is_closed = ? AND flow = ?", repoID, branch, false, false, PullRequestFlowGithub)
return prs, sess.Find(&prs)
}
@@ -74,7 +69,7 @@ func CanMaintainerWriteToBranch(p access_model.Permission, branch string, user *
return false
}
- prs, err := GetUnmergedPullRequestsByHeadInfo(p.Units[0].RepoID, branch, false)
+ prs, err := GetUnmergedPullRequestsByHeadInfo(p.Units[0].RepoID, branch)
if err != nil {
return false
}
diff --git a/models/issues/pull_test.go b/models/issues/pull_test.go
index 8d99b2667c..0b06095213 100644
--- a/models/issues/pull_test.go
+++ b/models/issues/pull_test.go
@@ -118,7 +118,7 @@ func TestHasUnmergedPullRequestsByHeadInfo(t *testing.T) {
func TestGetUnmergedPullRequestsByHeadInfo(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- prs, err := issues_model.GetUnmergedPullRequestsByHeadInfo(1, "branch2", false)
+ prs, err := issues_model.GetUnmergedPullRequestsByHeadInfo(1, "branch2")
assert.NoError(t, err)
assert.Len(t, prs, 1)
for _, pr := range prs {