diff --git a/gitlab4j-api/src/main/java/org/gitlab4j/api/RepositoryApi.java b/gitlab4j-api/src/main/java/org/gitlab4j/api/RepositoryApi.java index 72e858a9..20d02839 100644 --- a/gitlab4j-api/src/main/java/org/gitlab4j/api/RepositoryApi.java +++ b/gitlab4j-api/src/main/java/org/gitlab4j/api/RepositoryApi.java @@ -913,21 +913,12 @@ public File getRepositoryArchive( * false to compare using merge base (from…to)’. * @return a CompareResults containing the results of the comparison * @throws GitLabApiException if any exception occurs + * @deprecated use {@link #compare(Object, String, String, Long, Boolean)} instead */ + @Deprecated public CompareResults compare(Object projectIdOrPath, String from, String to, Boolean straight) throws GitLabApiException { - Form formData = new GitLabApiForm() - .withParam("from", from, true) - .withParam("to", to, true) - .withParam("straight", straight); - Response response = get( - Response.Status.OK, - formData.asMap(), - "projects", - getProjectIdOrPath(projectIdOrPath), - "repository", - "compare"); - return (response.readEntity(CompareResults.class)); + return compare(projectIdOrPath, from, to, null, straight); } /** @@ -939,9 +930,41 @@ public CompareResults compare(Object projectIdOrPath, String from, String to, Bo * @param to the commit SHA or branch name * @return a CompareResults containing the results of the comparison * @throws GitLabApiException if any exception occurs + * @deprecated use {@link #compare(Object, String, String, Long, Boolean)} instead */ + @Deprecated public CompareResults compare(Object projectIdOrPath, String from, String to) throws GitLabApiException { - return (compare(projectIdOrPath, from, to, false)); + return compare(projectIdOrPath, from, to, false); + } + + /** + * Compare branches, tags or commits. This can be accessed without authentication + * if the repository is publicly accessible. + * + * @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance + * @param from the commit SHA or branch name + * @param to the commit SHA or branch name + * @param fromProjectId The ID to compare from. + * @param straight specifies the comparison method, true for direct comparison between from and to (from..to), + * false to compare using merge base (from…to) + * @return a CompareResults containing the results of the comparison + * @throws GitLabApiException if any exception occurs + */ + public CompareResults compare(Object projectIdOrPath, String from, String to, Long fromProjectId, Boolean straight) + throws GitLabApiException { + GitLabApiForm formData = new GitLabApiForm() + .withParam("from", from, true) + .withParam("to", to, true) + .withParam("straight", straight) + .withParam("from_project_id", fromProjectId); + Response response = get( + Response.Status.OK, + formData.asMap(), + "projects", + getProjectIdOrPath(projectIdOrPath), + "repository", + "compare"); + return (response.readEntity(CompareResults.class)); } /**