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:
parent
3a388fba23
commit
140dd553e0
2
go.mod
2
go.mod
@ -46,7 +46,7 @@ require (
|
|||||||
github.com/shirou/gopsutil v2.19.11+incompatible
|
github.com/shirou/gopsutil v2.19.11+incompatible
|
||||||
github.com/stretchr/testify v1.4.0
|
github.com/stretchr/testify v1.4.0
|
||||||
github.com/wtfutil/spotigopher v0.0.0-20191127141047-7d8168fe103a
|
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/xanzy/go-gitlab v0.22.2
|
||||||
github.com/zmb3/spotify v0.0.0-20191010212056-e12fb981aacb
|
github.com/zmb3/spotify v0.0.0-20191010212056-e12fb981aacb
|
||||||
github.com/zorkian/go-datadog-api v2.25.0+incompatible
|
github.com/zorkian/go-datadog-api v2.25.0+incompatible
|
||||||
|
4
go.sum
4
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/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 h1:2eyMT9EpTPS4PiVfvXvqA8PKB5FoSl6gGjgb3CQ0cug=
|
||||||
github.com/wtfutil/spotigopher v0.0.0-20191127141047-7d8168fe103a/go.mod h1:AlO4kKlF1zyOHTq2pBzxEERdBDStJev0VZNukFEqz/E=
|
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.2-0.20191216004217-0ec29ceda61a h1:nD8ALd4TSo+zPHK5MqQWFj01G8fMMHFfC3rWvoq/9JA=
|
||||||
github.com/wtfutil/todoist v0.0.1/go.mod h1:YuuGLJSsTK6DGBD5Zaf3J8LSMfpEC2WtzYPey3XVOdI=
|
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 h1:KYPewSm3Tl7WHrVON7BOwX6FZ1gaiFEdpOt0DNIYySA=
|
||||||
github.com/xanzy/go-gitlab v0.22.2/go.mod h1:t4Bmvnxj7k37S4Y17lfLx+nLqkf/oQwT2HagfWKv5Og=
|
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=
|
github.com/zmb3/spotify v0.0.0-20191010212056-e12fb981aacb h1:uWB0RGxBo7AToSJ3rvoCZhXtLw4U7XISXSezPewmfic=
|
||||||
|
@ -14,7 +14,7 @@ type Project struct {
|
|||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewProject(id int) *Project {
|
func NewProject(id uint) *Project {
|
||||||
// Todoist seems to experience a lot of network issues on their side
|
// 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
|
// If we can't connect, handle it with an empty project until we can
|
||||||
project, err := todoist.GetProject(id)
|
project, err := todoist.GetProject(id)
|
||||||
|
@ -18,7 +18,7 @@ type Settings struct {
|
|||||||
common *cfg.Common
|
common *cfg.Common
|
||||||
|
|
||||||
apiKey string `help:"Your Todoist API key"`
|
apiKey string `help:"Your Todoist API key"`
|
||||||
projects []int
|
projects []uint
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSettingsFromYAML creates a new settings instance from a YAML config block
|
// 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),
|
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
|
||||||
|
|
||||||
apiKey: ymlConfig.UString("apiKey", ymlConfig.UString("apikey", os.Getenv("WTF_TODOIST_TOKEN"))),
|
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
|
return &settings
|
||||||
|
@ -19,6 +19,17 @@ func MapToStrs(aMap map[string]interface{}) map[string]string {
|
|||||||
|
|
||||||
/* -------------------- Slice Conversion -------------------- */
|
/* -------------------- 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
|
// ToInts takes a slice of interfaces and returns a slice of ints
|
||||||
func ToInts(slice []interface{}) []int {
|
func ToInts(slice []interface{}) []int {
|
||||||
results := make([]int, len(slice))
|
results := make([]int, len(slice))
|
||||||
@ -45,3 +56,14 @@ func ToStrs(slice []interface{}) []string {
|
|||||||
|
|
||||||
return results
|
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
|
||||||
|
}
|
||||||
|
@ -21,6 +21,32 @@ func Test_MapToStrs(t *testing.T) {
|
|||||||
assert.Equal(t, expected, MapToStrs(source))
|
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) {
|
func Test_ToInts(t *testing.T) {
|
||||||
expected := []int{1, 2, 3}
|
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(fromInts))
|
||||||
assert.Equal(t, expectedStrs, ToStrs(fromStrs))
|
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))
|
||||||
|
}
|
||||||
|
4
vendor/github.com/wtfutil/todoist/projects.go
generated
vendored
4
vendor/github.com/wtfutil/todoist/projects.go
generated
vendored
@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
// Project is a model of todoist project entity
|
// Project is a model of todoist project entity
|
||||||
type Project struct {
|
type Project struct {
|
||||||
ID int `json:"id"`
|
ID uint `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
CommentCount int `json:"comment_count"`
|
CommentCount int `json:"comment_count"`
|
||||||
Order int `json:"order"`
|
Order int `json:"order"`
|
||||||
@ -62,7 +62,7 @@ func ListProject() ([]Project, error) {
|
|||||||
// panic(err)
|
// panic(err)
|
||||||
// }
|
// }
|
||||||
// fmt.Println(project)
|
// fmt.Println(project)
|
||||||
func GetProject(id int) (Project, error) {
|
func GetProject(id uint) (Project, error) {
|
||||||
path := fmt.Sprintf("projects/%d", id)
|
path := fmt.Sprintf("projects/%d", id)
|
||||||
res, err := makeRequest(http.MethodGet, path, nil)
|
res, err := makeRequest(http.MethodGet, path, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
12
vendor/github.com/wtfutil/todoist/task.go
generated
vendored
12
vendor/github.com/wtfutil/todoist/task.go
generated
vendored
@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
// Task is a model of todoist project entity
|
// Task is a model of todoist project entity
|
||||||
type Task struct {
|
type Task struct {
|
||||||
ID int `json:"id"`
|
ID uint `json:"id"`
|
||||||
CommentCount int `json:"comment_count"`
|
CommentCount int `json:"comment_count"`
|
||||||
Completed bool `json:"completed"`
|
Completed bool `json:"completed"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
@ -24,10 +24,10 @@ type Task struct {
|
|||||||
|
|
||||||
// Due is a model of todoist project entity
|
// Due is a model of todoist project entity
|
||||||
type Due struct {
|
type Due struct {
|
||||||
String string `json:"string"`
|
String string `json:"string"`
|
||||||
Date string `json:"date"`
|
Date string `json:"date"`
|
||||||
Datetime time.Time `json:"datetime,omitempty"`
|
Datetime time.Time `json:"datetime,omitempty"`
|
||||||
Timezone string `json:"timezone"`
|
Timezone string `json:"timezone"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Task) taskSave() taskSave {
|
func (t Task) taskSave() taskSave {
|
||||||
@ -94,7 +94,7 @@ func ListTask(qp QueryParam) ([]Task, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetTask return a task by id
|
// GetTask return a task by id
|
||||||
func GetTask(id int) (Task, error) {
|
func GetTask(id uint) (Task, error) {
|
||||||
path := fmt.Sprintf("tasks/%d", id)
|
path := fmt.Sprintf("tasks/%d", id)
|
||||||
res, err := makeRequest(http.MethodGet, path, nil)
|
res, err := makeRequest(http.MethodGet, path, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@ -264,7 +264,7 @@ github.com/spf13/pflag
|
|||||||
github.com/stretchr/testify/assert
|
github.com/stretchr/testify/assert
|
||||||
# github.com/wtfutil/spotigopher v0.0.0-20191127141047-7d8168fe103a
|
# github.com/wtfutil/spotigopher v0.0.0-20191127141047-7d8168fe103a
|
||||||
github.com/wtfutil/spotigopher/spotigopher
|
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/wtfutil/todoist
|
||||||
# github.com/xanzy/go-gitlab v0.22.2
|
# github.com/xanzy/go-gitlab v0.22.2
|
||||||
github.com/xanzy/go-gitlab
|
github.com/xanzy/go-gitlab
|
||||||
|
Loading…
x
Reference in New Issue
Block a user