summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--models/issue.go18
-rw-r--r--models/issue_comment.go12
-rw-r--r--options/locale/locale_en-US.ini1
-rw-r--r--options/locale/locale_zh-CN.ini1
-rw-r--r--routers/repo/branch.go12
-rw-r--r--routers/repo/issue.go3
-rw-r--r--templates/repo/issue/view_content.tmpl10
7 files changed, 55 insertions, 2 deletions
diff --git a/models/issue.go b/models/issue.go
index 48d845e6e8..c3f5de6429 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -685,6 +685,24 @@ func (issue *Issue) ChangeTitle(doer *User, title string) (err error) {
return nil
}
+// AddDeletePRBranchComment adds delete branch comment for pull request issue
+func AddDeletePRBranchComment(doer *User, repo *Repository, issueID int64, branchName string) error {
+ issue, err := getIssueByID(x, issueID)
+ if err != nil {
+ return err
+ }
+ sess := x.NewSession()
+ defer sess.Close()
+ if err := sess.Begin(); err != nil {
+ return err
+ }
+ if _, err := createDeleteBranchComment(sess, doer, repo, issue, branchName); err != nil {
+ return err
+ }
+
+ return sess.Commit()
+}
+
// ChangeContent changes issue content, as the given user.
func (issue *Issue) ChangeContent(doer *User, content string) (err error) {
oldContent := issue.Content
diff --git a/models/issue_comment.go b/models/issue_comment.go
index e011f5f0d5..2eadba810b 100644
--- a/models/issue_comment.go
+++ b/models/issue_comment.go
@@ -44,6 +44,8 @@ const (
CommentTypeAssignees
// Change Title
CommentTypeChangeTitle
+ // Delete Branch
+ CommentTypeDeleteBranch
)
// CommentTag defines comment tag type
@@ -472,6 +474,16 @@ func createChangeTitleComment(e *xorm.Session, doer *User, repo *Repository, iss
})
}
+func createDeleteBranchComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue, branchName string) (*Comment, error) {
+ return createComment(e, &CreateCommentOptions{
+ Type: CommentTypeDeleteBranch,
+ Doer: doer,
+ Repo: repo,
+ Issue: issue,
+ CommitSHA: branchName,
+ })
+}
+
// CreateCommentOptions defines options for creating comment
type CreateCommentOptions struct {
Type CommentType
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index 3d1fd9da58..7e0d3feec9 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -551,6 +551,7 @@ issues.self_assign_at = `self-assigned this %s`
issues.add_assignee_at = `was assigned by <b>%s</b> %s`
issues.remove_assignee_at = `removed their assignment %s`
issues.change_title_at = `changed title from <b>%s</b> to <b>%s</b> %s`
+issues.delete_branch_at = `deleted branch <b>%s</b> %s`
issues.open_tab = %d Open
issues.close_tab = %d Closed
issues.filter_label = Label
diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini
index 3356a41280..74810cd882 100644
--- a/options/locale/locale_zh-CN.ini
+++ b/options/locale/locale_zh-CN.ini
@@ -510,6 +510,7 @@ issues.self_assign_at = `于 %s 指派给自己`
issues.add_assignee_at = `于 %[2]s 被 <b>%[1]s</b> 指派`
issues.remove_assignee_at = `于 %s 取消了指派`
issues.change_title_at = `于 %[3]s 修改标题 <b>%[1]s</b> 为 <b>%[2]s</b>`
+issues.delete_branch_at = `于 %[2]s 删除了分支 <b>%[1]s`
issues.open_tab=%d 个开启中
issues.close_tab=%d 个已关闭
issues.filter_label=标签筛选
diff --git a/routers/repo/branch.go b/routers/repo/branch.go
index 104d459a7d..d040f2a560 100644
--- a/routers/repo/branch.go
+++ b/routers/repo/branch.go
@@ -6,6 +6,7 @@ package repo
import (
"code.gitea.io/git"
+ "code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
@@ -70,12 +71,21 @@ func DeleteBranchPost(ctx *context.Context) {
}
if err := ctx.Repo.GitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{
- Force: false,
+ Force: true,
}); err != nil {
log.Error(4, "DeleteBranch: %v", err)
ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
return
}
+ issueID := ctx.QueryInt64("issue_id")
+ if issueID > 0 {
+ if err := models.AddDeletePRBranchComment(ctx.User, ctx.Repo.Repository, issueID, branchName); err != nil {
+ log.Error(4, "DeleteBranch: %v", err)
+ ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
+ return
+ }
+ }
+
ctx.Flash.Success(ctx.Tr("repo.branch.deletion_success", fullBranchName))
}
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 17c3b56c2e..e9b60175f3 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -635,7 +635,8 @@ func ViewIssue(ctx *context.Context) {
} else if ctx.User.IsWriterOfRepo(pull.HeadRepo) {
canDelete = true
deleteBranchURL := pull.HeadRepo.Link() + "/branches/" + pull.HeadBranch + "/delete"
- ctx.Data["DeleteBranchLink"] = fmt.Sprintf("%s?commit=%s&redirect_to=%s", deleteBranchURL, pull.MergedCommitID, ctx.Data["Link"])
+ ctx.Data["DeleteBranchLink"] = fmt.Sprintf("%s?commit=%s&redirect_to=%s&issue_id=%d",
+ deleteBranchURL, pull.MergedCommitID, ctx.Data["Link"], issue.ID)
}
}
diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl
index def50a179b..40993e54d2 100644
--- a/templates/repo/issue/view_content.tmpl
+++ b/templates/repo/issue/view_content.tmpl
@@ -185,6 +185,16 @@
<span class="text grey"><a href="{{.Poster.HomeLink}}">{{.Poster.Name}}</a>
{{$.i18n.Tr "repo.issues.change_title_at" .OldTitle .NewTitle $createdStr | Safe}}
</span>
+ {{else if eq .Type 11}}
+ <div class="event">
+ <span class="octicon octicon-primitive-dot"></span>
+ </div>
+ <a class="ui avatar image" href="{{.Poster.HomeLink}}">
+ <img src="{{.Poster.RelAvatarLink}}">
+ </a>
+ <span class="text grey"><a href="{{.Poster.HomeLink}}">{{.Poster.Name}}</a>
+ {{$.i18n.Tr "repo.issues.delete_branch_at" .CommitSHA $createdStr | Safe}}
+ </span>
{{end}}
{{end}}