extract some inline functions related with create comment (#8931)
This commit is contained in:
		
							parent
							
								
									c58fba944d
								
							
						
					
					
						commit
						e0e4473172
					
				| @ -652,7 +652,16 @@ func (issue *Issue) changeStatus(e *xorm.Session, doer *User, isClosed bool) (er | ||||
| 	} | ||||
| 
 | ||||
| 	// New action comment
 | ||||
| 	if _, err = createStatusComment(e, doer, issue); err != nil { | ||||
| 	cmtType := CommentTypeClose | ||||
| 	if !issue.IsClosed { | ||||
| 		cmtType = CommentTypeReopen | ||||
| 	} | ||||
| 	if _, err := createComment(e, &CreateCommentOptions{ | ||||
| 		Type:  cmtType, | ||||
| 		Doer:  doer, | ||||
| 		Repo:  issue.Repo, | ||||
| 		Issue: issue, | ||||
| 	}); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
| @ -702,8 +711,15 @@ func (issue *Issue) ChangeTitle(doer *User, oldTitle string) (err error) { | ||||
| 		return fmt.Errorf("loadRepo: %v", err) | ||||
| 	} | ||||
| 
 | ||||
| 	if _, err = createChangeTitleComment(sess, doer, issue.Repo, issue, oldTitle, issue.Title); err != nil { | ||||
| 		return fmt.Errorf("createChangeTitleComment: %v", err) | ||||
| 	if _, err = createComment(sess, &CreateCommentOptions{ | ||||
| 		Type:     CommentTypeChangeTitle, | ||||
| 		Doer:     doer, | ||||
| 		Repo:     issue.Repo, | ||||
| 		Issue:    issue, | ||||
| 		OldTitle: oldTitle, | ||||
| 		NewTitle: issue.Title, | ||||
| 	}); err != nil { | ||||
| 		return fmt.Errorf("createComment: %v", err) | ||||
| 	} | ||||
| 
 | ||||
| 	if err = issue.neuterCrossReferences(sess); err != nil { | ||||
| @ -728,7 +744,13 @@ func AddDeletePRBranchComment(doer *User, repo *Repository, issueID int64, branc | ||||
| 	if err := sess.Begin(); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	if _, err := createDeleteBranchComment(sess, doer, repo, issue, branchName); err != nil { | ||||
| 	if _, err := createComment(sess, &CreateCommentOptions{ | ||||
| 		Type:      CommentTypeDeleteBranch, | ||||
| 		Doer:      doer, | ||||
| 		Repo:      repo, | ||||
| 		Issue:     issue, | ||||
| 		CommitSHA: branchName, | ||||
| 	}); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
|  | ||||
| @ -120,9 +120,16 @@ func (issue *Issue) toggleAssignee(sess *xorm.Session, doer *User, assigneeID in | ||||
| 	} | ||||
| 
 | ||||
| 	// Comment
 | ||||
| 	comment, err = createAssigneeComment(sess, doer, issue.Repo, issue, assigneeID, removed) | ||||
| 	comment, err = createComment(sess, &CreateCommentOptions{ | ||||
| 		Type:            CommentTypeAssignees, | ||||
| 		Doer:            doer, | ||||
| 		Repo:            issue.Repo, | ||||
| 		Issue:           issue, | ||||
| 		RemovedAssignee: removed, | ||||
| 		AssigneeID:      assigneeID, | ||||
| 	}) | ||||
| 	if err != nil { | ||||
| 		return false, nil, fmt.Errorf("createAssigneeComment: %v", err) | ||||
| 		return false, nil, fmt.Errorf("createComment: %v", err) | ||||
| 	} | ||||
| 
 | ||||
| 	// if pull request is in the middle of creation - don't call webhook
 | ||||
|  | ||||
| @ -651,34 +651,6 @@ func sendCreateCommentAction(e *xorm.Session, opts *CreateCommentOptions, commen | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func createStatusComment(e *xorm.Session, doer *User, issue *Issue) (*Comment, error) { | ||||
| 	cmtType := CommentTypeClose | ||||
| 	if !issue.IsClosed { | ||||
| 		cmtType = CommentTypeReopen | ||||
| 	} | ||||
| 	return createComment(e, &CreateCommentOptions{ | ||||
| 		Type:  cmtType, | ||||
| 		Doer:  doer, | ||||
| 		Repo:  issue.Repo, | ||||
| 		Issue: issue, | ||||
| 	}) | ||||
| } | ||||
| 
 | ||||
| func createLabelComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue, label *Label, add bool) (*Comment, error) { | ||||
| 	var content string | ||||
| 	if add { | ||||
| 		content = "1" | ||||
| 	} | ||||
| 	return createComment(e, &CreateCommentOptions{ | ||||
| 		Type:    CommentTypeLabel, | ||||
| 		Doer:    doer, | ||||
| 		Repo:    repo, | ||||
| 		Issue:   issue, | ||||
| 		Label:   label, | ||||
| 		Content: content, | ||||
| 	}) | ||||
| } | ||||
| 
 | ||||
| func createMilestoneComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue, oldMilestoneID, milestoneID int64) (*Comment, error) { | ||||
| 	return createComment(e, &CreateCommentOptions{ | ||||
| 		Type:           CommentTypeMilestone, | ||||
| @ -690,17 +662,6 @@ func createMilestoneComment(e *xorm.Session, doer *User, repo *Repository, issue | ||||
| 	}) | ||||
| } | ||||
| 
 | ||||
| func createAssigneeComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue, assigneeID int64, removedAssignee bool) (*Comment, error) { | ||||
| 	return createComment(e, &CreateCommentOptions{ | ||||
| 		Type:            CommentTypeAssignees, | ||||
| 		Doer:            doer, | ||||
| 		Repo:            repo, | ||||
| 		Issue:           issue, | ||||
| 		RemovedAssignee: removedAssignee, | ||||
| 		AssigneeID:      assigneeID, | ||||
| 	}) | ||||
| } | ||||
| 
 | ||||
| func createDeadlineComment(e *xorm.Session, doer *User, issue *Issue, newDeadlineUnix timeutil.TimeStamp) (*Comment, error) { | ||||
| 
 | ||||
| 	var content string | ||||
| @ -733,27 +694,6 @@ func createDeadlineComment(e *xorm.Session, doer *User, issue *Issue, newDeadlin | ||||
| 	}) | ||||
| } | ||||
| 
 | ||||
| func createChangeTitleComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue, oldTitle, newTitle string) (*Comment, error) { | ||||
| 	return createComment(e, &CreateCommentOptions{ | ||||
| 		Type:     CommentTypeChangeTitle, | ||||
| 		Doer:     doer, | ||||
| 		Repo:     repo, | ||||
| 		Issue:    issue, | ||||
| 		OldTitle: oldTitle, | ||||
| 		NewTitle: newTitle, | ||||
| 	}) | ||||
| } | ||||
| 
 | ||||
| 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, | ||||
| 	}) | ||||
| } | ||||
| 
 | ||||
