@ -4,6 +4,7 @@
package issue
import (
"context"
"fmt"
activities_model "code.gitea.io/gitea/models/activities"
@ -20,49 +21,49 @@ import (
)
// NewIssue creates new issue with labels for repository.
func NewIssue ( repo * repo_model . Repository , issue * issues_model . Issue , labelIDs [ ] int64 , uuids [ ] string , assigneeIDs [ ] int64 ) error {
func NewIssue ( ctx context . Context , repo * repo_model . Repository , issue * issues_model . Issue , labelIDs [ ] int64 , uuids [ ] string , assigneeIDs [ ] int64 ) error {
if err := issues_model . NewIssue ( repo , issue , labelIDs , uuids ) ; err != nil {
return err
}
for _ , assigneeID := range assigneeIDs {
if err := AddAssigneeIfNotAssigned ( issue, issue . Poster , assigneeID ) ; err != nil {
if err := AddAssigneeIfNotAssigned ( ctx, issue, issue . Poster , assigneeID ) ; err != nil {
return err
}
}
mentions , err := issues_model . FindAndUpdateIssueMentions ( db. DefaultContext , issue , issue . Poster , issue . Content )
mentions , err := issues_model . FindAndUpdateIssueMentions ( ctx , issue , issue . Poster , issue . Content )
if err != nil {
return err
}
notification . NotifyNewIssue ( db. DefaultContext , issue , mentions )
notification . NotifyNewIssue ( ctx , issue , mentions )
if len ( issue . Labels ) > 0 {
notification . NotifyIssueChangeLabels ( db. DefaultContext , issue . Poster , issue , issue . Labels , nil )
notification . NotifyIssueChangeLabels ( ctx , issue . Poster , issue , issue . Labels , nil )
}
if issue . Milestone != nil {
notification . NotifyIssueChangeMilestone ( db. DefaultContext , issue . Poster , issue , 0 )
notification . NotifyIssueChangeMilestone ( ctx , issue . Poster , issue , 0 )
}
return nil
}
// ChangeTitle changes the title of this issue, as the given user.
func ChangeTitle ( issue * issues_model . Issue , doer * user_model . User , title string ) ( err error ) {
func ChangeTitle ( ctx context . Context , issue * issues_model . Issue , doer * user_model . User , title string ) ( err error ) {
oldTitle := issue . Title
issue . Title = title
if err = issues_model . ChangeIssueTitle ( issue, doer , oldTitle ) ; err != nil {
if err = issues_model . ChangeIssueTitle ( ctx, issue, doer , oldTitle ) ; err != nil {
return
}
notification . NotifyIssueChangeTitle ( db. DefaultContext , doer , issue , oldTitle )
notification . NotifyIssueChangeTitle ( ctx , doer , issue , oldTitle )
return nil
}
// ChangeIssueRef changes the branch of this issue, as the given user.
func ChangeIssueRef ( issue * issues_model . Issue , doer * user_model . User , ref string ) error {
func ChangeIssueRef ( ctx context . Context , issue * issues_model . Issue , doer * user_model . User , ref string ) error {
oldRef := issue . Ref
issue . Ref = ref
@ -70,7 +71,7 @@ func ChangeIssueRef(issue *issues_model.Issue, doer *user_model.User, ref string
return err
}
notification . NotifyIssueChangeRef ( db. DefaultContext , doer , issue , oldRef )
notification . NotifyIssueChangeRef ( ctx , doer , issue , oldRef )
return nil
}
@ -81,7 +82,7 @@ func ChangeIssueRef(issue *issues_model.Issue, doer *user_model.User, ref string
// "assignees" (array): Logins for Users to assign to this issue.
// Pass one or more user logins to replace the set of assignees on this Issue.
// Send an empty array ([]) to clear all assignees from the Issue.
func UpdateAssignees ( issue * issues_model . Issue , oneAssignee string , multipleAssignees [ ] string , doer * user_model . User ) ( err error ) {
func UpdateAssignees ( ctx context . Context , issue * issues_model . Issue , oneAssignee string , multipleAssignees [ ] string , doer * user_model . User ) ( err error ) {
var allNewAssignees [ ] * user_model . User
// Keep the old assignee thingy for compatibility reasons
@ -102,7 +103,7 @@ func UpdateAssignees(issue *issues_model.Issue, oneAssignee string, multipleAssi
// Loop through all assignees to add them
for _ , assigneeName := range multipleAssignees {
assignee , err := user_model . GetUserByName ( db. DefaultContext , assigneeName )
assignee , err := user_model . GetUserByName ( ctx , assigneeName )
if err != nil {
return err
}
@ -111,7 +112,7 @@ func UpdateAssignees(issue *issues_model.Issue, oneAssignee string, multipleAssi
}
// Delete all old assignees not passed
if err = DeleteNotPassedAssignee ( issue, doer , allNewAssignees ) ; err != nil {
if err = DeleteNotPassedAssignee ( ctx, issue, doer , allNewAssignees ) ; err != nil {
return err
}
@ -121,7 +122,7 @@ func UpdateAssignees(issue *issues_model.Issue, oneAssignee string, multipleAssi
// has access to the repo.
for _ , assignee := range allNewAssignees {
// Extra method to prevent double adding (which would result in removing)
err = AddAssigneeIfNotAssigned ( issue, doer , assignee . ID )
err = AddAssigneeIfNotAssigned ( ctx, issue, doer , assignee . ID )
if err != nil {
return err
}
@ -131,42 +132,42 @@ func UpdateAssignees(issue *issues_model.Issue, oneAssignee string, multipleAssi
}
// DeleteIssue deletes an issue
func DeleteIssue ( doer * user_model . User , gitRepo * git . Repository , issue * issues_model . Issue ) error {
func DeleteIssue ( ctx context . Context , doer * user_model . User , gitRepo * git . Repository , issue * issues_model . Issue ) error {
// load issue before deleting it
if err := issue . LoadAttributes ( gitRepo. C tx) ; err != nil {
if err := issue . LoadAttributes ( c tx) ; err != nil {
return err
}
if err := issue . LoadPullRequest ( gitRepo. C tx) ; err != nil {
if err := issue . LoadPullRequest ( c tx) ; err != nil {
return err
}
// delete entries in database
if err := deleteIssue ( issue) ; err != nil {
if err := deleteIssue ( ctx, issue) ; err != nil {
return err
}
// delete pull request related git data
if issue . IsPull {
if issue . IsPull && gitRepo != nil {
if err := gitRepo . RemoveReference ( fmt . Sprintf ( "%s%d/head" , git . PullPrefix , issue . PullRequest . Index ) ) ; err != nil {
return err
}
}
notification . NotifyDeleteIssue ( gitRepo. C tx, doer , issue )
notification . NotifyDeleteIssue ( c tx, doer , issue )
return nil
}
// AddAssigneeIfNotAssigned adds an assignee only if he isn't already assigned to the issue.
// Also checks for access of assigned user
func AddAssigneeIfNotAssigned ( issue * issues_model . Issue , doer * user_model . User , assigneeID int64 ) ( err error ) {
assignee , err := user_model . GetUserByID ( db. DefaultContext , assigneeID )
func AddAssigneeIfNotAssigned ( ctx context . Context , issue * issues_model . Issue , doer * user_model . User , assigneeID int64 ) ( err error ) {
assignee , err := user_model . GetUserByID ( ctx , assigneeID )
if err != nil {
return err
}
// Check if the user is already assigned
isAssigned , err := issues_model . IsUserAssignedToIssue ( db. DefaultContext , issue , assignee )
isAssigned , err := issues_model . IsUserAssignedToIssue ( ctx , issue , assignee )
if err != nil {
return err
}
@ -175,7 +176,7 @@ func AddAssigneeIfNotAssigned(issue *issues_model.Issue, doer *user_model.User,
return nil
}
valid , err := access_model . CanBeAssigned ( db. DefaultContext , assignee , issue . Repo , issue . IsPull )
valid , err := access_model . CanBeAssigned ( ctx , assignee , issue . Repo , issue . IsPull )
if err != nil {
return err
}
@ -183,7 +184,7 @@ func AddAssigneeIfNotAssigned(issue *issues_model.Issue, doer *user_model.User,
return repo_model . ErrUserDoesNotHaveAccessToRepo { UserID : assigneeID , RepoName : issue . Repo . Name }
}
_ , _ , err = ToggleAssignee ( issue, doer , assigneeID )
_ , _ , err = ToggleAssignee ( ctx, issue, doer , assigneeID )
if err != nil {
return err
}
@ -206,8 +207,8 @@ func GetRefEndNamesAndURLs(issues []*issues_model.Issue, repoLink string) (map[i
}
// deleteIssue deletes the issue
func deleteIssue ( issue * issues_model . Issue ) error {
ctx , committer , err := db . TxContext ( db. DefaultContext )
func deleteIssue ( ctx context . Context , issue * issues_model . Issue ) error {
ctx , committer , err := db . TxContext ( ctx )
if err != nil {
return err
}