Skip to content

Commit 7062eea

Browse files
committed
Adding getContributors sort by asc / desc support
1 parent 09ed795 commit 7062eea

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,33 @@ 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 sort optional param to sort the list of contributors by
675+
* @return a List containing the contributors for the specified project ID
676+
* @throws GitLabApiException if any exception occurs
677+
*/
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");
681+
}
682+
683+
GitLabApiForm formData = new GitLabApiForm().withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage);
684+
if (sort != null) {
685+
formData.withParam("sort", sort, false);
686+
}
687+
688+
Response response = get(Response.Status.OK, formData.asMap(),
689+
"projects", getProjectIdOrPath(projectIdOrPath), "repository", "contributors");
690+
return (response.readEntity(new GenericType<List<Contributor>>() { }));
691+
}
692+
666693
/**
667694
* Get a Pager of contributors from a project.
668695
*

0 commit comments

Comments
 (0)