| // Creates issue dependency comment
 | ||||
| func createIssueDependencyComment(e *xorm.Session, doer *User, issue *Issue, dependentIssue *Issue, add bool) (err error) { | ||||
| 	cType := CommentTypeAddDependency | ||||
|  | ||||
| @ -402,7 +402,14 @@ func newIssueLabel(e *xorm.Session, issue *Issue, label *Label, doer *User) (err | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	if _, err = createLabelComment(e, doer, issue.Repo, issue, label, true); err != nil { | ||||
| 	if _, err = createComment(e, &CreateCommentOptions{ | ||||
| 		Type:    CommentTypeLabel, | ||||
| 		Doer:    doer, | ||||
| 		Repo:    issue.Repo, | ||||
| 		Issue:   issue, | ||||
| 		Label:   label, | ||||
| 		Content: "1", | ||||
| 	}); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
| @ -471,7 +478,13 @@ func deleteIssueLabel(e *xorm.Session, issue *Issue, label *Label, doer *User) ( | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	if _, err = createLabelComment(e, doer, issue.Repo, issue, label, false); err != nil { | ||||
| 	if _, err = createComment(e, &CreateCommentOptions{ | ||||
| 		Type:  CommentTypeLabel, | ||||
| 		Doer:  doer, | ||||
| 		Repo:  issue.Repo, | ||||
| 		Issue: issue, | ||||
| 		Label: label, | ||||
| 	}); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
|  | ||||
| @ -25,25 +25,6 @@ type crossReferencesContext struct { | ||||
| 	OrigComment *Comment | ||||
| } | ||||
| 
 | ||||
| func newCrossReference(e *xorm.Session, ctx *crossReferencesContext, xref *crossReference) error { | ||||
| 	var refCommentID int64 | ||||
| 	if ctx.OrigComment != nil { | ||||
| 		refCommentID = ctx.OrigComment.ID | ||||
| 	} | ||||
| 	_, err := createComment(e, &CreateCommentOptions{ | ||||
| 		Type:         ctx.Type, | ||||
| 		Doer:         ctx.Doer, | ||||
| 		Repo:         xref.Issue.Repo, | ||||
| 		Issue:        xref.Issue, | ||||
| 		RefRepoID:    ctx.OrigIssue.RepoID, | ||||
| 		RefIssueID:   ctx.OrigIssue.ID, | ||||
| 		RefCommentID: refCommentID, | ||||
| 		RefAction:    xref.Action, | ||||
| 		RefIsPull:    xref.Issue.IsPull, | ||||
| 	}) | ||||
| 	return err | ||||
| } | ||||
| 
 | ||||
| func neuterCrossReferences(e Engine, issueID int64, commentID int64) error { | ||||
| 	active := make([]*Comment, 0, 10) | ||||
| 	sess := e.Where("`ref_action` IN (?, ?, ?)", references.XRefActionNone, references.XRefActionCloses, references.XRefActionReopens) | ||||
| @ -93,7 +74,21 @@ func (issue *Issue) createCrossReferences(e *xorm.Session, ctx *crossReferencesC | ||||
| 		return err | ||||
| 	} | ||||
| 	for _, xref := range xreflist { | ||||
| 		if err = newCrossReference(e, ctx, xref); err != nil { | ||||
| 		var refCommentID int64 | ||||
| 		if ctx.OrigComment != nil { | ||||
| 			refCommentID = ctx.OrigComment.ID | ||||
| 		} | ||||
| 		if _, err := createComment(e, &CreateCommentOptions{ | ||||
| 			Type:         ctx.Type, | ||||
| 			Doer:         ctx.Doer, | ||||
| 			Repo:         xref.Issue.Repo, | ||||
| 			Issue:        xref.Issue, | ||||
| 			RefRepoID:    ctx.OrigIssue.RepoID, | ||||
| 			RefIssueID:   ctx.OrigIssue.ID, | ||||
| 			RefCommentID: refCommentID, | ||||
| 			RefAction:    xref.Action, | ||||
| 			RefIsPull:    xref.Issue.IsPull, | ||||
| 		}); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user