Skip to content

Commit

Permalink
Use IssueOptions copy method to allow easier add filters in future
Browse files Browse the repository at this point in the history
  • Loading branch information
lafriks committed Sep 6, 2024
1 parent 1380776 commit 4e1448f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
12 changes: 5 additions & 7 deletions models/issues/issue_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ func (issue *Issue) ProjectColumnID(ctx context.Context) int64 {

// LoadIssuesFromColumn load issues assigned to this column
func LoadIssuesFromColumn(ctx context.Context, b *project_model.Column, opts *IssuesOptions) (IssueList, error) {
issueList, err := Issues(ctx, &IssuesOptions{
ProjectColumnID: b.ID,
ProjectID: b.ProjectID,
LabelIDs: opts.LabelIDs,
AssigneeID: opts.AssigneeID,
SortType: "project-column-sorting",
})
issueList, err := Issues(ctx, opts.Copy(func(o *IssuesOptions) {
o.ProjectColumnID = b.ID
o.ProjectID = b.ProjectID
o.SortType = "project-column-sorting"
}))
if err != nil {
return nil, err
}
Expand Down
13 changes: 13 additions & 0 deletions models/issues/issue_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ type IssuesOptions struct { //nolint
User *user_model.User // issues permission scope
}

// Copy returns a copy of the options.
// Be careful, it's not a deep copy, so `IssuesOptions.RepoIDs = {...}` is OK while `IssuesOptions.RepoIDs[0] = ...` is not.
func (o *IssuesOptions) Copy(edit ...func(options *IssuesOptions)) *IssuesOptions {
if o == nil {
return nil
}
v := *o
for _, e := range edit {
e(&v)
}
return &v
}

// applySorts sort an issues-related session based on the provided
// sortType string
func applySorts(sess *xorm.Session, sortType string, priorityRepoID int64) {
Expand Down

0 comments on commit 4e1448f

Please sign in to comment.