Commit f3eaaf77 authored by Greg Messner's avatar Greg Messner
Browse files

Added support for getting a singe MR diff (#569)

parent 28f581c8
...@@ -433,6 +433,43 @@ public class MergeRequestApi extends AbstractApi { ...@@ -433,6 +433,43 @@ public class MergeRequestApi extends AbstractApi {
return (getMergeRequestDiffs(projectIdOrPath, mergeRequestIid, getDefaultPerPage()).stream()); return (getMergeRequestDiffs(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 Integer(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 MergeRequestDiff instance for the specified MR diff version
* @throws GitLabApiException if any exception occurs
*/
public MergeRequestDiff getMergeRequestDiff(Object projectIdOrPath,
Integer mergeRequestIid, Integer 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 Integer(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 MergeRequestDiff as an Optional instance instance
*/
public Optional<MergeRequestDiff> getOptionalMergeRequestDiff(
Object projectIdOrPath, Integer mergeRequestIid, Integer versionId) {
try {
return (Optional.ofNullable(getMergeRequestDiff(projectIdOrPath, mergeRequestIid, versionId)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
}
/** /**
* Creates a merge request. * Creates a merge request.
* *
......
package org.gitlab4j.api.models; package org.gitlab4j.api.models;
import java.util.Date; import java.util.Date;
import java.util.List;
import org.gitlab4j.api.utils.JacksonJson;
import org.gitlab4j.api.utils.JacksonJson;
public class MergeRequestDiff {
public class MergeRequestDiff {
private Integer id;
private String headCommitSha; private Integer id;
private String baseCommitSha; private String headCommitSha;
private String startCommitSha; private String baseCommitSha;
private Date createdAt; private String startCommitSha;
private Integer mergeRequestId; private Date createdAt;
private String state; private Integer mergeRequestId;
private String realSize; private String state;
private String realSize;
public Integer getId() { private List<Commit> commits;
return id; private List<Diff> diffs;
}
public Integer getId() {
public void setId(Integer id) { return id;
this.id = id; }
}
public void setId(Integer id) {
public String getHeadCommitSha() { this.id = id;
return headCommitSha; }
}
public String getHeadCommitSha() {
public void setHeadCommitSha(String headCommitSha) { return headCommitSha;
this.headCommitSha = headCommitSha; }
}
public void setHeadCommitSha(String headCommitSha) {
public String getBaseCommitSha() { this.headCommitSha = headCommitSha;
return baseCommitSha; }
}
public String getBaseCommitSha() {
public void setBaseCommitSha(String baseCommitSha) { return baseCommitSha;
this.baseCommitSha = baseCommitSha; }
}
public void setBaseCommitSha(String baseCommitSha) {
public String getStartCommitSha() { this.baseCommitSha = baseCommitSha;
return startCommitSha; }
}
public String getStartCommitSha() {
public void setStartCommitSha(String startCommitSha) { return startCommitSha;
this.startCommitSha = startCommitSha; }
}
public void setStartCommitSha(String startCommitSha) {
public Date getCreatedAt() { this.startCommitSha = startCommitSha;
return createdAt; }
}
public Date getCreatedAt() {
public void setCreatedAt(Date createdAt) { return createdAt;
this.createdAt = createdAt; }
}
public void setCreatedAt(Date createdAt) {
public Integer getMergeRequestId() { this.createdAt = createdAt;
return mergeRequestId; }
}
public Integer getMergeRequestId() {
public void setMergeRequestId(Integer mergeRequestId) { return mergeRequestId;
this.mergeRequestId = mergeRequestId; }
}
public void setMergeRequestId(Integer mergeRequestId) {
public String getState() { this.mergeRequestId = mergeRequestId;
return state; }
}
public String getState() {
public void setState(String state) { return state;
this.state = state; }
}
public void setState(String state) {
public String getRealSize() { this.state = state;
return realSize; }
}
public String getRealSize() {
public void setRealSize(String realSize) { return realSize;
this.realSize = realSize; }
}
public void setRealSize(String realSize) {
@Override this.realSize = realSize;
public String toString() { }
return (JacksonJson.toJsonString(this));
} public List<Commit> getCommits() {
} return commits;
}
public void setCommits(List<Commit> commits) {
this.commits = commits;
}
public List<Diff> getDiffs() {
return diffs;
}
public void setDiffs(List<Diff> diffs) {
this.diffs = diffs;
}
@Override
public String toString() {
return (JacksonJson.toJsonString(this));
}
}
...@@ -539,6 +539,12 @@ public class TestGitLabApiBeans { ...@@ -539,6 +539,12 @@ public class TestGitLabApiBeans {
assertTrue(compareJson(mergeRequest, "merge-request.json")); assertTrue(compareJson(mergeRequest, "merge-request.json"));
} }
@Test
public void testMergeRequestDiff() throws Exception {
MergeRequestDiff diff = unmarshalResource(MergeRequestDiff.class, "merge-request-diff.json");
assertTrue(compareJson(diff, "merge-request-diff.json"));
}
@Test @Test
public void testMergeRequestDiffs() throws Exception { public void testMergeRequestDiffs() throws Exception {
List<MergeRequestDiff> diffs = unmarshalResourceList(MergeRequestDiff.class, "merge-request-diffs.json"); List<MergeRequestDiff> diffs = unmarshalResourceList(MergeRequestDiff.class, "merge-request-diffs.json");
......
{
"id": 110,
"head_commit_sha": "33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30",
"base_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd",
"start_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd",
"created_at": "2016-07-26T14:44:48.926Z",
"merge_request_id": 105,
"state": "collected",
"real_size": "1",
"commits": [{
"id": "33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30",
"short_id": "33e2ee85",
"title": "Change year to 2018",
"author_name": "Administrator",
"author_email": "admin@example.com",
"created_at": "2016-07-26T17:44:29Z",
"message": "Change year to 2018"
}, {
"id": "aa24655de48b36335556ac8a3cd8bb521f977cbd",
"short_id": "aa24655d",
"title": "Update LICENSE",
"author_name": "Administrator",
"author_email": "admin@example.com",
"created_at": "2016-07-25T17:21:53Z",
"message": "Update LICENSE"
}, {
"id": "3eed087b29835c48015768f839d76e5ea8f07a24",
"short_id": "3eed087b",
"title": "Add license",
"author_name": "Administrator",
"author_email": "admin@example.com",
"created_at": "2016-07-25T17:21:20Z",
"message": "Add license"
}],
"diffs": [{
"old_path": "LICENSE",
"new_path": "LICENSE",
"a_mode": "0",
"b_mode": "100644",
"diff": "--- /dev/null\n+++ b/LICENSE\n@@ -0,0 +1,21 @@\n+The MIT License (MIT)\n+\n+Copyright (c) 2018 Administrator\n+\n+Permission is hereby granted, free of charge, to any person obtaining a copy\n+of this software and associated documentation files (the \"Software\"), to deal\n+in the Software without restriction, including without limitation the rights\n+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+copies of the Software, and to permit persons to whom the Software is\n+furnished to do so, subject to the following conditions:\n+\n+The above copyright notice and this permission notice shall be included in all\n+copies or substantial portions of the Software.\n+\n+THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n+SOFTWARE.\n",
"new_file": true,
"renamed_file": false,
"deleted_file": false
}]
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment