Skip to content

Commit 73817d1

Browse files
authored
Merge pull request #822 from maddymanu/add-contributos-sort
Adding getContributors sort by asc / desc support
2 parents cf58df4 + e825044 commit 73817d1

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,34 @@ public List<Contributor> getContributors(Object projectIdOrPath, int page, int p
663663
return (response.readEntity(new GenericType<List<Contributor>>() { }));
664664
}
665665

666+
/**
667+
* Get a list of contributors from a project and in the specified page range, sorted by specified param.
668+
*
669+
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/contributors</code></pre>
670+
*
671+
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
672+
* @param page the page to get
673+
* @param perPage the number of projects per page
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
676+
* @return a List containing the contributors for the specified project ID
677+
* @throws GitLabApiException if any exception occurs
678+
*/
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);
683+
}
684+
685+
if (orderBy != null) {
686+
formData.withParam("order_by", orderBy, false);
687+
}
688+
689+
Response response = get(Response.Status.OK, formData.asMap(),
690+
"projects", getProjectIdOrPath(projectIdOrPath), "repository", "contributors");
691+
return (response.readEntity(new GenericType<List<Contributor>>() { }));
692+
}
693+
666694
/**
667695
* Get a Pager of contributors from a project.
668696
*

0 commit comments

Comments
 (0)