Skip to content

Commit e825044

Browse files
committed
Comments and order_by support
1 parent 7062eea commit e825044

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,29 @@ public String toString() {
311311
}
312312
}
313313

314+
/** Enum to use for ordering the results of getContibutors(). */
315+
public enum ContributorOrderBy {
316+
317+
NAME, EMAIL, COMMITS;
318+
319+
private static JacksonJsonEnumHelper<ContributorOrderBy> enumHelper = new JacksonJsonEnumHelper<>(ContributorOrderBy.class);
320+
321+
@JsonCreator
322+
public static ContributorOrderBy forValue(String value) {
323+
return enumHelper.forValue(value);
324+
}
325+
326+
@JsonValue
327+
public String toValue() {
328+
return (enumHelper.toString(this));
329+
}
330+
331+
@Override
332+
public String toString() {
333+
return (enumHelper.toString(this));
334+
}
335+
}
336+
314337
/** Enum to use for specifying the scope when calling getPipelines(). */
315338
public enum PipelineScope {
316339

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -671,18 +671,19 @@ public List<Contributor> getContributors(Object projectIdOrPath, int page, int p
671671
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
672672
* @param page the page to get
673673
* @param perPage the number of projects per page
674-
* @param sort optional param to sort the list of contributors by
674+
* @param orderBy (optional param) returns contributors ordered by NAME, EMAIL, or COMMITS. Default is COMMITS
675+
* @param sortOrder (optional param) returns contributors sorted in ASC or DESC order. Default is ASC
675676
* @return a List containing the contributors for the specified project ID
676677
* @throws GitLabApiException if any exception occurs
677678
*/
678-
public List<Contributor> getContributors(Object projectIdOrPath, int page, int perPage, String sort) throws GitLabApiException {
679-
if (sort != null && !(sort.equals("asc") || sort.equals("desc")) ) {
680-
throw new RuntimeException("Sort must be asc or desc");
679+
public List<Contributor> getContributors(Object projectIdOrPath, int page, int perPage, ContributorOrderBy orderBy, SortOrder sortOrder) throws GitLabApiException {
680+
GitLabApiForm formData = new GitLabApiForm().withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage);
681+
if (sortOrder != null) {
682+
formData.withParam("sort", sortOrder, false);
681683
}
682684

683-
GitLabApiForm formData = new GitLabApiForm().withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage);
684-
if (sort != null) {
685-
formData.withParam("sort", sort, false);
685+
if (orderBy != null) {
686+
formData.withParam("order_by", orderBy, false);
686687
}
687688

688689
Response response = get(Response.Status.OK, formData.asMap(),

0 commit comments

Comments
 (0)