diff --git a/changes.go b/changes.go index 938656d..ee515c8 100644 --- a/changes.go +++ b/changes.go @@ -504,15 +504,12 @@ type QueryOptions struct { // Clients are allowed to specify more than one query by setting the q parameter multiple times. // In this case the result is an array of arrays, one per query in the same order the queries were given in. // - // Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/user-search.html#_search_operators + // Gerrit API docs: https://gerrit-review.googlesource.com/Documentation/user-search.html#search-operators Query []string `url:"q,omitempty"` // The n parameter can be used to limit the returned results. // If the n query parameter is supplied and additional changes exist that match the query beyond the end, the last change object has a _more_changes: true JSON field set. Limit int `url:"n,omitempty"` - - // The S or start query parameter can be supplied to skip a number of changes from the list. - Start int `url:"start,omitempty"` } // QueryChangeOptions specifies the parameters to the ChangesService.QueryChanges. @@ -521,8 +518,7 @@ type QueryOptions struct { type QueryChangeOptions struct { QueryOptions - // The S or start query parameter can be supplied to skip a number of changes from the list. - Skip int `url:"S,omitempty"` + // The `S` or `start` query parameter can be supplied to skip a number of changes from the list. Start int `url:"start,omitempty"` ChangeOptions diff --git a/examples/list_branches_with_pagination/main.go b/examples/list_branches_with_pagination/main.go new file mode 100644 index 0000000..d0ef761 --- /dev/null +++ b/examples/list_branches_with_pagination/main.go @@ -0,0 +1,51 @@ +package main + +import ( + "fmt" + + "github.com/andygrunwald/go-gerrit" +) + +func main() { + instance := "https://gerrit-review.googlesource.com/" + client, err := gerrit.NewClient(instance, nil) + if err != nil { + panic(err) + } + + projectName := "gerrit" + + i := 0 + limit := 2 + skip := 0 + for i < 3 { + // Showcasing pagination + opt := &gerrit.BranchOptions{ + Limit: limit, + Skip: skip, + } + fmt.Printf("ListBranches with skip %d and limit %d\n", skip, limit) + branches, _, err := client.Projects.ListBranches(projectName, opt) + if err != nil { + panic(err) + } + + for _, branch := range *branches { + fmt.Printf("%s -> %s\n", branch.Ref, branch.Revision) + } + + // Raising pagination pointer + i++ + skip += limit + } + + // ListBranches with skip 0 and limit 2 + // HEAD -> master + // refs/meta/config -> 35fc56a537db06bbb9e5bf92f3a3e2e096d4f4c9 + // ListBranches with skip 2 and limit 2 + // refs/heads/infra/config -> 54bf8ddf9bcb4ffc748dd6fead98ececa95c98e5 + // refs/heads/master -> 5f8903effc18583a4796f2adfba13d416f874444 + // ListBranches with skip 4 and limit 2 + // refs/heads/stable-2.10 -> ed2d5cedd8d79ee224fcc2280a6f11e8175fc2b0 + // refs/heads/stable-2.11 -> 854e55ec22dadfc76b1112eb086f0d20dd4a977c +} diff --git a/examples/get_public_projects/main.go b/examples/list_projects/main.go similarity index 100% rename from examples/get_public_projects/main.go rename to examples/list_projects/main.go diff --git a/examples/list_projects_with_pagination/main.go b/examples/list_projects_with_pagination/main.go new file mode 100644 index 0000000..1e6c036 --- /dev/null +++ b/examples/list_projects_with_pagination/main.go @@ -0,0 +1,52 @@ +package main + +import ( + "fmt" + + "github.com/andygrunwald/go-gerrit" +) + +func main() { + instance := "https://gerrit-review.googlesource.com/" + client, err := gerrit.NewClient(instance, nil) + if err != nil { + panic(err) + } + + i := 0 + limit := 2 + skip := 0 + for i < 3 { + // Showcasing pagination + opt := &gerrit.ProjectOptions{ + ProjectBaseOptions: gerrit.ProjectBaseOptions{ + Limit: limit, + Skip: skip, + }, + Description: true, + } + fmt.Printf("ListProjects with skip %d and limit %d\n", skip, limit) + projects, _, err := client.Projects.ListProjects(opt) + if err != nil { + panic(err) + } + + for name, p := range *projects { + fmt.Printf("%s - State: %s\n", name, p.State) + } + + // Raising pagination pointer + i++ + skip += limit + } + + // ListProjects with skip 0 and limit 2 + // Core-Plugins - State: ACTIVE + // Public-Plugins - State: ACTIVE + // ListProjects with skip 2 and limit 2 + // Public-Projects - State: ACTIVE + // TestRepo - State: ACTIVE + // ListProjects with skip 4 and limit 2 + // apps/analytics-etl - State: ACTIVE + // apps/kibana-dashboard - State: ACTIVE +} diff --git a/examples/list_tags_with_pagination/main.go b/examples/list_tags_with_pagination/main.go new file mode 100644 index 0000000..df036a7 --- /dev/null +++ b/examples/list_tags_with_pagination/main.go @@ -0,0 +1,51 @@ +package main + +import ( + "fmt" + + "github.com/andygrunwald/go-gerrit" +) + +func main() { + instance := "https://gerrit-review.googlesource.com/" + client, err := gerrit.NewClient(instance, nil) + if err != nil { + panic(err) + } + + projectName := "gerrit" + + i := 0 + limit := 2 + skip := 0 + for i < 3 { + // Showcasing pagination + opt := &gerrit.ProjectBaseOptions{ + Limit: limit, + Skip: skip, + } + fmt.Printf("ListTags with skip %d and limit %d\n", skip, limit) + tags, _, err := client.Projects.ListTags(projectName, opt) + if err != nil { + panic(err) + } + + for _, tag := range *tags { + fmt.Printf("%s -> %s\n", tag.Message, tag.Ref) + } + + // Raising pagination pointer + i++ + skip += limit + } + + // ListTags with skip 0 and limit 2 + // gerrit 2.0 -> refs/tags/v2.0 + // gerrit 2.0-rc0 -> refs/tags/v2.0-rc0 + // ListTags with skip 2 and limit 2 + // gerrit 2.0.1 -> refs/tags/v2.0.1 + // gerrit 2.0.10 -> refs/tags/v2.0.10 + // ListTags with skip 4 and limit 2 + // gerrit 2.0.11 -> refs/tags/v2.0.11 + // gerrit 2.0.12 -> refs/tags/v2.0.12 +} diff --git a/examples/query_changes/main.go b/examples/query_changes/main.go new file mode 100644 index 0000000..b823f2e --- /dev/null +++ b/examples/query_changes/main.go @@ -0,0 +1,56 @@ +package main + +import ( + "fmt" + + "github.com/andygrunwald/go-gerrit" +) + +func main() { + instance := "https://gerrit-review.googlesource.com/" + client, err := gerrit.NewClient(instance, nil) + if err != nil { + panic(err) + } + + i := 0 + limit := 2 + start := 0 + for i < 3 { + // Showcasing + // - Pagination + // - How to query for a project + opt := &gerrit.QueryChangeOptions{ + QueryOptions: gerrit.QueryOptions{ + Query: []string{ + "project:gerrit", + }, + Limit: limit, + }, + Start: start, + } + fmt.Printf("QueryChanges with start %d and limit %d\n", start, limit) + changes, _, err := client.Changes.QueryChanges(opt) + if err != nil { + panic(err) + } + + for _, changeInfo := range *changes { + fmt.Printf("%+v -> %+v\n", changeInfo.ID, changeInfo.Subject) + } + + // Raising pagination pointer + i++ + start += limit + } + + // QueryChanges with start 0 and limit 2 + // gerrit~stable-3.3~I48896badc4a14927b98fef0311c4a63ba5b2251d -> Allow loading change notes from an existing Repository + // gerrit~master~I644cdc74b679844b21054445e68b3e171e836834 -> Add support for 'is:attention' and 'has:attention' + // QueryChanges with start 2 and limit 2 + // gerrit~master~Id3b9e395c977821f8957180a70de5379402d3621 -> Fix gr-identities "Link Another Identity" button test + // gerrit~stable-3.2~I85db585f9f4799f35dfc0913ec10f473fe08c25a -> Fix serialization of AllUsersName and AllProjectsName + // QueryChanges with start 4 and limit 2 + // gerrit~stable-3.2~Ic6520c1fc44ef51de8bb5d33e307e60ece630163 -> Log the result of git-upload-pack command in httpd_log + // gerrit~stable-3.3~I668e0a322feb09a8dad47233baa6fd9585b4a8a9 -> Do not avertise ALL refs when HEAD is requested +} diff --git a/projects.go b/projects.go index 17afaff..905be21 100644 --- a/projects.go +++ b/projects.go @@ -170,8 +170,8 @@ type ProjectBaseOptions struct { // Limit the number of projects to be included in the results. Limit int `url:"n,omitempty"` - // Skip the given number of branches from the beginning of the list. - Skip string `url:"s,omitempty"` + // Skip the given number of tags from the beginning of the list. + Skip int `url:"S,omitempty"` } // ProjectOptions specifies the parameters to the ProjectsService.ListProjects. @@ -192,9 +192,6 @@ type ProjectOptions struct { // For example: the regex 'test.*' will match any projects that start with 'test' and regex '.*test' will match any project that end with 'test'. Regex string `url:"r,omitempty"` - // Skip the given number of projects from the beginning of the list. - Skip string `url:"S,omitempty"` - // Limit the results to those projects that match the specified substring. Substring string `url:"m,omitempty"` diff --git a/projects_branch.go b/projects_branch.go index 285f20f..3974e1a 100644 --- a/projects_branch.go +++ b/projects_branch.go @@ -32,7 +32,7 @@ type BranchOptions struct { Limit int `url:"n,omitempty"` // Skip the given number of branches from the beginning of the list. - Skip string `url:"s,omitempty"` + Skip int `url:"S,omitempty"` // Substring limits the results to those projects that match the specified substring. Substring string `url:"m,omitempty"`