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
6e248bcc
Unverified
Commit
6e248bcc
authored
Apr 26, 2023
by
Jérémie Bresson
Committed by
GitHub
Apr 26, 2023
Browse files
Add repository submodules api (#956)
* Add repository submodules api Fixes #921 * Fix unit test
parent
384dcfa9
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/RepositorySubmodulesApi.java
0 → 100644
View file @
6e248bcc
package
org.gitlab4j.api
;
import
javax.ws.rs.core.Response
;
import
org.gitlab4j.api.models.Commit
;
/**
* <p>This class provides an entry point to all the GitLab API repository submodules calls.
* For more information on the repository APIs see:</p>
*
* @see <a href="https://docs.gitlab.com/ee/api/repository_submodules.html">Repository Submodules API</a>
*/
public
class
RepositorySubmodulesApi
extends
AbstractApi
{
public
RepositorySubmodulesApi
(
GitLabApi
gitLabApi
)
{
super
(
gitLabApi
);
}
/**
* Update existing submodule reference in repository.
*
* <pre><code>GitLab Endpoint: PUT /projects/:id/repository/submodules/:submodule</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param submodule full path to the submodule
* @param branch name of the branch to commit into
* @param commitSha full commit SHA to update the submodule to
* @param commitMessage commit message (optional). If no message is provided, a default is set
* @return the created commit
* @throws GitLabApiException if any exception occurs
*/
public
Commit
updateExistingSubmoduleReference
(
Object
projectIdOrPath
,
String
submodule
,
String
branch
,
String
commitSha
,
String
commitMessage
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"branch"
,
branch
,
true
)
.
withParam
(
"commit_sha"
,
commitSha
,
true
)
.
withParam
(
"commit_message"
,
commitMessage
);
Response
response
=
put
(
Response
.
Status
.
OK
,
formData
.
asMap
(),
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"repository"
,
"submodules"
,
urlEncode
(
submodule
));
return
(
response
.
readEntity
(
Commit
.
class
));
}
}
src/test/java/org/gitlab4j/api/TestRepositorySubmodulesApi.java
0 → 100644
View file @
6e248bcc
package
org.gitlab4j.api
;
import
static
org
.
gitlab4j
.
api
.
JsonUtils
.
compareJson
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertNotNull
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
mockito
.
MockitoAnnotations
.
openMocks
;
import
java.io.IOException
;
import
javax.ws.rs.core.MultivaluedMap
;
import
org.gitlab4j.api.models.Commit
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.mockito.ArgumentCaptor
;
import
org.mockito.Captor
;
import
org.mockito.Mock
;
import
org.mockito.Mockito
;
public
class
TestRepositorySubmodulesApi
implements
Constants
{
@Mock
private
GitLabApi
gitLabApi
;
@Mock
private
GitLabApiClient
gitLabApiClient
;
@Captor
private
ArgumentCaptor
<
MultivaluedMap
<
String
,
String
>>
attributeCaptor
;
private
MockResponse
response
;
@BeforeEach
public
void
setUp
()
throws
Exception
{
openMocks
(
this
);
}
@Test
public
void
testUpdateExistingSubmoduleReference
()
throws
Exception
{
init
();
Commit
result
=
new
RepositorySubmodulesApi
(
gitLabApi
).
updateExistingSubmoduleReference
(
6L
,
"my-sub"
,
"patch-1"
,
"33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30"
,
"message"
);
assertNotNull
(
result
);
assertTrue
(
compareJson
(
result
,
"commit.json"
));
}
private
void
init
()
throws
Exception
,
IOException
{
response
=
new
MockResponse
(
Commit
.
class
,
"commit.json"
,
null
);
when
(
gitLabApi
.
getApiClient
()).
thenReturn
(
gitLabApiClient
);
when
(
gitLabApiClient
.
validateSecretToken
(
any
())).
thenReturn
(
true
);
when
(
gitLabApiClient
.
put
(
attributeCaptor
.
capture
(),
Mockito
.<
Object
>
any
())).
thenReturn
(
response
);
}
}
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