Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
e1a54855
Commit
e1a54855
authored
Jan 14, 2020
by
Greg Messner
Browse files
Added Page and Stream methods for getDiff() (#497)
parent
897e1db0
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/CommitsApi.java
View file @
e1a54855
...
...
@@ -537,8 +537,46 @@ public class CommitsApi extends AbstractApi {
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public
List
<
Diff
>
getDiff
(
Object
projectIdOrPath
,
String
sha
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"repository"
,
"commits"
,
sha
,
"diff"
);
return
(
response
.
readEntity
(
new
GenericType
<
List
<
Diff
>>()
{}));
return
(
getDiff
(
projectIdOrPath
,
sha
,
getDefaultPerPage
()).
all
());
}
/**
* Get the Pager of diffs of a commit in a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits/:sha/diff</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param sha a commit hash or name of a branch or tag
* @param itemsPerPage the number of Diff instances that will be fetched per page
* @return a Pager of Diff instances for the specified project ID/sha pair
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public
Pager
<
Diff
>
getDiff
(
Object
projectIdOrPath
,
String
sha
,
int
itemsPerPage
)
throws
GitLabApiException
{
if
(
projectIdOrPath
==
null
)
{
throw
new
RuntimeException
(
"projectIdOrPath cannot be null"
);
}
if
(
sha
==
null
||
sha
.
trim
().
isEmpty
())
{
throw
new
RuntimeException
(
"sha cannot be null"
);
}
return
(
new
Pager
<
Diff
>(
this
,
Diff
.
class
,
itemsPerPage
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"repository"
,
"commits"
,
sha
,
"diff"
));
}
/**
* Get the Diff of diffs of a commit in a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits/:sha/diff</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param sha a commit hash or name of a branch or tag
* @return a Stream of Diff instances for the specified project ID/sha pair
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public
Stream
<
Diff
>
getDiffStream
(
Object
projectIdOrPath
,
String
sha
)
throws
GitLabApiException
{
return
(
getDiff
(
projectIdOrPath
,
sha
,
getDefaultPerPage
()).
stream
());
}
/**
...
...
src/test/java/org/gitlab4j/api/TestCommitsApi.java
View file @
e1a54855
...
...
@@ -13,6 +13,7 @@ import java.util.Arrays;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.stream.Stream
;
import
javax.ws.rs.core.Response
;
import
org.gitlab4j.api.models.Branch
;
...
...
@@ -95,6 +96,18 @@ public class TestCommitsApi extends AbstractIntegrationTest {
assertTrue
(
diffs
.
size
()
>
0
);
}
@Test
public
void
testDiffStream
()
throws
GitLabApiException
{
assertNotNull
(
testProject
);
List
<
Commit
>
commits
=
gitLabApi
.
getCommitsApi
().
getCommits
(
testProject
.
getId
());
assertTrue
(
commits
.
size
()
>
0
);
Stream
<
Diff
>
diffs
=
gitLabApi
.
getCommitsApi
().
getDiffStream
(
testProject
.
getId
(),
commits
.
get
(
0
).
getId
());
assertTrue
(
diffs
.
count
()
>
0
);
}
@Test
public
void
testComments
()
throws
GitLabApiException
,
ParseException
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment