Skip to content

Commit 4b7594d

Browse files
authored
Provide button to delete merged pull request (#441)
* provide button to delete merged pull request * golint fix
1 parent d4924d4 commit 4b7594d

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

cmd/web.go

+1
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ func runWeb(ctx *cli.Context) error {
518518
}, context.RepoRef())
519519

520520
// m.Get("/branches", repo.Branches)
521+
m.Post("/branches/:name/delete", reqSignIn, reqRepoWriter, repo.DeleteBranchPost)
521522

522523
m.Group("/wiki", func() {
523524
m.Get("/?:page", repo.Wiki)

options/locale/locale_en-US.ini

+1
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ pulls.cannot_auto_merge_desc = This pull request can't be merged automatically b
588588
pulls.cannot_auto_merge_helper = Please merge manually in order to resolve the conflicts.
589589
pulls.merge_pull_request = Merge Pull Request
590590
pulls.open_unmerged_pull_exists = `You can't perform reopen operation because there is already an open pull request (#%d) from same repository with same merge information and is waiting for merging.`
591+
pulls.delete_branch = Delete Branch
591592
592593
milestones.new = New Milestone
593594
milestones.open_tab = %d Open

routers/repo/branch.go

+19
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package repo
66

77
import (
8+
"code.gitea.io/git"
89
"code.gitea.io/gitea/modules/base"
910
"code.gitea.io/gitea/modules/context"
1011
)
@@ -30,3 +31,21 @@ func Branches(ctx *context.Context) {
3031
ctx.Data["Branches"] = brs
3132
ctx.HTML(200, tplBranch)
3233
}
34+
35+
// DeleteBranchPost responses for delete merged branch
36+
func DeleteBranchPost(ctx *context.Context) {
37+
branchName := ctx.Params(":name")
38+
39+
if err := ctx.Repo.GitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{
40+
Force: false,
41+
}); err != nil {
42+
ctx.Handle(500, "DeleteBranch", err)
43+
return
44+
}
45+
46+
redirectTo := ctx.Query("redirect_to")
47+
if len(redirectTo) == 0 {
48+
redirectTo = ctx.Repo.RepoLink
49+
}
50+
ctx.Redirect(redirectTo)
51+
}

routers/repo/issue.go

+9
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,15 @@ func ViewIssue(ctx *context.Context) {
661661
}
662662
}
663663

664+
if issue.IsPull {
665+
pull := issue.PullRequest
666+
ctx.Data["IsPullBranchDeletable"] = ctx.Repo.IsWriter() && ctx.Repo.GitRepo.IsBranchExist(pull.HeadBranch)
667+
668+
deleteBranchURL := ctx.Repo.RepoLink + "/branches/" + pull.HeadBranch + "/delete"
669+
queryParams := "?redirect_to=" + ctx.Data["Link"].(string)
670+
ctx.Data["DeleteBranchLink"] = deleteBranchURL + queryParams
671+
}
672+
664673
ctx.Data["Participants"] = participants
665674
ctx.Data["NumParticipants"] = len(participants)
666675
ctx.Data["Issue"] = issue

templates/repo/issue/view_content.tmpl

+10-1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,15 @@
163163
<div class="item text purple">
164164
{{$.i18n.Tr "repo.pulls.has_merged"}}
165165
</div>
166+
{{if .IsPullBranchDeletable}}
167+
<div class="ui divider"></div>
168+
<div>
169+
<form class="ui form" action="{{.DeleteBranchLink}}" method="post">
170+
{{.CsrfTokenHtml}}
171+
<button class="ui red button">{{$.i18n.Tr "repo.pulls.delete_branch"}}</button>
172+
</form>
173+
</div>
174+
{{end}}
166175
{{else if .Issue.IsClosed}}
167176
<div class="item text grey">
168177
{{$.i18n.Tr "repo.pulls.reopen_to_merge"}}
@@ -265,7 +274,7 @@
265274
<div class="item">
266275
<a class="ui label {{if not .IsChecked}}hide{{end}}" id="label_{{.ID}}" href="{{$.RepoLink}}/issues?labels={{.ID}}" style="color: {{.ForegroundColor}}; background-color: {{.Color}}">{{.Name}}</a>
267276
</div>
268-
277+
269278
{{end}}
270279
</div>
271280

0 commit comments

Comments
 (0)