MCPcopy Create free account
hub / github.com/gogs/gogs / newIssue

Function newIssue

internal/database/issue.go:664–753  ·  view source on GitHub ↗
(e *xorm.Session, opts NewIssueOptions)

Source from the content-addressed store, hash-verified

662}
663
664func newIssue(e *xorm.Session, opts NewIssueOptions) (err error) {
665 opts.Issue.Title = strings.TrimSpace(opts.Issue.Title)
666 opts.Issue.Index = opts.Repo.NextIssueIndex()
667
668 if opts.Issue.MilestoneID > 0 {
669 milestone, err := getMilestoneByRepoID(e, opts.Issue.RepoID, opts.Issue.MilestoneID)
670 if err != nil && !IsErrMilestoneNotExist(err) {
671 return errors.Newf("getMilestoneByID: %v", err)
672 }
673
674 // Assume milestone is invalid and drop silently.
675 opts.Issue.MilestoneID = 0
676 if milestone != nil {
677 opts.Issue.MilestoneID = milestone.ID
678 opts.Issue.Milestone = milestone
679 if err = changeMilestoneAssign(e, opts.Issue, -1); err != nil {
680 return err
681 }
682 }
683 }
684
685 if opts.Issue.AssigneeID > 0 {
686 assignee, err := getUserByID(e, opts.Issue.AssigneeID)
687 if err != nil && !IsErrUserNotExist(err) {
688 return errors.Newf("get user by ID: %v", err)
689 }
690
691 if assignee != nil {
692 opts.Issue.AssigneeID = assignee.ID
693 opts.Issue.Assignee = assignee
694 } else {
695 // The assignee does not exist, drop it
696 opts.Issue.AssigneeID = 0
697 }
698 }
699
700 // Milestone and assignee validation should happen before insert actual object.
701 if _, err = e.Insert(opts.Issue); err != nil {
702 return err
703 }
704
705 if opts.IsPull {
706 _, err = e.Exec("UPDATE `repository` SET num_pulls = num_pulls + 1 WHERE id = ?", opts.Issue.RepoID)
707 } else {
708 _, err = e.Exec("UPDATE `repository` SET num_issues = num_issues + 1 WHERE id = ?", opts.Issue.RepoID)
709 }
710 if err != nil {
711 return err
712 }
713
714 if len(opts.LableIDs) > 0 {
715 // During the session, SQLite3 driver cannot handle retrieve objects after update something.
716 // So we have to get all needed labels first.
717 labels := make([]*Label, 0, len(opts.LableIDs))
718 if err = e.In("id", opts.LableIDs).Find(&labels); err != nil {
719 return errors.Newf("find all labels [label_ids: %v]: %v", opts.LableIDs, err)
720 }
721

Callers 2

NewPullRequestFunction · 0.85
NewIssueFunction · 0.85

Calls 15

getMilestoneByRepoIDFunction · 0.85
IsErrMilestoneNotExistFunction · 0.85
changeMilestoneAssignFunction · 0.85
getUserByIDFunction · 0.85
IsErrUserNotExistFunction · 0.85
newIssueUsersFunction · 0.85
getAttachmentsByUUIDsFunction · 0.85
NextIssueIndexMethod · 0.80
InsertMethod · 0.80
ExecMethod · 0.80
InMethod · 0.80
addLabelMethod · 0.80

Tested by

no test coverage detected