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
ec39b573
Commit
ec39b573
authored
Sep 16, 2017
by
orangeStas
Committed by
Greg Messner
Sep 15, 2017
Browse files
Added get commits by path method (#73)
* Added get commits by path method
parent
4f83b9cb
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/CommitsApi.java
View file @
ec39b573
...
...
@@ -87,6 +87,26 @@ public class CommitsApi extends AbstractApi {
return
(
response
.
readEntity
(
new
GenericType
<
List
<
Commit
>>()
{}));
}
/**
* Get a list of file commits in a project
*
* GET /projects/:id/repository/commits?path=:file_path
*
* @param projectId the project ID to get the list of commits for
* @param ref the name of a repository branch or tag or if not given the default branch
* @param path the path to file of a project
* @return a list containing the commits for the specified project ID and file
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public
List
<
Commit
>
getCommits
(
int
projectId
,
String
ref
,
String
path
)
throws
GitLabApiException
{
Form
formData
=
new
GitLabApiForm
()
.
withParam
(
"ref_name"
,
ref
)
.
withParam
(
PER_PAGE_PARAM
,
getDefaultPerPage
());
String
pathArg
=
(
path
==
null
||
path
.
isEmpty
())
?
"commits"
:
"commits"
+
"?path="
+
path
;
Response
response
=
get
(
Response
.
Status
.
OK
,
formData
.
asMap
(),
"projects"
,
projectId
,
"repository"
,
pathArg
);
return
(
response
.
readEntity
(
new
GenericType
<
List
<
Commit
>>()
{}));
}
/**
* Get a list of repository commits in a project.
*
...
...
src/test/java/org/gitlab4j/api/TestCommitsApi.java
View file @
ec39b573
...
...
@@ -147,4 +147,15 @@ public class TestCommitsApi {
assertNotNull
(
pager
);
assertTrue
(
pager
.
getTotalItems
()
>
0
);
}
}
@Test
public
void
testCommitsByPath
()
throws
GitLabApiException
{
Project
project
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_PROJECT_NAME
);
CommitsApi
commitsApi
=
gitLabApi
.
getCommitsApi
();
List
<
Commit
>
commits
=
commitsApi
.
getCommits
(
project
.
getId
(),
"master"
,
"README"
);
assertNotNull
(
commits
);
assertTrue
(
commits
.
size
()
>
0
);
}
}
\ No newline at end of file
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