Skip to content

#993 Gitlab diff api seems to mismatch param #1004

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

Merged
merged 2 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 136 additions & 3 deletions src/main/java/org/gitlab4j/api/MergeRequestApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
import org.gitlab4j.api.models.ApprovalRuleParams;
import org.gitlab4j.api.models.ApprovalState;
import org.gitlab4j.api.models.Commit;
import org.gitlab4j.api.models.Diff;
import org.gitlab4j.api.models.Issue;
import org.gitlab4j.api.models.MergeRequest;
import org.gitlab4j.api.models.MergeRequestDiff;
import org.gitlab4j.api.models.MergeRequestFilter;
import org.gitlab4j.api.models.MergeRequestParams;
import org.gitlab4j.api.models.MergeRequestVersion;
import org.gitlab4j.api.models.Participant;
import org.gitlab4j.api.models.Pipeline;

Expand Down Expand Up @@ -400,7 +402,9 @@ public Stream<Commit> getCommitsStream(Object projectIdOrPath, Long mergeRequest
* @param mergeRequestIid the internal ID of the merge request
* @return a List of merge request diff versions for the specified merge request
* @throws GitLabApiException if any exception occurs
* @deprecated use {@link #getDiffVersions(Object, Long)} instead
*/
@Deprecated
public List<MergeRequestDiff> getMergeRequestDiffs(Object projectIdOrPath, Long mergeRequestIid) throws GitLabApiException {
return (getMergeRequestDiffs(projectIdOrPath, mergeRequestIid, getDefaultPerPage()).all());
}
Expand All @@ -415,7 +419,9 @@ public List<MergeRequestDiff> getMergeRequestDiffs(Object projectIdOrPath, Long
* @param itemsPerPage the number of MergeRequest instances that will be fetched per page
* @return a Pager of merge request diff versions for the specified merge request
* @throws GitLabApiException if any exception occurs
* @deprecated use {@link #getDiffVersions(Object, Long, int)} instead
*/
@Deprecated
public Pager<MergeRequestDiff> getMergeRequestDiffs(Object projectIdOrPath, Long mergeRequestIid, int itemsPerPage) throws GitLabApiException {
return (new Pager<MergeRequestDiff>(this, MergeRequestDiff.class, itemsPerPage, null,
"projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "versions"));
Expand All @@ -430,7 +436,9 @@ public Pager<MergeRequestDiff> getMergeRequestDiffs(Object projectIdOrPath, Long
* @param mergeRequestIid the internal ID of the merge request
* @return a Stream of merge request diff versions for the specified merge request
* @throws GitLabApiException if any exception occurs
* @deprecated use {@link #getDiffVersionsStream(Object, Long)} instead
*/
@Deprecated
public Stream<MergeRequestDiff> getMergeRequestDiffsStream(Object projectIdOrPath, Long mergeRequestIid) throws GitLabApiException {
return (getMergeRequestDiffs(projectIdOrPath, mergeRequestIid, getDefaultPerPage()).stream());
}
Expand All @@ -445,12 +453,12 @@ public Stream<MergeRequestDiff> getMergeRequestDiffsStream(Object projectIdOrPat
* @param versionId the ID of the merge request diff version
* @return a MergeRequestDiff instance for the specified MR diff version
* @throws GitLabApiException if any exception occurs
* @deprecated use {@link #getDiffVersion(Object, Long, Long)} instead
*/
@Deprecated
public MergeRequestDiff getMergeRequestDiff(Object projectIdOrPath,
Long mergeRequestIid, Long versionId) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath),
"merge_requests", mergeRequestIid, "versions", versionId);
return (response.readEntity(MergeRequestDiff.class));
return getDiffVersion(projectIdOrPath, mergeRequestIid, versionId);
}

/**
Expand All @@ -462,7 +470,9 @@ public MergeRequestDiff getMergeRequestDiff(Object projectIdOrPath,
* @param mergeRequestIid the internal ID of the merge request
* @param versionId the ID of the merge request diff version
* @return the specified MergeRequestDiff as an Optional instance instance
* @deprecated use {@link #getOptionalDiffVersion(Object, Long, Long)} instead
*/
@Deprecated
public Optional<MergeRequestDiff> getOptionalMergeRequestDiff(
Object projectIdOrPath, Long mergeRequestIid, Long versionId) {
try {
Expand All @@ -472,6 +482,129 @@ public Optional<MergeRequestDiff> getOptionalMergeRequestDiff(
}
}

/**
* Get a list of merge request diff versions.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/versions</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @return a List of merge request diff versions for the specified merge request
* @throws GitLabApiException if any exception occurs
*/
public List<MergeRequestVersion> getDiffVersions(Object projectIdOrPath, Long mergeRequestIid) throws GitLabApiException {
return (getDiffVersions(projectIdOrPath, mergeRequestIid, getDefaultPerPage()).all());
}

/**
* Get a Pager of merge request diff versions.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/versions</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @param itemsPerPage the number of MergeRequest instances that will be fetched per page
* @return a Pager of merge request diff versions for the specified merge request
* @throws GitLabApiException if any exception occurs
*/
public Pager<MergeRequestVersion> getDiffVersions(Object projectIdOrPath, Long mergeRequestIid, int itemsPerPage) throws GitLabApiException {
return (new Pager<MergeRequestVersion>(this, MergeRequestVersion.class, itemsPerPage, null,
"projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "versions"));
}

/**
* Get a Stream of merge request diff versions.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/versions</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @return a Stream of merge request diff versions for the specified merge request
* @throws GitLabApiException if any exception occurs
*/
public Stream<MergeRequestVersion> getDiffVersionsStream(Object projectIdOrPath, Long mergeRequestIid) throws GitLabApiException {
return (getDiffVersions(projectIdOrPath, mergeRequestIid, getDefaultPerPage()).stream());
}

/**
* Get a single merge request diff version.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/versions/:version_id</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @param versionId the ID of the merge request diff version
* @return a MergeRequestVersion instance for the specified MR diff version
* @throws GitLabApiException if any exception occurs
*/
public MergeRequestDiff getDiffVersion(Object projectIdOrPath, Long mergeRequestIid, Long versionId) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath),
"merge_requests", mergeRequestIid, "versions", versionId);
return (response.readEntity(MergeRequestDiff.class));
}

/**
* Get a single merge request diff version as an Optional instance.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/versions/:version_id</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @param versionId the ID of the merge request diff version
* @return the specified MergeRequestVersion as an Optional instance instance
*/
public Optional<MergeRequestDiff> getOptionalDiffVersion(Object projectIdOrPath, Long mergeRequestIid, Long versionId) {
try {
return (Optional.ofNullable(getDiffVersion(projectIdOrPath, mergeRequestIid, versionId)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}

/**
* Get a list of merge request diffs.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/diffs</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @return a List of merge request diffs for the specified merge request
* @throws GitLabApiException if any exception occurs
*/
public List<Diff> getDiffs(Object projectIdOrPath, Long mergeRequestIid) throws GitLabApiException {
return (getDiffs(projectIdOrPath, mergeRequestIid, getDefaultPerPage()).all());
}

/**
* Get a Pager of merge request diffs.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/diffs</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @param itemsPerPage the number of Diff instances that will be fetched per page
* @return a Pager of merge request diffs for the specified merge request
* @throws GitLabApiException if any exception occurs
*/
public Pager<Diff> getDiffs(Object projectIdOrPath, Long mergeRequestIid, int itemsPerPage) throws GitLabApiException {
return (new Pager<>(this, Diff.class, itemsPerPage, null,
"projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "diffs"));
}

/**
* Get a Stream of merge request diffs.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/diffs</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @return a Stream of merge request diffs for the specified merge request
* @throws GitLabApiException if any exception occurs
*/
public Stream<Diff> getDiffsStream(Object projectIdOrPath, Long mergeRequestIid) throws GitLabApiException {
return (getDiffs(projectIdOrPath, mergeRequestIid, getDefaultPerPage()).stream());
}

/**
* Creates a merge request.
*
Expand Down
75 changes: 1 addition & 74 deletions src/main/java/org/gitlab4j/api/models/MergeRequestDiff.java
Original file line number Diff line number Diff line change
@@ -1,87 +1,14 @@
package org.gitlab4j.api.models;

import java.util.Date;
import java.util.List;

import org.gitlab4j.api.utils.JacksonJson;

public class MergeRequestDiff {
public class MergeRequestDiff extends MergeRequestVersion {

private Long id;
private String headCommitSha;
private String baseCommitSha;
private String startCommitSha;
private Date createdAt;
private Long mergeRequestId;
private String state;
private String realSize;
private List<Commit> commits;
private List<Diff> diffs;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getHeadCommitSha() {
return headCommitSha;
}

public void setHeadCommitSha(String headCommitSha) {
this.headCommitSha = headCommitSha;
}

public String getBaseCommitSha() {
return baseCommitSha;
}

public void setBaseCommitSha(String baseCommitSha) {
this.baseCommitSha = baseCommitSha;
}

public String getStartCommitSha() {
return startCommitSha;
}

public void setStartCommitSha(String startCommitSha) {
this.startCommitSha = startCommitSha;
}

public Date getCreatedAt() {
return createdAt;
}

public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}

public Long getMergeRequestId() {
return mergeRequestId;
}

public void setMergeRequestId(Long mergeRequestId) {
this.mergeRequestId = mergeRequestId;
}

public String getState() {
return state;
}

public void setState(String state) {
this.state = state;
}

public String getRealSize() {
return realSize;
}

public void setRealSize(String realSize) {
this.realSize = realSize;
}

public List<Commit> getCommits() {
return commits;
}
Expand Down
86 changes: 86 additions & 0 deletions src/main/java/org/gitlab4j/api/models/MergeRequestVersion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package org.gitlab4j.api.models;

import java.util.Date;

import org.gitlab4j.api.utils.JacksonJson;

public class MergeRequestVersion {

private Long id;
private String headCommitSha;
private String baseCommitSha;
private String startCommitSha;
private Date createdAt;
private Long mergeRequestId;
private String state;
private String realSize;

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getHeadCommitSha() {
return headCommitSha;
}

public void setHeadCommitSha(String headCommitSha) {
this.headCommitSha = headCommitSha;
}

public String getBaseCommitSha() {
return baseCommitSha;
}

public void setBaseCommitSha(String baseCommitSha) {
this.baseCommitSha = baseCommitSha;
}

public String getStartCommitSha() {
return startCommitSha;
}

public void setStartCommitSha(String startCommitSha) {
this.startCommitSha = startCommitSha;
}

public Date getCreatedAt() {
return createdAt;
}

public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}

public Long getMergeRequestId() {
return mergeRequestId;
}

public void setMergeRequestId(Long mergeRequestId) {
this.mergeRequestId = mergeRequestId;
}

public String getState() {
return state;
}

public void setState(String state) {
this.state = state;
}

public String getRealSize() {
return realSize;
}

public void setRealSize(String realSize) {
this.realSize = realSize;
}

@Override
public String toString() {
return (JacksonJson.toJsonString(this));
}
}
7 changes: 7 additions & 0 deletions src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import org.gitlab4j.api.models.Member;
import org.gitlab4j.api.models.MergeRequest;
import org.gitlab4j.api.models.MergeRequestDiff;
import org.gitlab4j.api.models.MergeRequestVersion;
import org.gitlab4j.api.models.Milestone;
import org.gitlab4j.api.models.Note;
import org.gitlab4j.api.models.NotificationSettings;
Expand Down Expand Up @@ -656,6 +657,12 @@ public void testMergeRequestDiffs() throws Exception {
assertTrue(compareJson(diffs, "merge-request-diffs.json"));
}

@Test
public void testMergeRequestVersions() throws Exception {
List<MergeRequestVersion> versions = unmarshalResourceList(MergeRequestVersion.class, "merge-request-versions.json");
assertTrue(compareJson(versions, "merge-request-diffs.json"));
}

@Test
public void testMilestone() throws Exception {
Milestone milestone = unmarshalResource(Milestone.class, "milestone.json");
Expand Down
Loading