Verified Commit 2d201fad authored by Giannis Kepas's avatar Giannis Kepas Committed by GitLab
Browse files

Add root_storage_statistics to groups

Changelog: Improvements
parent b3e1e656
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -308,6 +308,7 @@ type Group struct {
	ParentID                             int64                         `json:"parent_id"`
	OrganizationID                       int64                         `json:"organization_id"`
	Statistics                           *Statistics                   `json:"statistics"`
	RootStorageStatistics                *RootStorageStatistics        `json:"root_storage_statistics"`
	CustomAttributes                     []*CustomAttribute            `json:"custom_attributes"`
	ShareWithGroupLock                   bool                          `json:"share_with_group_lock"`
	PreventSharingGroupsOutsideHierarchy bool                          `json:"prevent_sharing_groups_outside_hierarchy"`
@@ -366,6 +367,29 @@ type Group struct {
	DefaultBranchProtection int64 `json:"default_branch_protection"`
}

// RootStorageStatistics represents the storage statistics of a namespace,
// aggregated over the whole hierarchy of the top-level group. It is only
// returned for top-level groups, and only when statistics are requested.
//
// Unlike the per-group Statistics, it also reports the container registry
// and dependency proxy sizes.
//
// GitLab API docs: https://docs.gitlab.com/api/groups/#list-all-groups
type RootStorageStatistics struct {
	BuildArtifactsSize               int64 `json:"build_artifacts_size"`
	ContainerRegistrySize            int64 `json:"container_registry_size"`
	ContainerRegistrySizeIsEstimated bool  `json:"container_registry_size_is_estimated"`
	DependencyProxySize              int64 `json:"dependency_proxy_size"`
	LFSObjectsSize                   int64 `json:"lfs_objects_size"`
	PackagesSize                     int64 `json:"packages_size"`
	PipelineArtifactsSize            int64 `json:"pipeline_artifacts_size"`
	RepositorySize                   int64 `json:"repository_size"`
	SnippetsSize                     int64 `json:"snippets_size"`
	StorageSize                      int64 `json:"storage_size"`
	UploadsSize                      int64 `json:"uploads_size"`
	WikiSize                         int64 `json:"wiki_size"`
}

// SharedWithGroup represents a GitLab group shared with a group.
//
// GitLab API docs: https://docs.gitlab.com/api/groups/
+70 −0
Original line number Diff line number Diff line
@@ -293,6 +293,76 @@ func TestGetGroup_FullResponseFields(t *testing.T) {
	assert.Equal(t, want, group)
}

func TestListGroups_Statistics(t *testing.T) {
	t.Parallel()
	mux, client := setup(t)

	// GIVEN a GitLab API that returns both the per-group statistics and the
	// root storage statistics of a top-level group.
	mux.HandleFunc("/api/v4/groups",
		func(w http.ResponseWriter, r *http.Request) {
			testMethod(t, r, http.MethodGet)
			testParam(t, r, "statistics", "true")
			fmt.Fprint(w, `[{
				"id": 1,
				"statistics": {
					"storage_size": 363,
					"repository_size": 33,
					"wiki_size": 100,
					"lfs_objects_size": 123,
					"job_artifacts_size": 57,
					"pipeline_artifacts_size": 0,
					"packages_size": 0,
					"snippets_size": 50,
					"uploads_size": 0
				},
				"root_storage_statistics": {
					"build_artifacts_size": 57,
					"container_registry_size": 5678,
					"container_registry_size_is_estimated": true,
					"dependency_proxy_size": 1234,
					"lfs_objects_size": 123,
					"packages_size": 0,
					"pipeline_artifacts_size": 0,
					"repository_size": 33,
					"snippets_size": 50,
					"storage_size": 363,
					"uploads_size": 0,
					"wiki_size": 100
				}
			}]`)
		})

	// WHEN ListGroups is called with statistics enabled
	groups, _, err := client.Groups.ListGroups(&ListGroupsOptions{Statistics: Ptr(true)})
	require.NoError(t, err)

	// THEN both statistics objects are unmarshaled onto the Group struct.
	want := []*Group{{
		ID: 1,
		Statistics: &Statistics{
			StorageSize:      363,
			RepositorySize:   33,
			WikiSize:         100,
			LFSObjectsSize:   123,
			JobArtifactsSize: 57,
			SnippetsSize:     50,
		},
		RootStorageStatistics: &RootStorageStatistics{
			BuildArtifactsSize:               57,
			ContainerRegistrySize:            5678,
			ContainerRegistrySizeIsEstimated: true,
			DependencyProxySize:              1234,
			LFSObjectsSize:                   123,
			RepositorySize:                   33,
			SnippetsSize:                     50,
			StorageSize:                      363,
			WikiSize:                         100,
		},
	}}
	assert.Equal(t, want, groups)
}

func TestGetGroupWithFileTemplateId(t *testing.T) {
	t.Parallel()
	mux, client := setup(t)
+4 −0
Original line number Diff line number Diff line
@@ -645,6 +645,10 @@ type Repository struct {
}

// Statistics represents a statistics record for a group or project.
//
// ContainerRegistrySize is only returned for projects. For groups, use
// Group.RootStorageStatistics, which reports the container registry size
// of the whole top-level group.
type Statistics struct {
	CommitCount           int64 `json:"commit_count"`
	StorageSize           int64 `json:"storage_size"`