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
28be1a72
Commit
28be1a72
authored
Apr 23, 2018
by
Greg Messner
Browse files
Mods to support new services (#175, #176).
parent
d4abafc3
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/AbstractApi.java
View file @
28be1a72
...
...
@@ -47,7 +47,7 @@ public abstract class AbstractApi implements Constants {
return
(
id
);
}
String
path
=
((
Project
)
obj
).
getPath
();
String
path
=
((
Project
)
obj
).
getPath
WithNamespace
();
if
(
path
!=
null
&&
path
.
trim
().
length
()
>
0
)
{
return
(
urlEncode
(
path
.
trim
()));
}
...
...
src/main/java/org/gitlab4j/api/ServicesApi.java
View file @
28be1a72
...
...
@@ -26,6 +26,7 @@ public class ServicesApi extends AbstractApi {
* @param token for authentication
* @param projectCIUrl URL of the GitLab-CI project
* @throws GitLabApiException if any exception occurs
* @deprecated No longer supported
*/
public
void
setGitLabCI
(
Object
projectIdOrPath
,
String
token
,
String
projectCIUrl
)
throws
GitLabApiException
{
final
Form
formData
=
new
Form
();
...
...
@@ -41,6 +42,7 @@ public class ServicesApi extends AbstractApi {
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @throws GitLabApiException if any exception occurs
* @deprecated No longer supported
*/
public
void
deleteGitLabCI
(
Object
projectIdOrPath
)
throws
GitLabApiException
{
Response
.
Status
expectedStatus
=
(
isApiVersion
(
ApiVersion
.
V3
)
?
Response
.
Status
.
OK
:
Response
.
Status
.
NO_CONTENT
);
...
...
@@ -56,7 +58,7 @@ public class ServicesApi extends AbstractApi {
* @return a HipChatService instance holding the HipChatService notification settings
* @throws GitLabApiException if any exception occurs
*/
public
HipChatService
getHipChat
(
Object
projectIdOrPath
)
throws
GitLabApiException
{
public
HipChatService
getHipChat
Service
(
Object
projectIdOrPath
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"services"
,
"hipchat"
);
return
(
response
.
readEntity
(
HipChatService
.
class
));
}
...
...
@@ -89,7 +91,7 @@ public class ServicesApi extends AbstractApi {
* @return a HipChatService instance holding the newly updated settings
* @throws GitLabApiException if any exception occurs
*/
public
HipChatService
updateHipChat
(
Object
projectIdOrPath
,
HipChatService
hipChat
)
throws
GitLabApiException
{
public
HipChatService
updateHipChat
Service
(
Object
projectIdOrPath
,
HipChatService
hipChat
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"push_events"
,
hipChat
.
getPushEvents
())
.
withParam
(
"issues_events"
,
hipChat
.
getIssuesEvents
())
...
...
@@ -137,12 +139,25 @@ public class ServicesApi extends AbstractApi {
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @throws GitLabApiException if any exception occurs
* @deprecated replaced with {@link #deleteHipChatService(Object) updateHipChat} method
*/
public
void
deleteHipChat
(
Object
projectIdOrPath
)
throws
GitLabApiException
{
deleteHipChatService
(
projectIdOrPath
);
}
/**
* Deletes the HipChatService service for a project.
*
* DELETE /projects/:id/services/hipchat
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @throws GitLabApiException if any exception occurs
*/
public
void
deleteHipChatService
(
Object
projectIdOrPath
)
throws
GitLabApiException
{
Response
.
Status
expectedStatus
=
(
isApiVersion
(
ApiVersion
.
V3
)
?
Response
.
Status
.
OK
:
Response
.
Status
.
NO_CONTENT
);
delete
(
expectedStatus
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"services"
,
"hipchat"
);
}
/**
* Get the Slack notification settings for a project.
*
...
...
@@ -152,7 +167,7 @@ public class ServicesApi extends AbstractApi {
* @return a SlackService instance holding the Slack notification settings
* @throws GitLabApiException if any exception occurs
*/
public
SlackService
getSlack
Notifications
(
Object
projectIdOrPath
)
throws
GitLabApiException
{
public
SlackService
getSlack
Service
(
Object
projectIdOrPath
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"services"
,
"slack"
);
return
(
response
.
readEntity
(
SlackService
.
class
));
}
...
...
@@ -193,7 +208,7 @@ public class ServicesApi extends AbstractApi {
* @return a SlackService instance holding the newly updated settings
* @throws GitLabApiException if any exception occurs
*/
public
SlackService
updateSlack
Notifications
(
Object
projectIdOrPath
,
SlackService
slackNotifications
)
throws
GitLabApiException
{
public
SlackService
updateSlack
Service
(
Object
projectIdOrPath
,
SlackService
slackNotifications
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"webhook"
,
slackNotifications
.
getWebhook
(),
true
)
.
withParam
(
"username"
,
slackNotifications
.
getUsername
())
...
...
@@ -230,7 +245,7 @@ public class ServicesApi extends AbstractApi {
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @throws GitLabApiException if any exception occurs
*/
public
void
deleteSlack
Notifications
(
Object
projectIdOrPath
)
throws
GitLabApiException
{
public
void
deleteSlack
Service
(
Object
projectIdOrPath
)
throws
GitLabApiException
{
Response
.
Status
expectedStatus
=
(
isApiVersion
(
ApiVersion
.
V3
)
?
Response
.
Status
.
OK
:
Response
.
Status
.
NO_CONTENT
);
delete
(
expectedStatus
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"services"
,
"slack"
);
}
...
...
@@ -244,7 +259,7 @@ public class ServicesApi extends AbstractApi {
* @return a JiraService instance holding the JIRA service settings
* @throws GitLabApiException if any exception occurs
*/
public
JiraService
getJira
(
Object
projectIdOrPath
)
throws
GitLabApiException
{
public
JiraService
getJira
Service
(
Object
projectIdOrPath
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"services"
,
"jira"
);
return
(
response
.
readEntity
(
JiraService
.
class
));
}
...
...
@@ -270,7 +285,7 @@ public class ServicesApi extends AbstractApi {
* @return a JiraService instance holding the newly updated settings
* @throws GitLabApiException if any exception occurs
*/
public
JiraService
updateJira
(
Object
projectIdOrPath
,
JiraService
jira
)
throws
GitLabApiException
{
public
JiraService
updateJira
Service
(
Object
projectIdOrPath
,
JiraService
jira
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"merge_requests_events"
,
jira
.
getMergeRequestsEvents
())
.
withParam
(
"commit_events"
,
jira
.
getCommitEvents
())
...
...
@@ -292,7 +307,7 @@ public class ServicesApi extends AbstractApi {
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @throws GitLabApiException if any exception occurs
*/
public
void
deleteJira
(
Object
projectIdOrPath
)
throws
GitLabApiException
{
public
void
deleteJira
Service
(
Object
projectIdOrPath
)
throws
GitLabApiException
{
Response
.
Status
expectedStatus
=
(
isApiVersion
(
ApiVersion
.
V3
)
?
Response
.
Status
.
OK
:
Response
.
Status
.
NO_CONTENT
);
delete
(
expectedStatus
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"services"
,
"jira"
);
}
...
...
src/main/java/org/gitlab4j/api/services/JiraService.java
View file @
28be1a72
...
...
@@ -4,8 +4,6 @@ import javax.xml.bind.annotation.XmlAccessType;
import
javax.xml.bind.annotation.XmlAccessorType
;
import
javax.xml.bind.annotation.XmlRootElement
;
import
org.gitlab4j.api.utils.SecretString
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
@XmlRootElement
...
...
@@ -18,7 +16,7 @@ public class JiraService extends NotificationService {
public
static
final
String
USERNAME_PROP
=
"username"
;
public
static
final
String
JIRA_ISSUE_TRANSITION_ID_PROP
=
"jira_issue_transition_id"
;
private
SecretString
password
;
private
CharSequence
password
;
public
JiraService
withCommitEvents
(
Boolean
commitEvents
)
{
return
withCommitEvents
(
commitEvents
,
this
);
...
...
@@ -29,15 +27,15 @@ public class JiraService extends NotificationService {
}
@JsonIgnore
public
SecretString
getPassword
()
{
public
CharSequence
getPassword
()
{
return
password
;
}
public
void
setPassword
(
SecretString
password
)
{
public
void
setPassword
(
CharSequence
password
)
{
this
.
password
=
password
;
}
public
JiraService
with
Url
(
SecretString
password
)
{
public
JiraService
with
Password
(
CharSequence
password
)
{
setPassword
(
password
);
return
(
this
);
}
...
...
src/main/java/org/gitlab4j/api/services/NotificationService.java
View file @
28be1a72
...
...
@@ -84,7 +84,7 @@ public abstract class NotificationService {
this
.
pushEvents
=
pushEvents
;
}
p
ublic
<
T
>
T
withPushEvents
(
Boolean
pushEvents
,
T
derivedInstance
)
{
p
rotected
<
T
>
T
withPushEvents
(
Boolean
pushEvents
,
T
derivedInstance
)
{
this
.
pushEvents
=
pushEvents
;
return
(
derivedInstance
);
}
...
...
@@ -97,7 +97,7 @@ public abstract class NotificationService {
this
.
issuesEvents
=
issuesEvents
;
}
p
ublic
<
T
>
T
withIssuesEvents
(
Boolean
issuesEvents
,
T
derivedInstance
)
{
p
rotected
<
T
>
T
withIssuesEvents
(
Boolean
issuesEvents
,
T
derivedInstance
)
{
this
.
issuesEvents
=
issuesEvents
;
return
(
derivedInstance
);
}
...
...
@@ -110,7 +110,7 @@ public abstract class NotificationService {
this
.
confidentialIssuesEvents
=
confidentialIssuesEvents
;
}
p
ublic
<
T
>
T
withConfidentialIssuesEvents
(
Boolean
confidentialIssuesEvents
,
T
derivedInstance
)
{
p
rotected
<
T
>
T
withConfidentialIssuesEvents
(
Boolean
confidentialIssuesEvents
,
T
derivedInstance
)
{
this
.
confidentialIssuesEvents
=
confidentialIssuesEvents
;
return
(
derivedInstance
);
}
...
...
@@ -124,7 +124,7 @@ public abstract class NotificationService {
this
.
commitEvents
=
commitEvents
;
}
p
ublic
<
T
>
T
withCommitEvents
(
Boolean
commitEvents
,
T
derivedInstance
)
{
p
rotected
<
T
>
T
withCommitEvents
(
Boolean
commitEvents
,
T
derivedInstance
)
{
setCommitEvents
(
commitEvents
);
return
(
derivedInstance
);
}
...
...
@@ -137,7 +137,7 @@ public abstract class NotificationService {
this
.
mergeRequestsEvents
=
mergeRequestsEvents
;
}
p
ublic
<
T
>
T
withMergeRequestsEvents
(
Boolean
mergeRequestsEvents
,
T
derivedInstance
)
{
p
rotected
<
T
>
T
withMergeRequestsEvents
(
Boolean
mergeRequestsEvents
,
T
derivedInstance
)
{
this
.
mergeRequestsEvents
=
mergeRequestsEvents
;
return
(
derivedInstance
);
}
...
...
@@ -150,7 +150,7 @@ public abstract class NotificationService {
this
.
tagPushEvents
=
tagPushEvents
;
}
p
ublic
<
T
>
T
withTagPushEvents
(
Boolean
tagPushEvents
,
T
derivedInstance
)
{
p
rotected
<
T
>
T
withTagPushEvents
(
Boolean
tagPushEvents
,
T
derivedInstance
)
{
this
.
tagPushEvents
=
tagPushEvents
;
return
(
derivedInstance
);
}
...
...
@@ -163,7 +163,7 @@ public abstract class NotificationService {
this
.
noteEvents
=
noteEvents
;
}
p
ublic
<
T
>
T
withNoteEvents
(
Boolean
noteEvents
,
T
derivedInstance
)
{
p
rotected
<
T
>
T
withNoteEvents
(
Boolean
noteEvents
,
T
derivedInstance
)
{
this
.
noteEvents
=
noteEvents
;
return
(
derivedInstance
);
}
...
...
@@ -176,7 +176,7 @@ public abstract class NotificationService {
this
.
confidentialNoteEvents
=
confidentialNoteEvents
;
}
p
ublic
<
T
>
T
withConfidentialNoteEvents
(
Boolean
confidentialNoteEvents
,
T
derivedInstance
)
{
p
rotected
<
T
>
T
withConfidentialNoteEvents
(
Boolean
confidentialNoteEvents
,
T
derivedInstance
)
{
this
.
confidentialNoteEvents
=
confidentialNoteEvents
;
return
(
derivedInstance
);
}
...
...
@@ -189,7 +189,7 @@ public abstract class NotificationService {
this
.
pipelineEvents
=
pipelineEvents
;
}
p
ublic
<
T
>
T
withPipelineEvents
(
Boolean
pipelineEvents
,
T
derivedInstance
)
{
p
rotected
<
T
>
T
withPipelineEvents
(
Boolean
pipelineEvents
,
T
derivedInstance
)
{
this
.
pipelineEvents
=
pipelineEvents
;
return
(
derivedInstance
);
}
...
...
@@ -202,7 +202,7 @@ public abstract class NotificationService {
this
.
wikiPageEvents
=
wikiPageEvents
;
}
p
ublic
<
T
>
T
withWikiPageEvents
(
Boolean
wikiPageEvents
,
T
derivedInstance
)
{
p
rotected
<
T
>
T
withWikiPageEvents
(
Boolean
wikiPageEvents
,
T
derivedInstance
)
{
this
.
wikiPageEvents
=
wikiPageEvents
;
return
(
derivedInstance
);
}
...
...
@@ -215,7 +215,7 @@ public abstract class NotificationService {
this
.
jobEvents
=
jobEvents
;
}
p
ublic
<
T
>
T
withJobEvents
(
Boolean
jobEvents
,
T
derivedInstance
)
{
p
rotected
<
T
>
T
withJobEvents
(
Boolean
jobEvents
,
T
derivedInstance
)
{
this
.
jobEvents
=
jobEvents
;
return
(
derivedInstance
);
}
...
...
src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java
View file @
28be1a72
...
...
@@ -57,7 +57,7 @@ import org.gitlab4j.api.models.Project;
import
org.gitlab4j.api.models.ProjectHook
;
import
org.gitlab4j.api.models.ProjectUser
;
import
org.gitlab4j.api.models.ProtectedBranch
;
import
org.gitlab4j.api.models.PushRule
;
import
org.gitlab4j.api.models.PushRule
s
;
import
org.gitlab4j.api.models.Runner
;
import
org.gitlab4j.api.models.RunnerDetail
;
import
org.gitlab4j.api.models.Session
;
...
...
@@ -67,6 +67,7 @@ import org.gitlab4j.api.models.SystemHook;
import
org.gitlab4j.api.models.Tag
;
import
org.gitlab4j.api.models.TreeItem
;
import
org.gitlab4j.api.models.User
;
import
org.gitlab4j.api.services.JiraService
;
import
org.gitlab4j.api.services.SlackService
;
import
org.gitlab4j.api.systemhooks.ProjectSystemHookEvent
;
import
org.gitlab4j.api.systemhooks.PushSystemHookEvent
;
...
...
@@ -310,7 +311,7 @@ public class TestGitLabApiBeans {
public
void
testPushRule
()
{
try
{
PushRule
pushRule
=
makeFakeApiCall
(
PushRule
.
class
,
"push-rule"
);
PushRule
s
pushRule
=
makeFakeApiCall
(
PushRule
s
.
class
,
"push-rule"
);
assertTrue
(
compareJson
(
pushRule
,
"push-rule"
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
...
...
@@ -343,6 +344,17 @@ public class TestGitLabApiBeans {
}
}
@Test
public
void
testJiraService
()
{
try
{
JiraService
jira
=
makeFakeApiCall
(
JiraService
.
class
,
"jira"
);
assertTrue
(
compareJson
(
jira
,
"jira"
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
testKey
()
{
...
...
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