Skip to content

Commit 235a375

Browse files
committed
#755 added Package filter
based on docs https://docs.gitlab.com/ee/api/packages.html and inspired by GroupProjectsFilter
1 parent 20e122b commit 235a375

File tree

2 files changed

+158
-0
lines changed

2 files changed

+158
-0
lines changed

src/main/java/org/gitlab4j/api/Constants.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,52 @@ public String toString() {
131131
}
132132
}
133133

134+
/** Enum to use for ordering the results of getPackages(). */
135+
public enum PackageOrderBy {
136+
137+
NAME, CREATED_AT, VERSION, TYPE, PROJECT_PATH;
138+
139+
private static JacksonJsonEnumHelper<PackageOrderBy> enumHelper = new JacksonJsonEnumHelper<>(PackageOrderBy.class);
140+
141+
@JsonCreator
142+
public static PackageOrderBy forValue(String value) {
143+
return enumHelper.forValue(value);
144+
}
145+
146+
@JsonValue
147+
public String toValue() {
148+
return (enumHelper.toString(this));
149+
}
150+
151+
@Override
152+
public String toString() {
153+
return (enumHelper.toString(this));
154+
}
155+
}
156+
157+
/** Enum to use for filtering the results of getPackages(). */
158+
public enum PackageStatus {
159+
160+
DEFAULT, HIDDEN, PROCESSING;
161+
162+
private static JacksonJsonEnumHelper<PackageStatus> enumHelper = new JacksonJsonEnumHelper<>(PackageStatus.class);
163+
164+
@JsonCreator
165+
public static PackageStatus forValue(String value) {
166+
return enumHelper.forValue(value);
167+
}
168+
169+
@JsonValue
170+
public String toValue() {
171+
return (enumHelper.toString(this));
172+
}
173+
174+
@Override
175+
public String toString() {
176+
return (enumHelper.toString(this));
177+
}
178+
}
179+
134180
/** Enum to use for ordering the results of getProjects(). */
135181
public enum ProjectOrderBy {
136182

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package org.gitlab4j.api.models;
2+
3+
import org.gitlab4j.api.Constants.PackageStatus;
4+
import org.gitlab4j.api.Constants.PackageOrderBy;
5+
import org.gitlab4j.api.Constants.SortOrder;
6+
import org.gitlab4j.api.GitLabApiForm;
7+
8+
/**
9+
* This class is used to filter Projects when getting lists of projects for a specified group.
10+
*/
11+
public class PackageFilter {
12+
13+
private Boolean excludeSubgroups;
14+
private PackageOrderBy orderBy;
15+
private SortOrder sort;
16+
private PackageType packageType;
17+
private String packageName;
18+
private Boolean includeVersionless;
19+
private PackageStatus status;
20+
21+
/**
22+
* Exclude Subgroups.
23+
*
24+
* @param excludeSubgroups if true, packages from projects from subgroups are not listed.
25+
* @return the reference to this ProjectFilter instance
26+
*/
27+
public PackageFilter withExcludeSubgroups(Boolean excludeSubgroups) {
28+
this.excludeSubgroups = excludeSubgroups;
29+
return (this);
30+
}
31+
32+
/**
33+
* Return projects ordered by created_at, name, version, type, or project_path
34+
*
35+
* @param orderBy specifies what field to order by
36+
* @return the reference to this ProjectFilter instance
37+
*/
38+
public PackageFilter withOrderBy(PackageOrderBy orderBy) {
39+
this.orderBy = orderBy;
40+
return (this);
41+
}
42+
43+
/**
44+
* Return projects sorted in asc or desc order. Default is desc.
45+
*
46+
* @param sort sort direction, ASC or DESC
47+
* @return the reference to this ProjectFilter instance
48+
*/
49+
public PackageFilter withSortOder(SortOrder sort) {
50+
this.sort = sort;
51+
return (this);
52+
}
53+
54+
/**
55+
* Filter the returned packages by type.
56+
*
57+
* @param packageType One of conan, maven, npm, pypi, composer, nuget, helm, generic or golang
58+
* @return the reference to this ProjectFilter instance
59+
*/
60+
public PackageFilter withPackageType(PackageType packageType) {
61+
this.packageType = packageType;
62+
return (this);
63+
}
64+
65+
/**
66+
* Filter the project packages with a fuzzy search by name
67+
*
68+
* @param packageName
69+
* @return the reference to this ProjectFilter instance
70+
*/
71+
public PackageFilter withPackageName(String packageName) {
72+
this.packageName = packageName;
73+
return (this);
74+
}
75+
76+
/**
77+
* @param includeVersionless if true, versionless packages are included in the response
78+
* @return the reference to this ProjectFilter instance
79+
*/
80+
public PackageFilter withIncludeVersionless(Boolean includeVersionless) {
81+
this.includeVersionless = includeVersionless;
82+
return (this);
83+
}
84+
85+
/**
86+
* Filter the returned packages by status.
87+
*
88+
* @param status One of default (default), hidden, or processing
89+
* @return the reference to this ProjectFilter instance
90+
*/
91+
public PackageFilter withStatus(PackageStatus status) {
92+
this.status = status;
93+
return (this);
94+
}
95+
96+
/**
97+
* Get the query params specified by this filter.
98+
*
99+
* @return a GitLabApiForm instance holding the query parameters for this ProjectFilter instance
100+
*/
101+
public GitLabApiForm getQueryParams() {
102+
return (new GitLabApiForm()
103+
.withParam("order_by", orderBy)
104+
.withParam("sort", sort)
105+
.withParam("exclude_subgroups", excludeSubgroups)
106+
.withParam("package_type", packageType)
107+
.withParam("package_name", packageName)
108+
.withParam("include_versionless", includeVersionless)
109+
.withParam("status", status)
110+
);
111+
}
112+
}

0 commit comments

Comments
 (0)