Skip to content

Commit c8ecd50

Browse files
committed
Revert "Fix cannot reopen after pushing commits to a closed PR (go-gitea#23189)"
This reverts commit 2f49b55. # Conflicts: # templates/repo/issue/view_content/comments.tmpl
1 parent 79e7a6e commit c8ecd50

File tree

6 files changed

+16
-30
lines changed

6 files changed

+16
-30
lines changed

models/issues/pull_list.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,13 @@ func listPullRequestStatement(baseRepoID int64, opts *PullRequestsOptions) (*xor
5252

5353
// GetUnmergedPullRequestsByHeadInfo returns all pull requests that are open and has not been merged
5454
// by given head information (repo and branch).
55-
// arg `includeClosed` controls whether the SQL returns closed PRs
56-
func GetUnmergedPullRequestsByHeadInfo(repoID int64, branch string, includeClosed bool) ([]*PullRequest, error) {
55+
func GetUnmergedPullRequestsByHeadInfo(repoID int64, branch string) ([]*PullRequest, error) {
5756
prs := make([]*PullRequest, 0, 2)
58-
sess := db.GetEngine(db.DefaultContext).
57+
return prs, db.GetEngine(db.DefaultContext).
58+
Where("head_repo_id = ? AND head_branch = ? AND has_merged = ? AND issue.is_closed = ? AND flow = ?",
59+
repoID, branch, false, false, PullRequestFlowGithub).
5960
Join("INNER", "issue", "issue.id = pull_request.issue_id").
60-
Where("head_repo_id = ? AND head_branch = ? AND has_merged = ? AND flow = ?", repoID, branch, false, PullRequestFlowGithub)
61-
if !includeClosed {
62-
sess.Where("issue.is_closed = ?", false)
63-
}
64-
return prs, sess.Find(&prs)
61+
Find(&prs)
6562
}
6663

6764
// CanMaintainerWriteToBranch check whether user is a maintainer and could write to the branch
@@ -74,7 +71,7 @@ func CanMaintainerWriteToBranch(p access_model.Permission, branch string, user *
7471
return false
7572
}
7673

77-
prs, err := GetUnmergedPullRequestsByHeadInfo(p.Units[0].RepoID, branch, false)
74+
prs, err := GetUnmergedPullRequestsByHeadInfo(p.Units[0].RepoID, branch)
7875
if err != nil {
7976
return false
8077
}

models/issues/pull_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func TestHasUnmergedPullRequestsByHeadInfo(t *testing.T) {
118118

119119
func TestGetUnmergedPullRequestsByHeadInfo(t *testing.T) {
120120
assert.NoError(t, unittest.PrepareTestDatabase())
121-
prs, err := issues_model.GetUnmergedPullRequestsByHeadInfo(1, "branch2", false)
121+
prs, err := issues_model.GetUnmergedPullRequestsByHeadInfo(1, "branch2")
122122
assert.NoError(t, err)
123123
assert.Len(t, prs, 1)
124124
for _, pr := range prs {

routers/web/repo/issue.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,12 +1424,11 @@ func ViewIssue(ctx *context.Context) {
14241424
}
14251425

14261426
var (
1427-
role issues_model.RoleDescriptor
1428-
ok bool
1429-
marked = make(map[int64]issues_model.RoleDescriptor)
1430-
comment *issues_model.Comment
1431-
participants = make([]*user_model.User, 1, 10)
1432-
latestCloseCommentID int64
1427+
role issues_model.RoleDescriptor
1428+
ok bool
1429+
marked = make(map[int64]issues_model.RoleDescriptor)
1430+
comment *issues_model.Comment
1431+
participants = make([]*user_model.User, 1, 10)
14331432
)
14341433
if ctx.Repo.Repository.IsTimetrackerEnabled(ctx) {
14351434
if ctx.IsSigned {
@@ -1627,15 +1626,9 @@ func ViewIssue(ctx *context.Context) {
16271626
comment.Type == issues_model.CommentTypeStopTracking {
16281627
// drop error since times could be pruned from DB..
16291628
_ = comment.LoadTime()
1630-
} else if comment.Type == issues_model.CommentTypeClose {
1631-
// record ID of latest closed comment.
1632-
// if PR is closed, the comments whose type is CommentTypePullRequestPush(29) after latestCloseCommentID won't be rendered.
1633-
latestCloseCommentID = comment.ID
16341629
}
16351630
}
16361631

1637-
ctx.Data["LatestCloseCommentID"] = latestCloseCommentID
1638-
16391632
// Combine multiple label assignments into a single comment
16401633
combineLabelComments(issue)
16411634

routers/web/repo/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C
587587
ctx.Data["HeadBranchCommitID"] = headBranchSha
588588
ctx.Data["PullHeadCommitID"] = sha
589589

590-
if pull.HeadRepo == nil || !headBranchExist || (!pull.Issue.IsClosed && (headBranchSha != sha)) {
590+
if pull.HeadRepo == nil || !headBranchExist || headBranchSha != sha {
591591
ctx.Data["IsPullRequestBroken"] = true
592592
if pull.IsSameRepo() {
593593
ctx.Data["HeadTarget"] = pull.HeadBranch

services/pull/pull.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
257257
// If you don't let it run all the way then you will lose data
258258
// TODO: graceful: AddTestPullRequestTask needs to become a queue!
259259

260-
prs, err := issues_model.GetUnmergedPullRequestsByHeadInfo(repoID, branch, true)
260+
prs, err := issues_model.GetUnmergedPullRequestsByHeadInfo(repoID, branch)
261261
if err != nil {
262262
log.Error("Find pull requests [head_repo_id: %d, head_branch: %s]: %v", repoID, branch, err)
263263
return
@@ -499,7 +499,7 @@ func (errs errlist) Error() string {
499499

500500
// CloseBranchPulls close all the pull requests who's head branch is the branch
501501
func CloseBranchPulls(doer *user_model.User, repoID int64, branch string) error {
502-
prs, err := issues_model.GetUnmergedPullRequestsByHeadInfo(repoID, branch, false)
502+
prs, err := issues_model.GetUnmergedPullRequestsByHeadInfo(repoID, branch)
503503
if err != nil {
504504
return err
505505
}
@@ -535,7 +535,7 @@ func CloseRepoBranchesPulls(ctx context.Context, doer *user_model.User, repo *re
535535

536536
var errs errlist
537537
for _, branch := range branches {
538-
prs, err := issues_model.GetUnmergedPullRequestsByHeadInfo(repo.ID, branch.Name, false)
538+
prs, err := issues_model.GetUnmergedPullRequestsByHeadInfo(repo.ID, branch.Name)
539539
if err != nil {
540540
return err
541541
}

templates/repo/issue/view_content/comments.tmpl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -697,10 +697,6 @@
697697
</span>
698698
</div>
699699
{{else if and (eq .Type 29) (or (gt .CommitsNum 0) .IsForcePush)}}
700-
<!-- If PR is closed, the comments whose type is CommentTypePullRequestPush(29) after latestCloseCommentID won't be rendered. //-->
701-
{{if and .Issue.IsClosed (gt .ID $.LatestCloseCommentID)}}
702-
{{continue}}
703-
{{end}}
704700
<div class="timeline-item event" id="{{.HashTag}}">
705701
<span class="badge">{{svg "octicon-repo-push"}}</span>
706702
<span class="text grey muted-links">

0 commit comments

Comments
 (0)