Skip to content

Commit abc582d

Browse files
committed
Adding getContributors sort by asc / desc
1 parent bb2eb40 commit abc582d

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<groupId>org.gitlab4j</groupId>
66
<artifactId>gitlab4j-api-cortex</artifactId>
77
<packaging>jar</packaging>
8-
<version>4.20.1-SNAPSHOT</version>
8+
<version>4.20.2-SNAPSHOT</version>
99
<name>GitLab4J-API - GitLab API Java Client</name>
1010
<description>GitLab4J-API (gitlab4j-api) provides a full featured Java client library for working with GitLab repositories and servers via the GitLab REST API.</description>
1111
<url>https://github.com/gitlab4j/gitlab4j-api</url>

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+
/**
668+
* Get a list of contributors from a project and in the specified page range, sorted by specified param.
669+
*
670+
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/contributors</code></pre>
671+
*
672+
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
673+
* @param page the page to get
674+
* @param perPage the number of projects per page
675+
* @param sort optional param to sort the list of contributors by
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, String sort) throws GitLabApiException {
680+
if (sort != null && !(sort.equals("asc") || sort.equals("desc")) ) {
681+
throw new RuntimeException("Sort must be asc or desc");
682+
}
683+
684+
GitLabApiForm formData = new GitLabApiForm().withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage);
685+
if (sort != null) {
686+
formData.withParam("sort", sort, 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)