Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add RepositoryApi.compare(Object projectIdOrPath, String from, String to, Object fromProjectId, boolean straight) #1208

Merged
merged 12 commits into from
Dec 24, 2024
45 changes: 33 additions & 12 deletions gitlab4j-api/src/main/java/org/gitlab4j/api/RepositoryApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -914,18 +914,7 @@ public File getRepositoryArchive(
*/
public CompareResults compare(Object projectIdOrPath, String from, String to, boolean straight)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method should be deprecated, now that we have the one accepting more parameters.

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);
}

/**
Expand All @@ -942,6 +931,38 @@ public CompareResults compare(Object projectIdOrPath, String from, String to) th
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, Object fromProjectId, boolean straight)
jmini marked this conversation as resolved.
Show resolved Hide resolved
throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("from", from, true)
.withParam("to", to, true)
.withParam("straight", straight);
if (fromProjectId != null) {
formData.withParam("from_project_id", fromProjectId);
}
jmini marked this conversation as resolved.
Show resolved Hide resolved
Response response = get(
Response.Status.OK,
formData.asMap(),
"projects",
getProjectIdOrPath(projectIdOrPath),
"repository",
"compare");
return (response.readEntity(CompareResults.class));
}

/**
* Get a list of contributors from a project.
*
Expand Down
Loading