Commit d3788c8b authored by Jens Goldhammer's avatar Jens Goldhammer Committed by Greg Messner
Browse files

add project statistics information to projects api (#192)

* add project statistics information to Project model
parent b5db10eb
...@@ -85,6 +85,7 @@ public class Project { ...@@ -85,6 +85,7 @@ public class Project {
private String webUrl; private String webUrl;
private Boolean wikiEnabled; private Boolean wikiEnabled;
private Boolean printingMergeRequestLinkEnabled; private Boolean printingMergeRequestLinkEnabled;
private ProjectStatistics statistics;
public Integer getApprovalsBeforeMerge() { public Integer getApprovalsBeforeMerge() {
return approvalsBeforeMerge; return approvalsBeforeMerge;
...@@ -592,7 +593,16 @@ public class Project { ...@@ -592,7 +593,16 @@ public class Project {
return (this); return (this);
} }
public ProjectStatistics getStatistics() {
return statistics;
}
public void setStatistics(ProjectStatistics statistics) {
this.statistics = statistics;
}
public static final boolean isValid(Project project) { public static final boolean isValid(Project project) {
return (project != null && project.getId() != null); return (project != null && project.getId() != null);
} }
} }
package org.gitlab4j.api.models;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
/**
* contains sizing information from the project.
* To get this information, the project api has to be called with parameter statistics=true
* which is only allowed for gitlab admins.
*
* Example json from projects api response:
* https://<gitlab>/api/v4//projects?statistics=true
*
* "statistics": {
* "commit_count": 37,
* "storage_size": 1038090,
* "repository_size": 1038090,
* "lfs_objects_size": 0,
* "job_artifacts_size": 0
* }
*/
@XmlAccessorType(XmlAccessType.FIELD)
public class ProjectStatistics {
long commitCount;
long storageSize;
long lfsObjectSize;
long jobArtifactsSize;
public long getCommitCount() {
return commitCount;
}
public long getJobArtifactsSize() {
return jobArtifactsSize;
}
public long getLfsObjectSize() {
return lfsObjectSize;
}
public long getStorageSize() {
return storageSize;
}
public void setCommitCount(long commitCount) {
this.commitCount = commitCount;
}
public void setJobArtifactsSize(long jobArtifactsSize) {
this.jobArtifactsSize = jobArtifactsSize;
}
public void setLfsObjectSize(long lfsObjectSize) {
this.lfsObjectSize = lfsObjectSize;
}
public void setStorageSize(long storageSize) {
this.storageSize = storageSize;
}
}
...@@ -279,6 +279,23 @@ public class TestProjectApi { ...@@ -279,6 +279,23 @@ public class TestProjectApi {
assertEquals(TEST_PROJECT_NAME_1, projects.get(1).getName()); assertEquals(TEST_PROJECT_NAME_1, projects.get(1).getName());
} }
@Test
public void testListProjectsWithStatistics() throws GitLabApiException {
List<Project> projects = gitLabApi.getProjectApi().getProjects(false, null,
Constants.ProjectOrderBy.NAME, Constants.SortOrder.DESC, null, false, false, false, false, true);
assertNotNull(projects);
assertTrue(projects.size() >= 2);
assertNotNull(projects.get(0).getStatistics());
assertNotNull(projects.get(0).getStatistics().getLfsObjectSize());
assertNotNull(projects.get(0).getStatistics().getCommitCount());
assertNotNull(projects.get(0).getStatistics().getJobArtifactsSize());
assertNotNull(projects.get(0).getStatistics().getStorageSize());
}
@Test @Test
public void testListProjectsWithParamsViaPager() throws GitLabApiException { public void testListProjectsWithParamsViaPager() throws GitLabApiException {
......
Supports Markdown
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