diff --git a/go.mod b/go.mod index c5f9ccf0..78c45881 100644 --- a/go.mod +++ b/go.mod @@ -46,7 +46,7 @@ require ( github.com/shirou/gopsutil v2.19.11+incompatible github.com/stretchr/testify v1.4.0 github.com/wtfutil/spotigopher v0.0.0-20191127141047-7d8168fe103a - github.com/wtfutil/todoist v0.0.1 + github.com/wtfutil/todoist v0.0.2-0.20191216004217-0ec29ceda61a github.com/xanzy/go-gitlab v0.22.2 github.com/zmb3/spotify v0.0.0-20191010212056-e12fb981aacb github.com/zorkian/go-datadog-api v2.25.0+incompatible diff --git a/go.sum b/go.sum index a467b8e0..fc86fa9e 100644 --- a/go.sum +++ b/go.sum @@ -250,8 +250,8 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= github.com/wtfutil/spotigopher v0.0.0-20191127141047-7d8168fe103a h1:2eyMT9EpTPS4PiVfvXvqA8PKB5FoSl6gGjgb3CQ0cug= github.com/wtfutil/spotigopher v0.0.0-20191127141047-7d8168fe103a/go.mod h1:AlO4kKlF1zyOHTq2pBzxEERdBDStJev0VZNukFEqz/E= -github.com/wtfutil/todoist v0.0.1 h1:E3srzocggLHme8zIEAEXXoY/fQZtFRjW69m4OiYv3hg= -github.com/wtfutil/todoist v0.0.1/go.mod h1:YuuGLJSsTK6DGBD5Zaf3J8LSMfpEC2WtzYPey3XVOdI= +github.com/wtfutil/todoist v0.0.2-0.20191216004217-0ec29ceda61a h1:nD8ALd4TSo+zPHK5MqQWFj01G8fMMHFfC3rWvoq/9JA= +github.com/wtfutil/todoist v0.0.2-0.20191216004217-0ec29ceda61a/go.mod h1:YuuGLJSsTK6DGBD5Zaf3J8LSMfpEC2WtzYPey3XVOdI= github.com/xanzy/go-gitlab v0.22.2 h1:KYPewSm3Tl7WHrVON7BOwX6FZ1gaiFEdpOt0DNIYySA= github.com/xanzy/go-gitlab v0.22.2/go.mod h1:t4Bmvnxj7k37S4Y17lfLx+nLqkf/oQwT2HagfWKv5Og= github.com/zmb3/spotify v0.0.0-20191010212056-e12fb981aacb h1:uWB0RGxBo7AToSJ3rvoCZhXtLw4U7XISXSezPewmfic= diff --git a/modules/todoist/project.go b/modules/todoist/project.go index 6a295299..ae2919c4 100644 --- a/modules/todoist/project.go +++ b/modules/todoist/project.go @@ -14,7 +14,7 @@ type Project struct { err error } -func NewProject(id int) *Project { +func NewProject(id uint) *Project { // Todoist seems to experience a lot of network issues on their side // If we can't connect, handle it with an empty project until we can project, err := todoist.GetProject(id) diff --git a/modules/todoist/settings.go b/modules/todoist/settings.go index ae554d70..308bf5cc 100644 --- a/modules/todoist/settings.go +++ b/modules/todoist/settings.go @@ -18,7 +18,7 @@ type Settings struct { common *cfg.Common apiKey string `help:"Your Todoist API key"` - projects []int + projects []uint } // NewSettingsFromYAML creates a new settings instance from a YAML config block @@ -27,7 +27,7 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig), apiKey: ymlConfig.UString("apiKey", ymlConfig.UString("apikey", os.Getenv("WTF_TODOIST_TOKEN"))), - projects: utils.ToInts(ymlConfig.UList("projects")), + projects: utils.IntsToUints(utils.ToInts(ymlConfig.UList("projects"))), } return &settings diff --git a/utils/conversions.go b/utils/conversions.go index 133ddb5d..ed6405d1 100644 --- a/utils/conversions.go +++ b/utils/conversions.go @@ -19,6 +19,17 @@ func MapToStrs(aMap map[string]interface{}) map[string]string { /* -------------------- Slice Conversion -------------------- */ +// IntsToUints takes a slice of ints and returns a slice of uints +func IntsToUints(slice []int) []uint { + results := make([]uint, len(slice)) + + for i, val := range slice { + results[i] = uint(val) + } + + return results +} + // ToInts takes a slice of interfaces and returns a slice of ints func ToInts(slice []interface{}) []int { results := make([]int, len(slice)) @@ -45,3 +56,14 @@ func ToStrs(slice []interface{}) []string { return results } + +// ToUints takes a slice of interfaces and returns a slice of ints +func ToUints(slice []interface{}) []uint { + results := make([]uint, len(slice)) + + for i, val := range slice { + results[i] = val.(uint) + } + + return results +} diff --git a/utils/conversions_test.go b/utils/conversions_test.go index 12af7f2c..06f1f44f 100644 --- a/utils/conversions_test.go +++ b/utils/conversions_test.go @@ -21,6 +21,32 @@ func Test_MapToStrs(t *testing.T) { assert.Equal(t, expected, MapToStrs(source)) } +func Test_IntsToUints(t *testing.T) { + tests := []struct { + name string + src []int + expected []uint + }{ + { + name: "empty set", + src: []int{}, + expected: []uint{}, + }, + { + name: "full set", + src: []int{1, 2, 3}, + expected: []uint{1, 2, 3}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + actual := IntsToUints(tt.src) + assert.Equal(t, tt.expected, actual) + }) + } +} + func Test_ToInts(t *testing.T) { expected := []int{1, 2, 3} @@ -49,3 +75,14 @@ func Test_ToStrs(t *testing.T) { assert.Equal(t, expectedStrs, ToStrs(fromInts)) assert.Equal(t, expectedStrs, ToStrs(fromStrs)) } + +func Test_ToUints(t *testing.T) { + expected := []uint{1, 2, 3} + + source := make([]interface{}, len(expected)) + for idx, val := range expected { + source[idx] = val + } + + assert.Equal(t, expected, ToUints(source)) +} diff --git a/vendor/github.com/wtfutil/todoist/projects.go b/vendor/github.com/wtfutil/todoist/projects.go index 9493b18a..8ce2ae58 100644 --- a/vendor/github.com/wtfutil/todoist/projects.go +++ b/vendor/github.com/wtfutil/todoist/projects.go @@ -9,7 +9,7 @@ import ( // Project is a model of todoist project entity type Project struct { - ID int `json:"id"` + ID uint `json:"id"` Name string `json:"name"` CommentCount int `json:"comment_count"` Order int `json:"order"` @@ -62,7 +62,7 @@ func ListProject() ([]Project, error) { // panic(err) // } // fmt.Println(project) -func GetProject(id int) (Project, error) { +func GetProject(id uint) (Project, error) { path := fmt.Sprintf("projects/%d", id) res, err := makeRequest(http.MethodGet, path, nil) if err != nil { diff --git a/vendor/github.com/wtfutil/todoist/task.go b/vendor/github.com/wtfutil/todoist/task.go index 8fbe56ad..8ccce0c4 100644 --- a/vendor/github.com/wtfutil/todoist/task.go +++ b/vendor/github.com/wtfutil/todoist/task.go @@ -10,7 +10,7 @@ import ( // Task is a model of todoist project entity type Task struct { - ID int `json:"id"` + ID uint `json:"id"` CommentCount int `json:"comment_count"` Completed bool `json:"completed"` Content string `json:"content"` @@ -24,10 +24,10 @@ type Task struct { // Due is a model of todoist project entity type Due struct { - String string `json:"string"` - Date string `json:"date"` - Datetime time.Time `json:"datetime,omitempty"` - Timezone string `json:"timezone"` + String string `json:"string"` + Date string `json:"date"` + Datetime time.Time `json:"datetime,omitempty"` + Timezone string `json:"timezone"` } func (t Task) taskSave() taskSave { @@ -94,7 +94,7 @@ func ListTask(qp QueryParam) ([]Task, error) { } // GetTask return a task by id -func GetTask(id int) (Task, error) { +func GetTask(id uint) (Task, error) { path := fmt.Sprintf("tasks/%d", id) res, err := makeRequest(http.MethodGet, path, nil) if err != nil { diff --git a/vendor/modules.txt b/vendor/modules.txt index 223c8064..168f80b7 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -264,7 +264,7 @@ github.com/spf13/pflag github.com/stretchr/testify/assert # github.com/wtfutil/spotigopher v0.0.0-20191127141047-7d8168fe103a github.com/wtfutil/spotigopher/spotigopher -# github.com/wtfutil/todoist v0.0.1 +# github.com/wtfutil/todoist v0.0.2-0.20191216004217-0ec29ceda61a github.com/wtfutil/todoist # github.com/xanzy/go-gitlab v0.22.2 github.com/xanzy/go-gitlab