func CreateCodeComment(ctx *context.Context, form auth.CodeCommentForm) {
	issue := GetActionIssue(ctx)
	if !issue.IsPull {
		return
	}
	if ctx.Written() {
		return
	}

	if ctx.HasError() {
		ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
		ctx.Redirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
		return
	}
	var comment *models.Comment
	defer func() {
		if comment != nil {
			ctx.Redirect(comment.HTMLURL())
		} else {
			ctx.Redirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
		}
	}()
	signedLine := form.Line
	if form.Side == "previous" {
		signedLine *= -1
	}

	review := new(models.Review)
	if form.IsReview {
		var err error
		// Check if the user has already a pending review for this issue
		if review, err = models.GetCurrentReview(ctx.User, issue); err != nil {
			if !models.IsErrReviewNotExist(err) {
				ctx.ServerError("CreateCodeComment", err)
				return
			}
			// No pending review exists
			// Create a new pending review for this issue & user
			if review, err = pull_service.CreateReview(models.CreateReviewOptions{
				Type:     models.ReviewTypePending,
				Reviewer: ctx.User,
				Issue:    issue,
			}); err != nil {
				ctx.ServerError("CreateCodeComment", err)
				return
			}

		}
	}
	if review.ID == 0 {
		review.ID = form.Reply
	}
	//FIXME check if line, commit and treepath exist
	comment, err := models.CreateCodeComment(
		ctx.User,
		issue.Repo,
		issue,
		form.Content,
		form.TreePath,
		signedLine,
		review.ID,
	)
	if err != nil {
		ctx.ServerError("CreateCodeComment", err)
		return
	}
	// Send no notification if comment is pending
	if !form.IsReview || form.Reply != 0 {
		notification.NotifyCreateIssueComment(ctx.User, issue.Repo, issue, comment)
	}

	log.Trace("Comment created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID)
}
// CreateCodeComment will create a code comment including an pending review if required
CreateCodeComment will create a code comment including an pending review if required
// CreateCodeComment will create a code comment including an pending review if required
func CreateCodeComment(ctx *context.Context, form auth.CodeCommentForm) {
	issue := GetActionIssue(ctx)
	if !issue.IsPull {
		return
	}
	if ctx.Written() {
		return
	}
	if ctx.HasError() {
		ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
		ctx.Redirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
		return
	}
	var comment *models.Comment
	defer func() {
		if comment != nil {
			ctx.Redirect(comment.HTMLURL())
		} else {
			ctx.Redirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
		}
	}()
	signedLine := form.Line
	if form.Side == "previous" {
		signedLine *= -1
	}
	review := new(models.Review)
	if form.IsReview {
		var err error
		if review, err = models.GetCurrentReview(ctx.User, issue); err != nil {
			if !models.IsErrReviewNotExist(err) {
				ctx.ServerError("CreateCodeComment", err)
				return
			}
			if review, err = pull_service.CreateReview(models.CreateReviewOptions{
				Type:     models.ReviewTypePending,
				Reviewer: ctx.User,
				Issue:    issue,
			}); err != nil {
				ctx.ServerError("CreateCodeComment", err)
				return
			}
		}
	}
	if review.ID == 0 {
		review.ID = form.Reply
	}
	comment, err := models.CreateCodeComment(
		ctx.User,
		issue.Repo,
		issue,
		form.Content,
		form.TreePath,
		signedLine,
		review.ID,
	)
	if err != nil {
		ctx.ServerError("CreateCodeComment", err)
		return
	}
	if !form.IsReview || form.Reply != 0 {
		notification.NotifyCreateIssueComment(ctx.User, issue.Repo, issue, comment)
	}
	log.Trace("Comment created: %d/%d/%d", ctx.Repo.Repository.ID, issue.ID, comment.ID)
}
func CreateCodeComment ( ctx * context . Context , form auth . CodeCommentForm ) { issue := GetActionIssue ( ctx ) if ! issue . IsPull { return } if ctx . Written ( ) { return } if ctx . HasError ( ) { ctx . Flash . Error ( ctx . Data [ " " ] . ( string ) ) ctx . Redirect ( fmt . Sprintf ( " " , ctx . Repo . RepoLink , issue . Index ) ) return } var comment * models . Comment defer func ( ) { if comment != nil { ctx . Redirect ( comment . HTMLURL ( ) ) } else { ctx . Redirect ( fmt . Sprintf ( " " , ctx . Repo . RepoLink , issue . Index ) ) } } ( ) signedLine := form . Line if form . Side == " " { signedLine *= - 1 } review := new ( models . Review ) if form . IsReview { var err error if review , err = models . GetCurrentReview ( ctx . User , issue ) ; err != nil { if ! models . IsErrReviewNotExist ( err ) { ctx . ServerError ( " " , err ) return } if review , err = pull_service . CreateReview ( models . CreateReviewOptions { Type : models . ReviewTypePending , Reviewer : ctx . User , Issue : issue , } ) ; err != nil { ctx . ServerError ( " " , err ) return } } } if review . ID == 0 { review . ID = form . Reply } comment , err := models . CreateCodeComment ( ctx . User , issue . Repo , issue , form . Content , form . TreePath , signedLine , review . ID , ) if err != nil { ctx . ServerError ( " " , err ) return } if ! form . IsReview || form . Reply != 0 { notification . NotifyCreateIssueComment ( ctx . User , issue . Repo , issue , comment ) } log . Trace ( " " , ctx . Repo . Repository . ID , issue . ID , comment . ID ) }
CreateCodeComment will create a code comment including an pending review if required
CreateCodeComment will create a code comment including an pending review if required
// Check if the user has already a pending review for this issue // No pending review exists // Create a new pending review for this issue & user //FIXME check if line, commit and treepath exist // Send no notification if comment is pending