1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

WTF-781 Todoist project ID conversion (#789)

* WTF-781 Switch Todoist IDs from `int` to `string`

On platforms that convert an `int` to `int32`, like the Raspberry Pi,
an `int` is not large enough to store Todoist project IDs.

Using a `string` ensures this never becomes a problem.

Fixes #781

Signed-off-by: Chris Cummer <chriscummer@me.com>
This commit is contained in:
Chris Cummer 2019-12-16 20:25:52 -08:00 committed by GitHub
parent 3a388fba23
commit 140dd553e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 74 additions and 15 deletions

2
go.mod
View File

@ -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

4
go.sum
View File

@ -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=

View File

@ -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)

View File

@ -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

View File

@ -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
}

View File

@ -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))
}

View File

@ -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 {

View File

@ -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"`
@ -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 {

2
vendor/modules.txt vendored
View File

@ -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