Skip to content

Commit 378acc9

Browse files
zeripath6543lunny
authored
Use OldRef instead of CommitSHA for DeleteBranch comments (#14604)
Fix #14545 Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: 6543 <[email protected]> Co-authored-by: Lunny Xiao <[email protected]>
1 parent 98827e9 commit 378acc9

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

models/issue.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -745,11 +745,11 @@ func AddDeletePRBranchComment(doer *User, repo *Repository, issueID int64, branc
745745
return err
746746
}
747747
var opts = &CreateCommentOptions{
748-
Type: CommentTypeDeleteBranch,
749-
Doer: doer,
750-
Repo: repo,
751-
Issue: issue,
752-
CommitSHA: branchName,
748+
Type: CommentTypeDeleteBranch,
749+
Doer: doer,
750+
Repo: repo,
751+
Issue: issue,
752+
OldRef: branchName,
753753
}
754754
if _, err = createComment(sess, opts); err != nil {
755755
return err

models/migrations/migrations.go

+2
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ var migrations = []Migration{
284284
NewMigration("Add user redirect", addUserRedirect),
285285
// v168 -> v169
286286
NewMigration("Recreate user table to fix default values", recreateUserTableToFixDefaultValues),
287+
// v169 -> v170
288+
NewMigration("Update DeleteBranch comments to set the old_ref to the commit_sha", commentTypeDeleteBranchUseOldRef),
287289
}
288290

289291
// GetCurrentDBVersion returns the current db version

models/migrations/v169.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2021 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package migrations
6+
7+
import (
8+
"xorm.io/xorm"
9+
)
10+
11+
func commentTypeDeleteBranchUseOldRef(x *xorm.Engine) error {
12+
_, err := x.Exec("UPDATE comment SET old_ref = commit_sha, commit_sha = '' WHERE type = 11")
13+
return err
14+
}

templates/repo/issue/view_content/comments.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@
251251
</a>
252252
<span class="text grey">
253253
<a class="author" href="{{.Poster.HomeLink}}">{{.Poster.GetDisplayName}}</a>
254-
{{$.i18n.Tr "repo.issues.delete_branch_at" (.CommitSHA|Escape) $createdStr | Safe}}
254+
{{$.i18n.Tr "repo.issues.delete_branch_at" (.OldRef|Escape) $createdStr | Safe}}
255255
</span>
256256
</div>
257257
{{else if eq .Type 12}}

0 commit comments

Comments
 (0)