Factor out creation of reference comments
This commit is contained in:
parent
faf860e707
commit
8c7a08fccf
|
@ -502,7 +502,7 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit, com
|
|||
|
||||
if (mask & KeywordsFoundReference) == KeywordsFoundReference {
|
||||
message := fmt.Sprintf(`<a href="%s/commit/%s">%s</a>`, repo.Link(), c.Sha1, c.Message)
|
||||
if err = CreateRefComment(doer, repo, issue, message, c.Sha1); err != nil {
|
||||
if err = CreateCommitRefComment(doer, repo, issue, message, c.Sha1); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,7 +107,8 @@ type Comment struct {
|
|||
CreatedUnix util.TimeStamp `xorm:"INDEX created"`
|
||||
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
|
||||
|
||||
// Reference issue in commit message
|
||||
// Reference issue in commit message, comments, issues, or pull requests
|
||||
// the commit SHA for commit refs otherwise a SHA of a unique reference identifier
|
||||
CommitSHA string `xorm:"VARCHAR(40)"`
|
||||
|
||||
Attachments []*Attachment `xorm:"-"`
|
||||
|
@ -622,17 +623,17 @@ func CreateIssueComment(doer *User, repo *Repository, issue *Issue, content stri
|
|||
return comment, nil
|
||||
}
|
||||
|
||||
// CreateRefComment creates a commit reference comment to issue.
|
||||
func CreateRefComment(doer *User, repo *Repository, issue *Issue, content, commitSHA string) error {
|
||||
if len(commitSHA) == 0 {
|
||||
return fmt.Errorf("cannot create reference with empty commit SHA")
|
||||
// createRefComment creates a commit, comment, issue, or pull request reference comment to issue.
|
||||
func createRefComment(doer *User, repo *Repository, issue *Issue, content, refSHA string, commentType CommentType) error {
|
||||
if len(refSHA) == 0 {
|
||||
return fmt.Errorf("cannot create reference with empty SHA")
|
||||
}
|
||||
|
||||
// Check if same reference from same commit has already existed.
|
||||
// Check if same reference from same issue and comment has already existed.
|
||||
has, err := x.Get(&Comment{
|
||||
Type: CommentTypeCommitRef,
|
||||
Type: commentType,
|
||||
IssueID: issue.ID,
|
||||
CommitSHA: commitSHA,
|
||||
CommitSHA: refSHA,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("check reference comment: %v", err)
|
||||
|
@ -641,16 +642,36 @@ func CreateRefComment(doer *User, repo *Repository, issue *Issue, content, commi
|
|||
}
|
||||
|
||||
_, err = CreateComment(&CreateCommentOptions{
|
||||
Type: CommentTypeCommitRef,
|
||||
Type: commentType,
|
||||
Doer: doer,
|
||||
Repo: repo,
|
||||
Issue: issue,
|
||||
CommitSHA: commitSHA,
|
||||
CommitSHA: refSHA,
|
||||
Content: content,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
// CreateCommitRefComment creates a commit reference comment to issue.
|
||||
func CreateCommitRefComment(doer *User, repo *Repository, issue *Issue, content, commitSHA string) error {
|
||||
return createRefComment(doer, repo, issue, content, commitSHA, CommentTypeCommitRef)
|
||||
}
|
||||
|
||||
// CreateCommentRefComment creates a comment reference comment to issue.
|
||||
func CreateCommentRefComment(doer *User, repo *Repository, issue *Issue, content, refSHA string) error {
|
||||
return createRefComment(doer, repo, issue, content, refSHA, CommentTypeCommentRef)
|
||||
}
|
||||
|
||||
// CreateIssueRefComment creates a comment reference comment to issue.
|
||||
func CreateIssueRefComment(doer *User, repo *Repository, issue *Issue, content, refSHA string) error {
|
||||
return createRefComment(doer, repo, issue, content, refSHA, CommentTypeIssueRef)
|
||||
}
|
||||
|
||||
// CreatePullRefComment creates a comment reference comment to issue.
|
||||
func CreatePullRefComment(doer *User, repo *Repository, issue *Issue, content, refSHA string) error {
|
||||
return createRefComment(doer, repo, issue, content, refSHA, CommentTypePullRef)
|
||||
}
|
||||
|
||||
// GetCommentByID returns the comment by given ID.
|
||||
func GetCommentByID(id int64) (*Comment, error) {
|
||||
c := new(Comment)
|
||||
|
|
Loading…
Reference in New Issue
Block a user