aboutsummaryrefslogtreecommitdiffstats
path: root/services/issue
diff options
context:
space:
mode:
Diffstat (limited to 'services/issue')
-rw-r--r--services/issue/label.go32
-rw-r--r--services/issue/label_test.go5
2 files changed, 20 insertions, 17 deletions
diff --git a/services/issue/label.go b/services/issue/label.go
index f830aab0e7..91f0308d9f 100644
--- a/services/issue/label.go
+++ b/services/issue/label.go
@@ -4,6 +4,8 @@
package issue
import (
+ "context"
+
"code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
access_model "code.gitea.io/gitea/models/perm/access"
@@ -12,49 +14,49 @@ import (
)
// ClearLabels clears all of an issue's labels
-func ClearLabels(issue *issues_model.Issue, doer *user_model.User) error {
+func ClearLabels(ctx context.Context, issue *issues_model.Issue, doer *user_model.User) error {
if err := issues_model.ClearIssueLabels(issue, doer); err != nil {
return err
}
- notify_service.IssueClearLabels(db.DefaultContext, doer, issue)
+ notify_service.IssueClearLabels(ctx, doer, issue)
return nil
}
// AddLabel adds a new label to the issue.
-func AddLabel(issue *issues_model.Issue, doer *user_model.User, label *issues_model.Label) error {
+func AddLabel(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, label *issues_model.Label) error {
if err := issues_model.NewIssueLabel(issue, label, doer); err != nil {
return err
}
- notify_service.IssueChangeLabels(db.DefaultContext, doer, issue, []*issues_model.Label{label}, nil)
+ notify_service.IssueChangeLabels(ctx, doer, issue, []*issues_model.Label{label}, nil)
return nil
}
// AddLabels adds a list of new labels to the issue.
-func AddLabels(issue *issues_model.Issue, doer *user_model.User, labels []*issues_model.Label) error {
+func AddLabels(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, labels []*issues_model.Label) error {
if err := issues_model.NewIssueLabels(issue, labels, doer); err != nil {
return err
}
- notify_service.IssueChangeLabels(db.DefaultContext, doer, issue, labels, nil)
+ notify_service.IssueChangeLabels(ctx, doer, issue, labels, nil)
return nil
}
// RemoveLabel removes a label from issue by given ID.
-func RemoveLabel(issue *issues_model.Issue, doer *user_model.User, label *issues_model.Label) error {
- ctx, committer, err := db.TxContext(db.DefaultContext)
+func RemoveLabel(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, label *issues_model.Label) error {
+ dbCtx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
defer committer.Close()
- if err := issue.LoadRepo(ctx); err != nil {
+ if err := issue.LoadRepo(dbCtx); err != nil {
return err
}
- perm, err := access_model.GetUserRepoPermission(ctx, issue.Repo, doer)
+ perm, err := access_model.GetUserRepoPermission(dbCtx, issue.Repo, doer)
if err != nil {
return err
}
@@ -65,7 +67,7 @@ func RemoveLabel(issue *issues_model.Issue, doer *user_model.User, label *issues
return issues_model.ErrRepoLabelNotExist{}
}
- if err := issues_model.DeleteIssueLabel(ctx, issue, label, doer); err != nil {
+ if err := issues_model.DeleteIssueLabel(dbCtx, issue, label, doer); err != nil {
return err
}
@@ -73,13 +75,13 @@ func RemoveLabel(issue *issues_model.Issue, doer *user_model.User, label *issues
return err
}
- notify_service.IssueChangeLabels(db.DefaultContext, doer, issue, nil, []*issues_model.Label{label})
+ notify_service.IssueChangeLabels(ctx, doer, issue, nil, []*issues_model.Label{label})
return nil
}
// ReplaceLabels removes all current labels and add new labels to the issue.
-func ReplaceLabels(issue *issues_model.Issue, doer *user_model.User, labels []*issues_model.Label) error {
- old, err := issues_model.GetLabelsByIssueID(db.DefaultContext, issue.ID)
+func ReplaceLabels(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, labels []*issues_model.Label) error {
+ old, err := issues_model.GetLabelsByIssueID(ctx, issue.ID)
if err != nil {
return err
}
@@ -88,6 +90,6 @@ func ReplaceLabels(issue *issues_model.Issue, doer *user_model.User, labels []*i
return err
}
- notify_service.IssueChangeLabels(db.DefaultContext, doer, issue, labels, old)
+ notify_service.IssueChangeLabels(ctx, doer, issue, labels, old)
return nil
}
diff --git a/services/issue/label_test.go b/services/issue/label_test.go
index af220601f1..90608c9e26 100644
--- a/services/issue/label_test.go
+++ b/services/issue/label_test.go
@@ -6,6 +6,7 @@ package issue
import (
"testing"
+ "code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
@@ -32,7 +33,7 @@ func TestIssue_AddLabels(t *testing.T) {
labels[i] = unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: labelID})
}
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: test.doerID})
- assert.NoError(t, AddLabels(issue, doer, labels))
+ assert.NoError(t, AddLabels(db.DefaultContext, issue, doer, labels))
for _, labelID := range test.labelIDs {
unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: test.issueID, LabelID: labelID})
}
@@ -55,7 +56,7 @@ func TestIssue_AddLabel(t *testing.T) {
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: test.issueID})
label := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: test.labelID})
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: test.doerID})
- assert.NoError(t, AddLabel(issue, doer, label))
+ assert.NoError(t, AddLabel(db.DefaultContext, issue, doer, label))
unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: test.issueID, LabelID: test.labelID})
}
}