Skip to content

Commit d3788c8

Browse files
jgoldhammergmessner
authored andcommitted
add project statistics information to projects api (#192)
* add project statistics information to Project model
1 parent b5db10e commit d3788c8

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

src/main/java/org/gitlab4j/api/models/Project.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public String toString() {
8585
private String webUrl;
8686
private Boolean wikiEnabled;
8787
private Boolean printingMergeRequestLinkEnabled;
88+
private ProjectStatistics statistics;
8889

8990
public Integer getApprovalsBeforeMerge() {
9091
return approvalsBeforeMerge;
@@ -592,7 +593,16 @@ public Project withPrintingMergeRequestLinkEnabled(Boolean printingMergeRequestL
592593
return (this);
593594
}
594595

596+
public ProjectStatistics getStatistics() {
597+
return statistics;
598+
}
599+
600+
public void setStatistics(ProjectStatistics statistics) {
601+
this.statistics = statistics;
602+
}
603+
595604
public static final boolean isValid(Project project) {
596605
return (project != null && project.getId() != null);
597606
}
607+
598608
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package org.gitlab4j.api.models;
2+
3+
4+
import javax.xml.bind.annotation.XmlAccessType;
5+
import javax.xml.bind.annotation.XmlAccessorType;
6+
7+
/**
8+
* contains sizing information from the project.
9+
* To get this information, the project api has to be called with parameter statistics=true
10+
* which is only allowed for gitlab admins.
11+
*
12+
* Example json from projects api response:
13+
* https://<gitlab>/api/v4//projects?statistics=true
14+
*
15+
* "statistics": {
16+
* "commit_count": 37,
17+
* "storage_size": 1038090,
18+
* "repository_size": 1038090,
19+
* "lfs_objects_size": 0,
20+
* "job_artifacts_size": 0
21+
* }
22+
*/
23+
@XmlAccessorType(XmlAccessType.FIELD)
24+
public class ProjectStatistics {
25+
26+
long commitCount;
27+
long storageSize;
28+
long lfsObjectSize;
29+
long jobArtifactsSize;
30+
31+
public long getCommitCount() {
32+
return commitCount;
33+
}
34+
35+
public long getJobArtifactsSize() {
36+
return jobArtifactsSize;
37+
}
38+
39+
public long getLfsObjectSize() {
40+
return lfsObjectSize;
41+
}
42+
43+
public long getStorageSize() {
44+
return storageSize;
45+
}
46+
47+
public void setCommitCount(long commitCount) {
48+
this.commitCount = commitCount;
49+
}
50+
51+
public void setJobArtifactsSize(long jobArtifactsSize) {
52+
this.jobArtifactsSize = jobArtifactsSize;
53+
}
54+
55+
public void setLfsObjectSize(long lfsObjectSize) {
56+
this.lfsObjectSize = lfsObjectSize;
57+
}
58+
59+
public void setStorageSize(long storageSize) {
60+
this.storageSize = storageSize;
61+
}
62+
}

src/test/java/org/gitlab4j/api/TestProjectApi.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,23 @@ else if (TEST_PROJECT_NAME_2.equals(project.getName()))
279279
assertEquals(TEST_PROJECT_NAME_1, projects.get(1).getName());
280280
}
281281

282+
283+
@Test
284+
public void testListProjectsWithStatistics() throws GitLabApiException {
285+
286+
List<Project> projects = gitLabApi.getProjectApi().getProjects(false, null,
287+
Constants.ProjectOrderBy.NAME, Constants.SortOrder.DESC, null, false, false, false, false, true);
288+
assertNotNull(projects);
289+
assertTrue(projects.size() >= 2);
290+
291+
assertNotNull(projects.get(0).getStatistics());
292+
assertNotNull(projects.get(0).getStatistics().getLfsObjectSize());
293+
assertNotNull(projects.get(0).getStatistics().getCommitCount());
294+
assertNotNull(projects.get(0).getStatistics().getJobArtifactsSize());
295+
assertNotNull(projects.get(0).getStatistics().getStorageSize());
296+
297+
}
298+
282299
@Test
283300
public void testListProjectsWithParamsViaPager() throws GitLabApiException {
284301

0 commit comments

Comments
 (0)