Skip to content

Commit 4e1448f

Browse files
committed
Use IssueOptions copy method to allow easier add filters in future
1 parent 1380776 commit 4e1448f

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

models/issues/issue_project.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,11 @@ func (issue *Issue) ProjectColumnID(ctx context.Context) int64 {
4949

5050
// LoadIssuesFromColumn load issues assigned to this column
5151
func LoadIssuesFromColumn(ctx context.Context, b *project_model.Column, opts *IssuesOptions) (IssueList, error) {
52-
issueList, err := Issues(ctx, &IssuesOptions{
53-
ProjectColumnID: b.ID,
54-
ProjectID: b.ProjectID,
55-
LabelIDs: opts.LabelIDs,
56-
AssigneeID: opts.AssigneeID,
57-
SortType: "project-column-sorting",
58-
})
52+
issueList, err := Issues(ctx, opts.Copy(func(o *IssuesOptions) {
53+
o.ProjectColumnID = b.ID
54+
o.ProjectID = b.ProjectID
55+
o.SortType = "project-column-sorting"
56+
}))
5957
if err != nil {
6058
return nil, err
6159
}

models/issues/issue_search.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ type IssuesOptions struct { //nolint
5454
User *user_model.User // issues permission scope
5555
}
5656

57+
// Copy returns a copy of the options.
58+
// Be careful, it's not a deep copy, so `IssuesOptions.RepoIDs = {...}` is OK while `IssuesOptions.RepoIDs[0] = ...` is not.
59+
func (o *IssuesOptions) Copy(edit ...func(options *IssuesOptions)) *IssuesOptions {
60+
if o == nil {
61+
return nil
62+
}
63+
v := *o
64+
for _, e := range edit {
65+
e(&v)
66+
}
67+
return &v
68+
}
69+
5770
// applySorts sort an issues-related session based on the provided
5871
// sortType string
5972
func applySorts(sess *xorm.Session, sortType string, priorityRepoID int64) {

0 commit comments

Comments
 (0)