Commit c39af18e authored by Ulrich Schreiner's avatar Ulrich Schreiner Committed by Sander van Harmelen

Add statistics information and flag to query options (#141)

* Add statistics information and flag to query options

* groups do not expose a CommitCount

* make the sizes unsigned, negative values dont make sense

* repair tests

* add review comments

* remove wrong tagging from field
parent 0c848680
......@@ -33,11 +33,12 @@ type GroupsService struct {
//
// GitLab API docs: https://docs.gitlab.com/ce/api/groups.html
type Group struct {
ID int `json:"id"`
Name string `json:"name"`
Path string `json:"path"`
Description string `json:"description"`
Projects *[]Project `json:"projects,omitempty"`
ID int `json:"id"`
Name string `json:"name"`
Path string `json:"path"`
Description string `json:"description"`
Projects *[]Project `json:"projects"`
Statistics *StorageStatistics `json:"statistics"`
}
// ListGroupsOptions represents the available ListGroups() options.
......@@ -45,7 +46,8 @@ type Group struct {
// GitLab API docs: https://docs.gitlab.com/ce/api/groups.html#list-project-groups
type ListGroupsOptions struct {
ListOptions
Search *string `url:"search,omitempty" json:"search,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
Statistics *bool `url:"statistics,omitempty" json:"statistics,omitempty"`
}
// ListGroups gets a list of groups. (As user: my groups, as admin: all groups)
......
......@@ -77,6 +77,7 @@ type Project struct {
GroupName string `json:"group_name"`
GroupAccessLevel int `json:"group_access_level"`
} `json:"shared_with_groups"`
Statistics *ProjectStatistics `json:"statistics"`
}
// Repository represents a repository.
......@@ -108,6 +109,20 @@ type ProjectNamespace struct {
UpdatedAt *time.Time `json:"updated_at"`
}
// StorageStatistics represents a statistics record for a group or project.
type StorageStatistics struct {
StorageSize int64 `json:"storage_size"`
RepositorySize int64 `json:"repository_size"`
LfsObjectsSize int64 `json:"lfs_objects_size"`
BuildArtifactsSize int64 `json:"build_artifacts_size"`
}
// ProjectStatistics represents a statistics record for a project.
type ProjectStatistics struct {
StorageStatistics
CommitCount int `json:"commit_count"`
}
// Permissions represents premissions.
type Permissions struct {
ProjectAccess *ProjectAccess `json:"project_access"`
......@@ -141,6 +156,7 @@ type ListProjectsOptions struct {
Search *string `url:"search,omitempty" json:"search,omitempty"`
Simple *bool `url:"simple,omitempty" json:"simple,omitempty"`
Visibility *string `url:"visibility,omitempty" json:"visibility,omitempty"`
Statistics *bool `url:"statistics,omitempty" json:"statistics,omitempty"`
}
// ListProjects gets a list of projects accessible by the authenticated user.
......
......@@ -22,11 +22,12 @@ func TestListProjects(t *testing.T) {
"search": "query",
"simple": "true",
"visibility": "public",
"statistics": "true",
})
fmt.Fprint(w, `[{"id":1},{"id":2}]`)
})
opt := &ListProjectsOptions{ListOptions{2, 3}, Bool(true), String("name"), String("asc"), String("query"), Bool(true), String("public")}
opt := &ListProjectsOptions{ListOptions{2, 3}, Bool(true), String("name"), String("asc"), String("query"), Bool(true), String("public"), Bool(true)}
projects, _, err := client.Projects.ListProjects(opt)
if err != nil {
......@@ -54,11 +55,12 @@ func TestListOwnedProjects(t *testing.T) {
"search": "query",
"simple": "true",
"visibility": "public",
"statistics": "false",
})
fmt.Fprint(w, `[{"id":1},{"id":2}]`)
})
opt := &ListProjectsOptions{ListOptions{2, 3}, Bool(true), String("name"), String("asc"), String("query"), Bool(true), String("public")}
opt := &ListProjectsOptions{ListOptions{2, 3}, Bool(true), String("name"), String("asc"), String("query"), Bool(true), String("public"), Bool(false)}
projects, _, err := client.Projects.ListOwnedProjects(opt)
if err != nil {
......@@ -86,11 +88,12 @@ func TestListStarredProjects(t *testing.T) {
"search": "query",
"simple": "true",
"visibility": "public",
"statistics": "false",
})
fmt.Fprint(w, `[{"id":1},{"id":2}]`)
})
opt := &ListProjectsOptions{ListOptions{2, 3}, Bool(true), String("name"), String("asc"), String("query"), Bool(true), String("public")}
opt := &ListProjectsOptions{ListOptions{2, 3}, Bool(true), String("name"), String("asc"), String("query"), Bool(true), String("public"), Bool(false)}
projects, _, err := client.Projects.ListStarredProjects(opt)
if err != nil {
......@@ -118,11 +121,12 @@ func TestListAllProjects(t *testing.T) {
"search": "query",
"simple": "true",
"visibility": "public",
"statistics": "false",
})
fmt.Fprint(w, `[{"id":1},{"id":2}]`)
})
opt := &ListProjectsOptions{ListOptions{2, 3}, Bool(true), String("name"), String("asc"), String("query"), Bool(true), String("public")}
opt := &ListProjectsOptions{ListOptions{2, 3}, Bool(true), String("name"), String("asc"), String("query"), Bool(true), String("public"), Bool(false)}
projects, _, err := client.Projects.ListAllProjects(opt)
if err != nil {
......
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