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

Method ChangeAssignee

internal/database/issue.go:607–654  ·  view source on GitHub ↗
(doer *User, assigneeID int64)

Source from the content-addressed store, hash-verified

605}
606
607func (issue *Issue) ChangeAssignee(doer *User, assigneeID int64) (err error) {
608 issue.AssigneeID = assigneeID
609 if err = UpdateIssueUserByAssignee(issue); err != nil {
610 return errors.Newf("UpdateIssueUserByAssignee: %v", err)
611 }
612
613 issue.Assignee, err = Handle.Users().GetByID(context.TODO(), issue.AssigneeID)
614 if err != nil && !IsErrUserNotExist(err) {
615 log.Error("Failed to get user by ID: %v", err)
616 return nil
617 }
618
619 // Error not nil here means user does not exist, which is remove assignee.
620 isRemoveAssignee := err != nil
621 if issue.IsPull {
622 issue.PullRequest.Issue = issue
623 apiPullRequest := &api.PullRequestPayload{
624 Index: issue.Index,
625 PullRequest: issue.PullRequest.APIFormat(),
626 Repository: issue.Repo.APIFormatLegacy(nil),
627 Sender: doer.APIFormat(),
628 }
629 if isRemoveAssignee {
630 apiPullRequest.Action = api.HOOK_ISSUE_UNASSIGNED
631 } else {
632 apiPullRequest.Action = api.HOOK_ISSUE_ASSIGNED
633 }
634 err = PrepareWebhooks(issue.Repo, HookEventTypePullRequest, apiPullRequest)
635 } else {
636 apiIssues := &api.IssuesPayload{
637 Index: issue.Index,
638 Issue: issue.APIFormat(),
639 Repository: issue.Repo.APIFormatLegacy(nil),
640 Sender: doer.APIFormat(),
641 }
642 if isRemoveAssignee {
643 apiIssues.Action = api.HOOK_ISSUE_UNASSIGNED
644 } else {
645 apiIssues.Action = api.HOOK_ISSUE_ASSIGNED
646 }
647 err = PrepareWebhooks(issue.Repo, HookEventTypeIssues, apiIssues)
648 }
649 if err != nil {
650 log.Error("PrepareWebhooks [is_pull: %v, remove_assignee: %v]: %v", issue.IsPull, isRemoveAssignee, err)
651 }
652
653 return nil
654}
655
656type NewIssueOptions struct {
657 Repo *Repository

Callers 1

UpdateIssueAssigneeFunction · 0.80

Implementers 1

mailerIssueinternal/database/issue_mail.go

Calls 8

APIFormatMethod · 0.95
IsErrUserNotExistFunction · 0.85
PrepareWebhooksFunction · 0.85
UsersMethod · 0.80
APIFormatLegacyMethod · 0.80
GetByIDMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected