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
45040e3d
Commit
45040e3d
authored
Feb 01, 2020
by
Greg Messner
Browse files
Added support for getting merge requests associated with a commit (#502)
parent
899ad6cf
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/CommitsApi.java
View file @
45040e3d
...
@@ -21,6 +21,8 @@ import org.gitlab4j.api.models.CommitRef.RefType;
...
@@ -21,6 +21,8 @@ import org.gitlab4j.api.models.CommitRef.RefType;
import
org.gitlab4j.api.models.CommitStatus
;
import
org.gitlab4j.api.models.CommitStatus
;
import
org.gitlab4j.api.models.CommitStatusFilter
;
import
org.gitlab4j.api.models.CommitStatusFilter
;
import
org.gitlab4j.api.models.Diff
;
import
org.gitlab4j.api.models.Diff
;
import
org.gitlab4j.api.models.GpgSignature
;
import
org.gitlab4j.api.models.MergeRequest
;
import
org.gitlab4j.api.utils.ISO8601
;
import
org.gitlab4j.api.utils.ISO8601
;
/**
/**
...
@@ -793,4 +795,81 @@ public class CommitsApi extends AbstractApi {
...
@@ -793,4 +795,81 @@ public class CommitsApi extends AbstractApi {
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"repository"
,
"commits"
,
sha
,
"cherry_pick"
);
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"repository"
,
"commits"
,
sha
,
"cherry_pick"
);
return
(
response
.
readEntity
(
Commit
.
class
));
return
(
response
.
readEntity
(
Commit
.
class
));
}
}
/**
* Get a list of Merge Requests related to the specified commit.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits/:sha/merge_requests</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param sha the commit SHA to get merge requests for
* @return a list containing the MergeRequest instances for the specified project/SHA
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public
List
<
MergeRequest
>
getMergeRequests
(
Object
projectIdOrPath
,
String
sha
)
throws
GitLabApiException
{
return
(
getMergeRequests
(
projectIdOrPath
,
sha
,
getDefaultPerPage
()).
all
());
}
/**
* Get a Pager of Merge Requests related to the specified commit.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits/:sha/merge_requests</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param sha the commit SHA to get merge requests for
* @param itemsPerPage the number of Commit instances that will be fetched per page
* @return a Pager containing the MergeRequest instances for the specified project/SHA
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public
Pager
<
MergeRequest
>
getMergeRequests
(
Object
projectIdOrPath
,
String
sha
,
int
itemsPerPage
)
throws
GitLabApiException
{
return
(
new
Pager
<
MergeRequest
>(
this
,
MergeRequest
.
class
,
itemsPerPage
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"repository"
,
"commits"
,
urlEncode
(
sha
),
"merge_requests"
));
}
/**
* Get a Stream of Merge Requests related to the specified commit.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits/:sha/merge_requests</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param sha the commit SHA to get merge requests for
* @return a Stream containing the MergeRequest instances for the specified project/SHA
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public
Stream
<
MergeRequest
>
getMergeRequestsStream
(
Object
projectIdOrPath
,
String
sha
)
throws
GitLabApiException
{
return
(
getMergeRequests
(
projectIdOrPath
,
sha
,
getDefaultPerPage
()).
stream
());
}
/**
* Get the GPG signature from a commit, if it is signed. For unsigned commits, it results in a 404 response.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits/:sha/signature</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 the GpgSignature instance for the specified project ID/sha pair
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public
GpgSignature
getGpgSignature
(
Object
projectIdOrPath
,
String
sha
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
getDefaultPerPageParam
(),
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"repository"
,
"commits"
,
urlEncode
(
sha
),
"signature"
);
return
(
response
.
readEntity
(
GpgSignature
.
class
));
}
/**
* Get the GPG signature from a commit as an Optional instance
*
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits/:sha/signature</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 the GpgSignature for the specified project ID/sha pair as an Optional instance
*/
public
Optional
<
GpgSignature
>
getOptionalGpgSignature
(
Object
projectIdOrPath
,
String
sha
)
{
try
{
return
(
Optional
.
ofNullable
(
getGpgSignature
(
projectIdOrPath
,
sha
)));
}
catch
(
GitLabApiException
glae
)
{
return
(
GitLabApi
.
createOptionalFromException
(
glae
));
}
}
}
}
src/main/java/org/gitlab4j/api/models/GpgSignature.java
0 → 100644
View file @
45040e3d
package
org.gitlab4j.api.models
;
import
org.gitlab4j.api.utils.JacksonJson
;
public
class
GpgSignature
{
private
Integer
gpgKeyId
;
private
String
gpgKeyPrimaryKeyid
;
private
String
gpgKeyUserName
;
private
String
gpgKeyUserEmail
;
private
String
verificationStatus
;
private
String
gpgKeySubkeyId
;
public
Integer
getGpgKeyId
()
{
return
gpgKeyId
;
}
public
void
setGpgKeyId
(
Integer
gpgKeyId
)
{
this
.
gpgKeyId
=
gpgKeyId
;
}
public
String
getGpgKeyPrimaryKeyid
()
{
return
gpgKeyPrimaryKeyid
;
}
public
void
setGpgKeyPrimaryKeyid
(
String
gpgKeyPrimaryKeyid
)
{
this
.
gpgKeyPrimaryKeyid
=
gpgKeyPrimaryKeyid
;
}
public
String
getGpgKeyUserName
()
{
return
gpgKeyUserName
;
}
public
void
setGpgKeyUserName
(
String
gpgKeyUserName
)
{
this
.
gpgKeyUserName
=
gpgKeyUserName
;
}
public
String
getGpgKeyUserEmail
()
{
return
gpgKeyUserEmail
;
}
public
void
setGpgKeyUserEmail
(
String
gpgKeyUserEmail
)
{
this
.
gpgKeyUserEmail
=
gpgKeyUserEmail
;
}
public
String
getVerificationStatus
()
{
return
verificationStatus
;
}
public
void
setVerificationStatus
(
String
verificationStatus
)
{
this
.
verificationStatus
=
verificationStatus
;
}
public
String
getGpgKeySubkeyId
()
{
return
gpgKeySubkeyId
;
}
public
void
setGpgKeySubkeyId
(
String
gpgKeySubkeyId
)
{
this
.
gpgKeySubkeyId
=
gpgKeySubkeyId
;
}
@Override
public
String
toString
()
{
return
(
JacksonJson
.
toJsonString
(
this
));
}
}
src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java
View file @
45040e3d
...
@@ -59,6 +59,7 @@ import org.gitlab4j.api.models.EpicIssue;
...
@@ -59,6 +59,7 @@ import org.gitlab4j.api.models.EpicIssue;
import
org.gitlab4j.api.models.Event
;
import
org.gitlab4j.api.models.Event
;
import
org.gitlab4j.api.models.ExportStatus
;
import
org.gitlab4j.api.models.ExportStatus
;
import
org.gitlab4j.api.models.FileUpload
;
import
org.gitlab4j.api.models.FileUpload
;
import
org.gitlab4j.api.models.GpgSignature
;
import
org.gitlab4j.api.models.Group
;
import
org.gitlab4j.api.models.Group
;
import
org.gitlab4j.api.models.HealthCheckInfo
;
import
org.gitlab4j.api.models.HealthCheckInfo
;
import
org.gitlab4j.api.models.ImpersonationToken
;
import
org.gitlab4j.api.models.ImpersonationToken
;
...
@@ -242,6 +243,12 @@ public class TestGitLabApiBeans {
...
@@ -242,6 +243,12 @@ public class TestGitLabApiBeans {
assertTrue
(
compareJson
(
fileUpload
,
"file-upload.json"
));
assertTrue
(
compareJson
(
fileUpload
,
"file-upload.json"
));
}
}
@Test
public
void
testGpgSignature
()
throws
Exception
{
GpgSignature
gpgSignature
=
unmarshalResource
(
GpgSignature
.
class
,
"gpg-signature.json"
);
assertTrue
(
compareJson
(
gpgSignature
,
"gpg-signature.json"
));
}
@Test
@Test
public
void
testIssuesStatistics
()
throws
Exception
{
public
void
testIssuesStatistics
()
throws
Exception
{
IssuesStatistics
statistics
=
unmarshalResource
(
IssuesStatistics
.
class
,
"issues-statistics.json"
);
IssuesStatistics
statistics
=
unmarshalResource
(
IssuesStatistics
.
class
,
"issues-statistics.json"
);
...
...
src/test/resources/org/gitlab4j/api/gpg-signature.json
0 → 100644
View file @
45040e3d
{
"gpg_key_id"
:
1
,
"gpg_key_primary_keyid"
:
"8254AAB3FBD54AC9"
,
"gpg_key_user_name"
:
"John Doe"
,
"gpg_key_user_email"
:
"johndoe@example.com"
,
"verification_status"
:
"verified"
,
"gpg_key_subkey_id"
:
"1234AAB3FBD54AC9"
}
\ 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