Commit 0925bd84 authored by Sander van Harmelen's avatar Sander van Harmelen

Merge pull request #18 from martinsefcik/pagination

Added pagination parameters for all API calls where it is supported
parents 4b8992ab 381bae9f
...@@ -54,6 +54,7 @@ func (c Commit) String() string { ...@@ -54,6 +54,7 @@ func (c Commit) String() string {
// //
// GitLab API docs: http://doc.gitlab.com/ce/api/commits.html#list-commits // GitLab API docs: http://doc.gitlab.com/ce/api/commits.html#list-commits
type ListCommitsOptions struct { type ListCommitsOptions struct {
ListOptions
RefName string `url:"ref_name,omitempty"` RefName string `url:"ref_name,omitempty"`
} }
......
...@@ -35,7 +35,7 @@ func projectExample() { ...@@ -35,7 +35,7 @@ func projectExample() {
} }
// List all project snippets // List all project snippets
snippets, _, err := git.ProjectSnippets.ListSnippits(project.PathWithNamespace) snippets, _, err := git.ProjectSnippets.ListSnippets(project.PathWithNamespace, &gitlab.ListSnippetsOptions{})
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
......
...@@ -40,12 +40,20 @@ type Group struct { ...@@ -40,12 +40,20 @@ type Group struct {
Projects *[]Project `json:"projects,omitempty"` Projects *[]Project `json:"projects,omitempty"`
} }
// ListGroupsOptions represents the available ListGroups() options.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/groups.html#list-project-groups
type ListGroupsOptions struct {
ListOptions
Search string `url:"search,omitempty"`
}
// ListGroups gets a list of groups. (As user: my groups, as admin: all groups) // ListGroups gets a list of groups. (As user: my groups, as admin: all groups)
// //
// GitLab API docs: // GitLab API docs:
// http://doc.gitlab.com/ce/api/groups.html#list-project-groups // http://doc.gitlab.com/ce/api/groups.html#list-project-groups
func (s *GroupsService) ListGroups() ([]*Group, *Response, error) { func (s *GroupsService) ListGroups(opt *ListGroupsOptions) ([]*Group, *Response, error) {
req, err := s.client.NewRequest("GET", "groups", nil) req, err := s.client.NewRequest("GET", "groups", opt)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
......
...@@ -320,6 +320,15 @@ func (m MergeRequestComment) String() string { ...@@ -320,6 +320,15 @@ func (m MergeRequestComment) String() string {
return Stringify(m) return Stringify(m)
} }
// GetMergeRequestCommentsOptions represents the available GetMergeRequestComments()
// options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/merge_requests.html#get-the-comments-on-a-mr
type GetMergeRequestCommentsOptions struct {
ListOptions
}
// GetMergeRequestComments gets all the comments associated with a merge // GetMergeRequestComments gets all the comments associated with a merge
// request. // request.
// //
...@@ -327,14 +336,15 @@ func (m MergeRequestComment) String() string { ...@@ -327,14 +336,15 @@ func (m MergeRequestComment) String() string {
// http://doc.gitlab.com/ce/api/merge_requests.html#get-the-comments-on-a-mr // http://doc.gitlab.com/ce/api/merge_requests.html#get-the-comments-on-a-mr
func (s *MergeRequestsService) GetMergeRequestComments( func (s *MergeRequestsService) GetMergeRequestComments(
pid interface{}, pid interface{},
mergeRequest int) ([]*MergeRequestComment, *Response, error) { mergeRequest int,
opt *GetMergeRequestCommentsOptions) ([]*MergeRequestComment, *Response, error) {
project, err := parseID(pid) project, err := parseID(pid)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
u := fmt.Sprintf("projects/%s/merge_request/%d/comments", url.QueryEscape(project), mergeRequest) u := fmt.Sprintf("projects/%s/merge_request/%d/comments", url.QueryEscape(project), mergeRequest)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, opt)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
......
...@@ -54,6 +54,7 @@ func (m Milestone) String() string { ...@@ -54,6 +54,7 @@ func (m Milestone) String() string {
// GitLab API docs: // GitLab API docs:
// http://doc.gitlab.com/ce/api/milestones.html#list-project-milestones // http://doc.gitlab.com/ce/api/milestones.html#list-project-milestones
type ListMilestonesOptions struct { type ListMilestonesOptions struct {
ListOptions
IID int `url:"iid,omitempty"` IID int `url:"iid,omitempty"`
} }
...@@ -187,20 +188,29 @@ func (s *MilestonesService) UpdateMilestone( ...@@ -187,20 +188,29 @@ func (s *MilestonesService) UpdateMilestone(
return m, resp, err return m, resp, err
} }
// GetMilestoneIssuesOptions represents the available GetMilestoneIssues() options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/milestones.html#get-all-issues-assigned-to-a-single-milestone
type GetMilestoneIssuesOptions struct {
ListOptions
}
// GetMilestoneIssues gets all issues assigned to a single project milestone. // GetMilestoneIssues gets all issues assigned to a single project milestone.
// //
// GitLab API docs: // GitLab API docs:
// http://doc.gitlab.com/ce/api/milestones.html#get-all-issues-assigned-to-a-single-milestone // http://doc.gitlab.com/ce/api/milestones.html#get-all-issues-assigned-to-a-single-milestone
func (s *MilestonesService) GetMilestoneIssues( func (s *MilestonesService) GetMilestoneIssues(
pid interface{}, pid interface{},
milestone int) ([]*Issue, *Response, error) { milestone int,
opt *GetMilestoneIssuesOptions) ([]*Issue, *Response, error) {
project, err := parseID(pid) project, err := parseID(pid)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
u := fmt.Sprintf("projects/%s/milestones/%d/issues", url.QueryEscape(project), milestone) u := fmt.Sprintf("projects/%s/milestones/%d/issues", url.QueryEscape(project), milestone)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, opt)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
......
...@@ -37,11 +37,19 @@ func (n Namespace) String() string { ...@@ -37,11 +37,19 @@ func (n Namespace) String() string {
return Stringify(n) return Stringify(n)
} }
// ListNamespacesOptions represents the available ListNamespaces() options.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/namespaces.html#list-namespaces
type ListNamespacesOptions struct {
ListOptions
Search string `url:"search,omitempty"`
}
// ListNamespaces gets a list of projects accessible by the authenticated user. // ListNamespaces gets a list of projects accessible by the authenticated user.
// //
// GitLab API docs: http://doc.gitlab.com/ce/api/namespaces.html#list-namespaces // GitLab API docs: http://doc.gitlab.com/ce/api/namespaces.html#list-namespaces
func (s *NamespacesService) ListNamespaces() ([]*Namespace, *Response, error) { func (s *NamespacesService) ListNamespaces(opt *ListNamespacesOptions) ([]*Namespace, *Response, error) {
req, err := s.client.NewRequest("GET", "namespaces", nil) req, err := s.client.NewRequest("GET", "namespaces", opt)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
......
...@@ -56,18 +56,29 @@ func (n Note) String() string { ...@@ -56,18 +56,29 @@ func (n Note) String() string {
return Stringify(n) return Stringify(n)
} }
// ListIssueNotesOptions represents the available ListIssueNotes() options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/notes.html#list-project-issue-notes
type ListIssueNotesOptions struct {
ListOptions
}
// ListIssueNotes gets a list of all notes for a single issue. // ListIssueNotes gets a list of all notes for a single issue.
// //
// GitLab API docs: // GitLab API docs:
// http://doc.gitlab.com/ce/api/notes.html#list-project-issue-notes // http://doc.gitlab.com/ce/api/notes.html#list-project-issue-notes
func (s *NotesService) ListIssueNotes(pid interface{}, issue int) ([]*Note, *Response, error) { func (s *NotesService) ListIssueNotes(
pid interface{},
issue int,
opt *ListIssueNotesOptions) ([]*Note, *Response, error) {
project, err := parseID(pid) project, err := parseID(pid)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
u := fmt.Sprintf("projects/%s/issues/%d/notes", url.QueryEscape(project), issue) u := fmt.Sprintf("projects/%s/issues/%d/notes", url.QueryEscape(project), issue)
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, opt)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
......
...@@ -55,17 +55,26 @@ func (s Snippet) String() string { ...@@ -55,17 +55,26 @@ func (s Snippet) String() string {
return Stringify(s) return Stringify(s)
} }
// ListSnippits gets a list of project snippets. // ListSnippetsOptions represents the available ListSnippets() options.
// //
// GitLab API docs: http://doc.gitlab.com/ce/api/project_snippets.html#list-snippets // GitLab API docs: http://doc.gitlab.com/ce/api/project_snippets.html#list-snippets
func (s *ProjectSnippetsService) ListSnippits(pid interface{}) ([]*Snippet, *Response, error) { type ListSnippetsOptions struct {
ListOptions
}
// ListSnippets gets a list of project snippets.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/project_snippets.html#list-snippets
func (s *ProjectSnippetsService) ListSnippets(
pid interface{},
opt *ListSnippetsOptions) ([]*Snippet, *Response, error) {
project, err := parseID(pid) project, err := parseID(pid)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
u := fmt.Sprintf("projects/%s/snippets", url.QueryEscape(project)) u := fmt.Sprintf("projects/%s/snippets", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, opt)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
...@@ -79,11 +88,11 @@ func (s *ProjectSnippetsService) ListSnippits(pid interface{}) ([]*Snippet, *Res ...@@ -79,11 +88,11 @@ func (s *ProjectSnippetsService) ListSnippits(pid interface{}) ([]*Snippet, *Res
return ps, resp, err return ps, resp, err
} }
// GetSnippit gets a single project snippet // GetSnippet gets a single project snippet
// //
// GitLab API docs: // GitLab API docs:
// http://doc.gitlab.com/ce/api/project_snippets.html#single-snippet // http://doc.gitlab.com/ce/api/project_snippets.html#single-snippet
func (s *ProjectSnippetsService) GetSnippit( func (s *ProjectSnippetsService) GetSnippet(
pid interface{}, pid interface{},
snippet int) (*Snippet, *Response, error) { snippet int) (*Snippet, *Response, error) {
project, err := parseID(pid) project, err := parseID(pid)
...@@ -211,11 +220,11 @@ func (s *ProjectSnippetsService) DeleteSnippet(pid interface{}, snippet int) (*R ...@@ -211,11 +220,11 @@ func (s *ProjectSnippetsService) DeleteSnippet(pid interface{}, snippet int) (*R
return resp, err return resp, err
} }
// SnippitContent returns the raw project snippet as plain text. // SnippetContent returns the raw project snippet as plain text.
// //
// GitLab API docs: // GitLab API docs:
// http://doc.gitlab.com/ce/api/project_snippets.html#snippet-content // http://doc.gitlab.com/ce/api/project_snippets.html#snippet-content
func (s *ProjectSnippetsService) SnippitContent( func (s *ProjectSnippetsService) SnippetContent(
pid interface{}, pid interface{},
snippet int) ([]byte, *Response, error) { snippet int) ([]byte, *Response, error) {
project, err := parseID(pid) project, err := parseID(pid)
......
...@@ -76,6 +76,7 @@ func (s Project) String() string { ...@@ -76,6 +76,7 @@ func (s Project) String() string {
// //
// GitLab API docs: http://doc.gitlab.com/ce/api/projects.html#list-projects // GitLab API docs: http://doc.gitlab.com/ce/api/projects.html#list-projects
type ListProjectsOptions struct { type ListProjectsOptions struct {
ListOptions
Archived bool `url:"archived,omitempty"` Archived bool `url:"archived,omitempty"`
OrderBy string `url:"order_by,omitempty"` OrderBy string `url:"order_by,omitempty"`
Sort string `url:"sort,omitempty"` Sort string `url:"sort,omitempty"`
...@@ -172,8 +173,7 @@ func (s *ProjectsService) GetProject(pid interface{}) (*Project, *Response, erro ...@@ -172,8 +173,7 @@ func (s *ProjectsService) GetProject(pid interface{}) (*Project, *Response, erro
// GitLab API docs: // GitLab API docs:
// http://doc.gitlab.com/ce/api/projects.html#search-for-projects-by-name // http://doc.gitlab.com/ce/api/projects.html#search-for-projects-by-name
type SearchProjectsOptions struct { type SearchProjectsOptions struct {
PerPage int `url:"per_page,omitempty"` ListOptions
Page int `url:"page,omitempty"`
OrderBy string `url:"order_by,omitempty"` OrderBy string `url:"order_by,omitempty"`
Sort string `url:"sort,omitempty"` Sort string `url:"sort,omitempty"`
} }
...@@ -245,19 +245,29 @@ func (s ProjectEvent) String() string { ...@@ -245,19 +245,29 @@ func (s ProjectEvent) String() string {
return Stringify(s) return Stringify(s)
} }
// GetProjectEventsOptions represents the available GetProjectEvents() options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/projects.html#get-project-events
type GetProjectEventsOptions struct {
ListOptions
}
// GetProjectEvents gets the events for the specified project. Sorted from // GetProjectEvents gets the events for the specified project. Sorted from
// newest to latest. // newest to latest.
// //
// GitLab API docs: // GitLab API docs:
// http://doc.gitlab.com/ce/api/projects.html#get-project-events // http://doc.gitlab.com/ce/api/projects.html#get-project-events
func (s *ProjectsService) GetProjectEvents(pid interface{}) ([]*ProjectEvent, *Response, error) { func (s *ProjectsService) GetProjectEvents(
pid interface{},
opt *GetProjectEventsOptions) ([]*ProjectEvent, *Response, error) {
project, err := parseID(pid) project, err := parseID(pid)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
u := fmt.Sprintf("projects/%s/events", url.QueryEscape(project)) u := fmt.Sprintf("projects/%s/events", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, opt)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
...@@ -460,6 +470,7 @@ type ProjectMember struct { ...@@ -460,6 +470,7 @@ type ProjectMember struct {
// GitLab API docs: // GitLab API docs:
// http://doc.gitlab.com/ce/api/projects.html#list-project-team-members // http://doc.gitlab.com/ce/api/projects.html#list-project-team-members
type ListProjectMembersOptions struct { type ListProjectMembersOptions struct {
ListOptions
Query string `url:"query,omitempty"` Query string `url:"query,omitempty"`
} }
...@@ -630,18 +641,27 @@ type ProjectHook struct { ...@@ -630,18 +641,27 @@ type ProjectHook struct {
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
} }
// ListProjectHooksOptions represents the available ListProjectHooks() options.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/projects.html#list-project-hooks
type ListProjectHooksOptions struct {
ListOptions
}
// ListProjectHooks gets a list of project hooks. // ListProjectHooks gets a list of project hooks.
// //
// GitLab API docs: // GitLab API docs:
// http://doc.gitlab.com/ce/api/projects.html#list-project-hooks // http://doc.gitlab.com/ce/api/projects.html#list-project-hooks
func (s *ProjectsService) ListProjectHooks(pid interface{}) ([]*ProjectHook, *Response, error) { func (s *ProjectsService) ListProjectHooks(
pid interface{},
opt *ListProjectHooksOptions) ([]*ProjectHook, *Response, error) {
project, err := parseID(pid) project, err := parseID(pid)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
u := fmt.Sprintf("projects/%s/hooks", url.QueryEscape(project)) u := fmt.Sprintf("projects/%s/hooks", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, opt)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
......
...@@ -57,11 +57,20 @@ type User struct { ...@@ -57,11 +57,20 @@ type User struct {
TwoFactorEnabled bool `json:"two_factor_enabled"` TwoFactorEnabled bool `json:"two_factor_enabled"`
} }
// ListUsersOptions represents the available ListUsers() options.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/users.html#list-users
type ListUsersOptions struct {
ListOptions
Active bool `url:"active,omitempty"`
Search string `url:"search,omitempty"`
}
// ListUsers gets a list of users. // ListUsers gets a list of users.
// //
// GitLab API docs: http://doc.gitlab.com/ce/api/users.html#list-users // GitLab API docs: http://doc.gitlab.com/ce/api/users.html#list-users
func (s *UsersService) ListUsers() ([]*User, *Response, error) { func (s *UsersService) ListUsers(opt *ListUsersOptions) ([]*User, *Response, error) {
req, err := s.client.NewRequest("GET", "users", nil) req, err := s.client.NewRequest("GET", "users", opt)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment