-
-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Projects list #46
Comments
And in issue.go : |
Currently, I don't have an environment to test this but could you please check this patch? diff --git a/project.go b/project.go
index 3afab73..d48b880 100644
--- a/project.go
+++ b/project.go
@@ -17,7 +17,10 @@ type projectResult struct {
}
type projectsResult struct {
- Projects []Project `json:"projects"`
+ Projects []Project `json:"projects"`
+ TotalCount uint `json:"total_count"`
+ Offset uint `json:"offset"`
+ Limit uint `json:"limit"`
}
type Project struct {
@@ -55,8 +58,9 @@ func (c *Client) Project(id int) (*Project, error) {
return &r.Project, nil
}
-func (c *Client) Projects() ([]Project, error) {
- res, err := c.Get(c.endpoint + "/projects.json?key=" + c.apikey + c.getPaginationClause())
+func getProject(c *Client, url string, offset int) (*projectsResult, error) {
+ res, err := c.Get(c.endpoint + url + "&offset=" + strconv.Itoa(offset))
+
if err != nil {
return nil, err
}
@@ -76,7 +80,49 @@ func (c *Client) Projects() ([]Project, error) {
if err != nil {
return nil, err
}
- return r.Projects, nil
+
+ return &r, nil
+}
+
+func getProjects(c *Client, url string) ([]Project, error) {
+ completed := false
+ var projects []Project
+
+ for completed == false {
+ r, err := getProject(c, url, len(projects))
+
+ if err != nil {
+ return nil, err
+ }
+
+ if r.TotalCount == uint(len(projects)) {
+ completed = true
+ }
+
+ projects = append(projects, r.Projects...)
+ }
+
+ return projects, nil
+}
+
+func (c *Client) Projects() ([]Project, error) {
+ completed := false
+ var projects []Project
+
+ for completed == false {
+ r, err := getProject(c, "/projects.json?key="+c.apikey+c.getPaginationClause(), len(projects))
+
+ if err != nil {
+ return nil, err
+ }
+
+ if r.TotalCount == uint(len(projects)) {
+ completed = true
+ }
+
+ projects = append(projects, r.Projects...)
+ }
+ return projects, nil
}
func (c *Client) CreateProject(project Project) (*Project, error) { |
Please, check this one:
You check length of result array before appending new result. So you make one empty request. |
Hello!
I looked your code for listing projects, and, if i understand correct, you don't check, if number of projects is more than limit (default or set in const).
I looked in
godmine/main.go#L456
and
project.go#L58
but didn't find any checks, like in issues:
issue.go#L369
I hope i wrong, correct me if yes.
Have a good day!
The text was updated successfully, but these errors were encountered: