Browse Source

Add delete branch track on pull request comments (#888)

* add delete branch track on pull request comments

* don't change vendor
tags/v1.1.0
Lunny Xiao 7 years ago
parent
commit
cf0f451c37

+ 18
- 0
models/issue.go View File

return nil 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. // ChangeContent changes issue content, as the given user.
func (issue *Issue) ChangeContent(doer *User, content string) (err error) { func (issue *Issue) ChangeContent(doer *User, content string) (err error) {
oldContent := issue.Content oldContent := issue.Content

+ 12
- 0
models/issue_comment.go View File

CommentTypeAssignees CommentTypeAssignees
// Change Title // Change Title
CommentTypeChangeTitle CommentTypeChangeTitle
// Delete Branch
CommentTypeDeleteBranch
) )


// CommentTag defines comment tag type // CommentTag defines comment tag type
}) })
} }


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 // CreateCommentOptions defines options for creating comment
type CreateCommentOptions struct { type CreateCommentOptions struct {
Type CommentType Type CommentType

+ 1
- 0
options/locale/locale_en-US.ini View File

issues.add_assignee_at = `was assigned by <b>%s</b> %s` issues.add_assignee_at = `was assigned by <b>%s</b> %s`
issues.remove_assignee_at = `removed their assignment %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.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.open_tab = %d Open
issues.close_tab = %d Closed issues.close_tab = %d Closed
issues.filter_label = Label issues.filter_label = Label

+ 1
- 0
options/locale/locale_zh-CN.ini View File

issues.add_assignee_at = `于 %[2]s 被 <b>%[1]s</b> 指派` issues.add_assignee_at = `于 %[2]s 被 <b>%[1]s</b> 指派`
issues.remove_assignee_at = `于 %s 取消了指派` issues.remove_assignee_at = `于 %s 取消了指派`
issues.change_title_at = `于 %[3]s 修改标题 <b>%[1]s</b> 为 <b>%[2]s</b>` 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.open_tab=%d 个开启中
issues.close_tab=%d 个已关闭 issues.close_tab=%d 个已关闭
issues.filter_label=标签筛选 issues.filter_label=标签筛选

+ 11
- 1
routers/repo/branch.go View File



import ( import (
"code.gitea.io/git" "code.gitea.io/git"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
} }


if err := ctx.Repo.GitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{ if err := ctx.Repo.GitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{
Force: false,
Force: true,
}); err != nil { }); err != nil {
log.Error(4, "DeleteBranch: %v", err) log.Error(4, "DeleteBranch: %v", err)
ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName)) ctx.Flash.Error(ctx.Tr("repo.branch.deletion_failed", fullBranchName))
return 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)) ctx.Flash.Success(ctx.Tr("repo.branch.deletion_success", fullBranchName))
} }

+ 2
- 1
routers/repo/issue.go View File

} else if ctx.User.IsWriterOfRepo(pull.HeadRepo) { } else if ctx.User.IsWriterOfRepo(pull.HeadRepo) {
canDelete = true canDelete = true
deleteBranchURL := pull.HeadRepo.Link() + "/branches/" + pull.HeadBranch + "/delete" 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)


} }
} }

+ 10
- 0
templates/repo/issue/view_content.tmpl View File

<span class="text grey"><a href="{{.Poster.HomeLink}}">{{.Poster.Name}}</a> <span class="text grey"><a href="{{.Poster.HomeLink}}">{{.Poster.Name}}</a>
{{$.i18n.Tr "repo.issues.change_title_at" .OldTitle .NewTitle $createdStr | Safe}} {{$.i18n.Tr "repo.issues.change_title_at" .OldTitle .NewTitle $createdStr | Safe}}
</span> </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}}


{{end}} {{end}}

Loading…
Cancel
Save