From 378acc9d966554299e4a7dbe15e6e41026963653 Mon Sep 17 00:00:00 2001 From: zeripath Date: Mon, 8 Feb 2021 03:09:14 +0000 Subject: [PATCH] Use OldRef instead of CommitSHA for DeleteBranch comments (#14604) Fix #14545 Signed-off-by: Andrew Thornton Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Lunny Xiao --- models/issue.go | 10 +++++----- models/migrations/migrations.go | 2 ++ models/migrations/v169.go | 14 ++++++++++++++ templates/repo/issue/view_content/comments.tmpl | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 models/migrations/v169.go diff --git a/models/issue.go b/models/issue.go index a7392633af..b903e82ad7 100644 --- a/models/issue.go +++ b/models/issue.go @@ -745,11 +745,11 @@ func AddDeletePRBranchComment(doer *User, repo *Repository, issueID int64, branc return err } var opts = &CreateCommentOptions{ - Type: CommentTypeDeleteBranch, - Doer: doer, - Repo: repo, - Issue: issue, - CommitSHA: branchName, + Type: CommentTypeDeleteBranch, + Doer: doer, + Repo: repo, + Issue: issue, + OldRef: branchName, } if _, err = createComment(sess, opts); err != nil { return err diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index c1a3b186cf..c926ee6ccf 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -284,6 +284,8 @@ var migrations = []Migration{ NewMigration("Add user redirect", addUserRedirect), // v168 -> v169 NewMigration("Recreate user table to fix default values", recreateUserTableToFixDefaultValues), + // v169 -> v170 + NewMigration("Update DeleteBranch comments to set the old_ref to the commit_sha", commentTypeDeleteBranchUseOldRef), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v169.go b/models/migrations/v169.go new file mode 100644 index 0000000000..e976281c5b --- /dev/null +++ b/models/migrations/v169.go @@ -0,0 +1,14 @@ +// Copyright 2021 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package migrations + +import ( + "xorm.io/xorm" +) + +func commentTypeDeleteBranchUseOldRef(x *xorm.Engine) error { + _, err := x.Exec("UPDATE comment SET old_ref = commit_sha, commit_sha = '' WHERE type = 11") + return err +} diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index abf5792a9e..63fe73857c 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -251,7 +251,7 @@ {{.Poster.GetDisplayName}} - {{$.i18n.Tr "repo.issues.delete_branch_at" (.CommitSHA|Escape) $createdStr | Safe}} + {{$.i18n.Tr "repo.issues.delete_branch_at" (.OldRef|Escape) $createdStr | Safe}} {{else if eq .Type 12}}