Skip to content

Commit 28be1a7

Browse files
committed
Mods to support new services (#175, #176).
1 parent d4abafc commit 28be1a7

File tree

5 files changed

+54
-29
lines changed

5 files changed

+54
-29
lines changed

src/main/java/org/gitlab4j/api/AbstractApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public Object getProjectIdOrPath(Object obj) throws GitLabApiException {
4747
return (id);
4848
}
4949

50-
String path = ((Project) obj).getPath();
50+
String path = ((Project) obj).getPathWithNamespace();
5151
if (path != null && path.trim().length() > 0) {
5252
return (urlEncode(path.trim()));
5353
}

src/main/java/org/gitlab4j/api/ServicesApi.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public ServicesApi(GitLabApi gitLabApi) {
2626
* @param token for authentication
2727
* @param projectCIUrl URL of the GitLab-CI project
2828
* @throws GitLabApiException if any exception occurs
29+
* @deprecated No longer supported
2930
*/
3031
public void setGitLabCI(Object projectIdOrPath, String token, String projectCIUrl) throws GitLabApiException {
3132
final Form formData = new Form();
@@ -41,6 +42,7 @@ public void setGitLabCI(Object projectIdOrPath, String token, String projectCIUr
4142
*
4243
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
4344
* @throws GitLabApiException if any exception occurs
45+
* @deprecated No longer supported
4446
*/
4547
public void deleteGitLabCI(Object projectIdOrPath) throws GitLabApiException {
4648
Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
@@ -56,7 +58,7 @@ public void deleteGitLabCI(Object projectIdOrPath) throws GitLabApiException {
5658
* @return a HipChatService instance holding the HipChatService notification settings
5759
* @throws GitLabApiException if any exception occurs
5860
*/
59-
public HipChatService getHipChat(Object projectIdOrPath) throws GitLabApiException {
61+
public HipChatService getHipChatService(Object projectIdOrPath) throws GitLabApiException {
6062
Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "hipchat");
6163
return (response.readEntity(HipChatService.class));
6264
}
@@ -89,7 +91,7 @@ public HipChatService getHipChat(Object projectIdOrPath) throws GitLabApiExcepti
8991
* @return a HipChatService instance holding the newly updated settings
9092
* @throws GitLabApiException if any exception occurs
9193
*/
92-
public HipChatService updateHipChat(Object projectIdOrPath, HipChatService hipChat) throws GitLabApiException {
94+
public HipChatService updateHipChatService(Object projectIdOrPath, HipChatService hipChat) throws GitLabApiException {
9395
GitLabApiForm formData = new GitLabApiForm()
9496
.withParam("push_events", hipChat.getPushEvents())
9597
.withParam("issues_events", hipChat.getIssuesEvents())
@@ -137,12 +139,25 @@ public void setHipChat(Object projectIdOrPath, String token, String room, String
137139
*
138140
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
139141
* @throws GitLabApiException if any exception occurs
142+
* @deprecated replaced with {@link #deleteHipChatService(Object) updateHipChat} method
140143
*/
141144
public void deleteHipChat(Object projectIdOrPath) throws GitLabApiException {
145+
deleteHipChatService(projectIdOrPath);
146+
}
147+
148+
/**
149+
* Deletes the HipChatService service for a project.
150+
*
151+
* DELETE /projects/:id/services/hipchat
152+
*
153+
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
154+
* @throws GitLabApiException if any exception occurs
155+
*/
156+
public void deleteHipChatService(Object projectIdOrPath) throws GitLabApiException {
142157
Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
143158
delete(expectedStatus, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "hipchat");
144159
}
145-
160+
146161
/**
147162
* Get the Slack notification settings for a project.
148163
*
@@ -152,7 +167,7 @@ public void deleteHipChat(Object projectIdOrPath) throws GitLabApiException {
152167
* @return a SlackService instance holding the Slack notification settings
153168
* @throws GitLabApiException if any exception occurs
154169
*/
155-
public SlackService getSlackNotifications(Object projectIdOrPath) throws GitLabApiException {
170+
public SlackService getSlackService(Object projectIdOrPath) throws GitLabApiException {
156171
Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "slack");
157172
return (response.readEntity(SlackService.class));
158173
}
@@ -193,7 +208,7 @@ public SlackService getSlackNotifications(Object projectIdOrPath) throws GitLabA
193208
* @return a SlackService instance holding the newly updated settings
194209
* @throws GitLabApiException if any exception occurs
195210
*/
196-
public SlackService updateSlackNotifications(Object projectIdOrPath, SlackService slackNotifications) throws GitLabApiException {
211+
public SlackService updateSlackService(Object projectIdOrPath, SlackService slackNotifications) throws GitLabApiException {
197212
GitLabApiForm formData = new GitLabApiForm()
198213
.withParam("webhook", slackNotifications.getWebhook(), true)
199214
.withParam("username", slackNotifications.getUsername())
@@ -230,7 +245,7 @@ public SlackService updateSlackNotifications(Object projectIdOrPath, SlackServic
230245
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
231246
* @throws GitLabApiException if any exception occurs
232247
*/
233-
public void deleteSlackNotifications(Object projectIdOrPath) throws GitLabApiException {
248+
public void deleteSlackService(Object projectIdOrPath) throws GitLabApiException {
234249
Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
235250
delete(expectedStatus, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "slack");
236251
}
@@ -244,7 +259,7 @@ public void deleteSlackNotifications(Object projectIdOrPath) throws GitLabApiExc
244259
* @return a JiraService instance holding the JIRA service settings
245260
* @throws GitLabApiException if any exception occurs
246261
*/
247-
public JiraService getJira(Object projectIdOrPath) throws GitLabApiException {
262+
public JiraService getJiraService(Object projectIdOrPath) throws GitLabApiException {
248263
Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "jira");
249264
return (response.readEntity(JiraService.class));
250265
}
@@ -270,7 +285,7 @@ public JiraService getJira(Object projectIdOrPath) throws GitLabApiException {
270285
* @return a JiraService instance holding the newly updated settings
271286
* @throws GitLabApiException if any exception occurs
272287
*/
273-
public JiraService updateJira(Object projectIdOrPath, JiraService jira) throws GitLabApiException {
288+
public JiraService updateJiraService(Object projectIdOrPath, JiraService jira) throws GitLabApiException {
274289
GitLabApiForm formData = new GitLabApiForm()
275290
.withParam("merge_requests_events", jira.getMergeRequestsEvents())
276291
.withParam("commit_events", jira.getCommitEvents())
@@ -292,7 +307,7 @@ public JiraService updateJira(Object projectIdOrPath, JiraService jira) throws G
292307
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
293308
* @throws GitLabApiException if any exception occurs
294309
*/
295-
public void deleteJira(Object projectIdOrPath) throws GitLabApiException {
310+
public void deleteJiraService(Object projectIdOrPath) throws GitLabApiException {
296311
Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
297312
delete(expectedStatus, null, "projects", getProjectIdOrPath(projectIdOrPath), "services", "jira");
298313
}

src/main/java/org/gitlab4j/api/services/JiraService.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import javax.xml.bind.annotation.XmlAccessorType;
55
import javax.xml.bind.annotation.XmlRootElement;
66

7-
import org.gitlab4j.api.utils.SecretString;
8-
97
import com.fasterxml.jackson.annotation.JsonIgnore;
108

119
@XmlRootElement
@@ -18,7 +16,7 @@ public class JiraService extends NotificationService {
1816
public static final String USERNAME_PROP = "username";
1917
public static final String JIRA_ISSUE_TRANSITION_ID_PROP = "jira_issue_transition_id";
2018

21-
private SecretString password;
19+
private CharSequence password;
2220

2321
public JiraService withCommitEvents(Boolean commitEvents) {
2422
return withCommitEvents(commitEvents, this);
@@ -29,15 +27,15 @@ public JiraService withMergeRequestsEvents(Boolean mergeRequestsEvents) {
2927
}
3028

3129
@JsonIgnore
32-
public SecretString getPassword() {
30+
public CharSequence getPassword() {
3331
return password;
3432
}
3533

36-
public void setPassword(SecretString password) {
34+
public void setPassword(CharSequence password) {
3735
this.password = password;
3836
}
3937

40-
public JiraService withUrl(SecretString password) {
38+
public JiraService withPassword(CharSequence password) {
4139
setPassword(password);
4240
return (this);
4341
}

src/main/java/org/gitlab4j/api/services/NotificationService.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void setPushEvents(Boolean pushEvents) {
8484
this.pushEvents = pushEvents;
8585
}
8686

87-
public <T> T withPushEvents(Boolean pushEvents, T derivedInstance) {
87+
protected <T> T withPushEvents(Boolean pushEvents, T derivedInstance) {
8888
this.pushEvents = pushEvents;
8989
return (derivedInstance);
9090
}
@@ -97,7 +97,7 @@ public void setIssuesEvents(Boolean issuesEvents) {
9797
this.issuesEvents = issuesEvents;
9898
}
9999

100-
public <T> T withIssuesEvents(Boolean issuesEvents, T derivedInstance) {
100+
protected <T> T withIssuesEvents(Boolean issuesEvents, T derivedInstance) {
101101
this.issuesEvents = issuesEvents;
102102
return (derivedInstance);
103103
}
@@ -110,7 +110,7 @@ public void setConfidentialIssuesEvents(Boolean confidentialIssuesEvents) {
110110
this.confidentialIssuesEvents = confidentialIssuesEvents;
111111
}
112112

113-
public <T> T withConfidentialIssuesEvents(Boolean confidentialIssuesEvents, T derivedInstance) {
113+
protected <T> T withConfidentialIssuesEvents(Boolean confidentialIssuesEvents, T derivedInstance) {
114114
this.confidentialIssuesEvents = confidentialIssuesEvents;
115115
return (derivedInstance);
116116
}
@@ -124,7 +124,7 @@ public void setCommitEvents(Boolean commitEvents) {
124124
this.commitEvents = commitEvents;
125125
}
126126

127-
public <T> T withCommitEvents(Boolean commitEvents, T derivedInstance) {
127+
protected <T> T withCommitEvents(Boolean commitEvents, T derivedInstance) {
128128
setCommitEvents(commitEvents);
129129
return (derivedInstance);
130130
}
@@ -137,7 +137,7 @@ public void setMergeRequestsEvents(Boolean mergeRequestsEvents) {
137137
this.mergeRequestsEvents = mergeRequestsEvents;
138138
}
139139

140-
public <T> T withMergeRequestsEvents(Boolean mergeRequestsEvents, T derivedInstance) {
140+
protected <T> T withMergeRequestsEvents(Boolean mergeRequestsEvents, T derivedInstance) {
141141
this.mergeRequestsEvents = mergeRequestsEvents;
142142
return (derivedInstance);
143143
}
@@ -150,7 +150,7 @@ public void setTagPushEvents(Boolean tagPushEvents) {
150150
this.tagPushEvents = tagPushEvents;
151151
}
152152

153-
public <T> T withTagPushEvents(Boolean tagPushEvents, T derivedInstance) {
153+
protected <T> T withTagPushEvents(Boolean tagPushEvents, T derivedInstance) {
154154
this.tagPushEvents = tagPushEvents;
155155
return (derivedInstance);
156156
}
@@ -163,7 +163,7 @@ public void setNoteEvents(Boolean noteEvents) {
163163
this.noteEvents = noteEvents;
164164
}
165165

166-
public <T> T withNoteEvents(Boolean noteEvents, T derivedInstance) {
166+
protected <T> T withNoteEvents(Boolean noteEvents, T derivedInstance) {
167167
this.noteEvents = noteEvents;
168168
return (derivedInstance);
169169
}
@@ -176,7 +176,7 @@ public void setConfidentialNoteEvents(Boolean confidentialNoteEvents) {
176176
this.confidentialNoteEvents = confidentialNoteEvents;
177177
}
178178

179-
public <T> T withConfidentialNoteEvents(Boolean confidentialNoteEvents, T derivedInstance) {
179+
protected <T> T withConfidentialNoteEvents(Boolean confidentialNoteEvents, T derivedInstance) {
180180
this.confidentialNoteEvents = confidentialNoteEvents;
181181
return (derivedInstance);
182182
}
@@ -189,7 +189,7 @@ public void setPipelineEvents(Boolean pipelineEvents) {
189189
this.pipelineEvents = pipelineEvents;
190190
}
191191

192-
public <T> T withPipelineEvents(Boolean pipelineEvents, T derivedInstance) {
192+
protected <T> T withPipelineEvents(Boolean pipelineEvents, T derivedInstance) {
193193
this.pipelineEvents = pipelineEvents;
194194
return (derivedInstance);
195195
}
@@ -202,7 +202,7 @@ public void setWikiPageEvents(Boolean wikiPageEvents) {
202202
this.wikiPageEvents = wikiPageEvents;
203203
}
204204

205-
public <T> T withWikiPageEvents(Boolean wikiPageEvents, T derivedInstance) {
205+
protected <T> T withWikiPageEvents(Boolean wikiPageEvents, T derivedInstance) {
206206
this.wikiPageEvents = wikiPageEvents;
207207
return (derivedInstance);
208208
}
@@ -215,7 +215,7 @@ public void setJobEvents(Boolean jobEvents) {
215215
this.jobEvents = jobEvents;
216216
}
217217

218-
public <T> T withJobEvents(Boolean jobEvents, T derivedInstance) {
218+
protected <T> T withJobEvents(Boolean jobEvents, T derivedInstance) {
219219
this.jobEvents = jobEvents;
220220
return (derivedInstance);
221221
}

src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
import org.gitlab4j.api.models.ProjectHook;
5858
import org.gitlab4j.api.models.ProjectUser;
5959
import org.gitlab4j.api.models.ProtectedBranch;
60-
import org.gitlab4j.api.models.PushRule;
60+
import org.gitlab4j.api.models.PushRules;
6161
import org.gitlab4j.api.models.Runner;
6262
import org.gitlab4j.api.models.RunnerDetail;
6363
import org.gitlab4j.api.models.Session;
@@ -67,6 +67,7 @@
6767
import org.gitlab4j.api.models.Tag;
6868
import org.gitlab4j.api.models.TreeItem;
6969
import org.gitlab4j.api.models.User;
70+
import org.gitlab4j.api.services.JiraService;
7071
import org.gitlab4j.api.services.SlackService;
7172
import org.gitlab4j.api.systemhooks.ProjectSystemHookEvent;
7273
import org.gitlab4j.api.systemhooks.PushSystemHookEvent;
@@ -310,7 +311,7 @@ public void testProtectedBranch() {
310311
public void testPushRule() {
311312

312313
try {
313-
PushRule pushRule = makeFakeApiCall(PushRule.class, "push-rule");
314+
PushRules pushRule = makeFakeApiCall(PushRules.class, "push-rule");
314315
assertTrue(compareJson(pushRule, "push-rule"));
315316
} catch (Exception e) {
316317
e.printStackTrace();
@@ -343,6 +344,17 @@ public void testAllRunners() {
343344
}
344345
}
345346

347+
@Test
348+
public void testJiraService() {
349+
350+
try {
351+
JiraService jira = makeFakeApiCall(JiraService.class, "jira");
352+
assertTrue(compareJson(jira, "jira"));
353+
} catch (Exception e) {
354+
e.printStackTrace();
355+
}
356+
}
357+
346358
@Test
347359
public void testKey() {
348360

0 commit comments

Comments
 (0)