Ignore subtasks, work around sections.any API bug
This commit is contained in:
@@ -7,6 +7,7 @@ import "strings"
|
|||||||
import "cloud.google.com/go/civil"
|
import "cloud.google.com/go/civil"
|
||||||
|
|
||||||
type SearchQuery struct {
|
type SearchQuery struct {
|
||||||
|
AssigneeAny []*User
|
||||||
SectionsAny []*Section
|
SectionsAny []*Section
|
||||||
Completed *bool
|
Completed *bool
|
||||||
Due *bool
|
Due *bool
|
||||||
@@ -26,11 +27,20 @@ func (wc *WorkspaceClient) Search(q *SearchQuery) ([]*Task, error) {
|
|||||||
path := fmt.Sprintf("workspaces/%s/tasks/search", wc.workspace.GID)
|
path := fmt.Sprintf("workspaces/%s/tasks/search", wc.workspace.GID)
|
||||||
|
|
||||||
values := &url.Values{
|
values := &url.Values{
|
||||||
|
"is_subtask": []string{"false"},
|
||||||
"sort_by": []string{"created_at"},
|
"sort_by": []string{"created_at"},
|
||||||
"sort_ascending": []string{"true"},
|
"sort_ascending": []string{"true"},
|
||||||
}
|
}
|
||||||
|
|
||||||
values.Add("opt_fields", "created_at,due_on,html_notes,name")
|
values.Add("opt_fields", "assignee_section,created_at,due_on,html_notes,name")
|
||||||
|
|
||||||
|
if len(q.AssigneeAny) > 0 {
|
||||||
|
gids := []string{}
|
||||||
|
for _, u := range q.AssigneeAny {
|
||||||
|
gids = append(gids, u.GID)
|
||||||
|
}
|
||||||
|
values.Add("assignee.any", strings.Join(gids, ","))
|
||||||
|
}
|
||||||
|
|
||||||
if len(q.SectionsAny) > 0 {
|
if len(q.SectionsAny) > 0 {
|
||||||
gids := []string{}
|
gids := []string{}
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ type Task struct {
|
|||||||
ParsedDueOn *civil.Date `json:"-"`
|
ParsedDueOn *civil.Date `json:"-"`
|
||||||
HTMLNotes string `json:"html_notes,omitempty"`
|
HTMLNotes string `json:"html_notes,omitempty"`
|
||||||
ParsedHTMLNotes *html.Node `json:"-"`
|
ParsedHTMLNotes *html.Node `json:"-"`
|
||||||
|
AssigneeSection *AssigneeSection `json:"assignee_section"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AssigneeSection struct {
|
||||||
|
GID string `json:"gid,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type taskResponse struct {
|
type taskResponse struct {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import "golang.org/x/net/html/atom"
|
|||||||
|
|
||||||
type queryMutator func(*client.WorkspaceClient, *client.SearchQuery) error
|
type queryMutator func(*client.WorkspaceClient, *client.SearchQuery) error
|
||||||
type taskActor func(*client.WorkspaceClient, *client.Task) error
|
type taskActor func(*client.WorkspaceClient, *client.Task) error
|
||||||
type taskFilter func(*client.WorkspaceClient, *client.Task) (bool, error)
|
type taskFilter func(*client.WorkspaceClient, *client.SearchQuery, *client.Task) (bool, error)
|
||||||
type workspaceClientGetter func(*client.Client) (*client.WorkspaceClient, error)
|
type workspaceClientGetter func(*client.Client) (*client.WorkspaceClient, error)
|
||||||
|
|
||||||
type periodic struct {
|
type periodic struct {
|
||||||
@@ -54,6 +54,13 @@ func InWorkspace(name string) *periodic {
|
|||||||
// Query mutators
|
// Query mutators
|
||||||
func (p *periodic) InMyTasksSections(names ...string) *periodic {
|
func (p *periodic) InMyTasksSections(names ...string) *periodic {
|
||||||
p.queryMutators = append(p.queryMutators, func(wc *client.WorkspaceClient, q *client.SearchQuery) error {
|
p.queryMutators = append(p.queryMutators, func(wc *client.WorkspaceClient, q *client.SearchQuery) error {
|
||||||
|
u, err := wc.GetMe()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
q.AssigneeAny = append(q.AssigneeAny, u)
|
||||||
|
|
||||||
utl, err := wc.GetMyUserTaskList()
|
utl, err := wc.GetMyUserTaskList()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -76,6 +83,18 @@ func (p *periodic) InMyTasksSections(names ...string) *periodic {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Backup filter if the API misbehaves
|
||||||
|
// Asana issue #600801
|
||||||
|
p.taskFilters = append(p.taskFilters, func(wc *client.WorkspaceClient, q *client.SearchQuery, t *client.Task) (bool, error) {
|
||||||
|
for _, sec := range q.SectionsAny {
|
||||||
|
if sec.GID == t.AssigneeSection.GID {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false, nil
|
||||||
|
})
|
||||||
|
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,7 +223,7 @@ func (p *periodic) WithoutTagsAnyOf(names ...string) *periodic {
|
|||||||
|
|
||||||
// Task filters
|
// Task filters
|
||||||
func (p *periodic) WithUnlinkedURL() *periodic {
|
func (p *periodic) WithUnlinkedURL() *periodic {
|
||||||
p.taskFilters = append(p.taskFilters, func(wc *client.WorkspaceClient, t *client.Task) (bool, error) {
|
p.taskFilters = append(p.taskFilters, func(wc *client.WorkspaceClient, _ *client.SearchQuery, t *client.Task) (bool, error) {
|
||||||
return hasUnlinkedURL(t.ParsedHTMLNotes), nil
|
return hasUnlinkedURL(t.ParsedHTMLNotes), nil
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -213,7 +232,7 @@ func (p *periodic) WithUnlinkedURL() *periodic {
|
|||||||
|
|
||||||
func (p *periodic) WithoutDue() *periodic {
|
func (p *periodic) WithoutDue() *periodic {
|
||||||
// We can't mutate the query because due_on=null is buggy in the Asana API
|
// We can't mutate the query because due_on=null is buggy in the Asana API
|
||||||
p.taskFilters = append(p.taskFilters, func(wc *client.WorkspaceClient, t *client.Task) (bool, error) {
|
p.taskFilters = append(p.taskFilters, func(wc *client.WorkspaceClient, _ *client.SearchQuery, t *client.Task) (bool, error) {
|
||||||
return t.ParsedDueOn == nil, nil
|
return t.ParsedDueOn == nil, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -327,7 +346,7 @@ func (p *periodic) exec(c *client.Client) error {
|
|||||||
included := true
|
included := true
|
||||||
|
|
||||||
for _, filter := range p.taskFilters {
|
for _, filter := range p.taskFilters {
|
||||||
include, err := filter(wc, task)
|
include, err := filter(wc, q, task)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user