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 {
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.
*
......
package org.gitlab4j.api.models;
import java.util.Date;
import org.gitlab4j.api.utils.JacksonJson;
public class MergeRequestDiff {
private Integer id;
private String headCommitSha;
private String baseCommitSha;
private String startCommitSha;
private Date createdAt;
private Integer mergeRequestId;
private String state;
private String realSize;
public Integer getId() {
return id;
}
public void setId(Integer 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 Integer getMergeRequestId() {
return mergeRequestId;
}
public void setMergeRequestId(Integer 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));
}
}
package org.gitlab4j.api.models;
import java.util.Date;
import java.util.List;
import org.gitlab4j.api.utils.JacksonJson;
public class MergeRequestDiff {
private Integer id;
private String headCommitSha;
private String baseCommitSha;
private String startCommitSha;
private Date createdAt;
private Integer mergeRequestId;
private String state;
private String realSize;
private List<Commit> commits;
private List<Diff> diffs;
public Integer getId() {
return id;
}
public void setId(Integer 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 Integer getMergeRequestId() {
return mergeRequestId;
}
public void setMergeRequestId(Integer 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;
}
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 {
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
public void testMergeRequestDiffs() throws Exception {
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