2
2
3
3
import java .util .List ;
4
4
import java .util .Optional ;
5
+ import java .util .stream .Stream ;
5
6
6
7
import javax .ws .rs .core .Form ;
7
8
import javax .ws .rs .core .GenericType ;
@@ -20,22 +21,21 @@ public DeployKeysApi(GitLabApi gitLabApi) {
20
21
21
22
/**
22
23
* Get a list of all deploy keys across all projects of the GitLab instance. This method requires admin access.
23
- * Only returns the first page.
24
24
*
25
- * GET /deploy_keys
25
+ * <pre><code>GitLab Endpoint: GET /deploy_keys</code></pre>
26
26
*
27
27
* @return a list of DeployKey
28
28
* @throws GitLabApiException if any exception occurs
29
29
*/
30
30
public List <DeployKey > getDeployKeys () throws GitLabApiException {
31
- return (getDeployKeys (1 , getDefaultPerPage ()));
31
+ return (getDeployKeys (getDefaultPerPage ()). all ( ));
32
32
}
33
33
34
34
/**
35
35
* Get a list of all deploy keys across all projects of the GitLab instance using the specified page and per page settings.
36
36
* This method requires admin access.
37
37
*
38
- * GET /deploy_keys
38
+ * <pre><code>GitLab Endpoint: GET /deploy_keys</code></pre>
39
39
*
40
40
* @param page the page to get
41
41
* @param perPage the number of deploy keys per page
@@ -50,7 +50,7 @@ public List<DeployKey> getDeployKeys(int page, int perPage) throws GitLabApiExce
50
50
/**
51
51
* Get a Pager of all deploy keys across all projects of the GitLab instance. This method requires admin access.
52
52
*
53
- * GET /deploy_keys
53
+ * <pre><code>GitLab Endpoint: GET /deploy_keys</code></pre>
54
54
*
55
55
* @param itemsPerPage the number of DeployKey instances that will be fetched per page
56
56
* @return a Pager of DeployKey
@@ -59,98 +59,111 @@ public List<DeployKey> getDeployKeys(int page, int perPage) throws GitLabApiExce
59
59
public Pager <DeployKey > getDeployKeys (int itemsPerPage ) throws GitLabApiException {
60
60
return (new Pager <DeployKey >(this , DeployKey .class , itemsPerPage , null , "deploy_keys" ));
61
61
}
62
-
62
+
63
+ /**
64
+ * Get a Stream of all deploy keys across all projects of the GitLab instance. This method requires admin access.
65
+ *
66
+ * <pre><code>GitLab Endpoint: GET /deploy_keys</code></pre>
67
+ *
68
+ * @return a list of DeployKey
69
+ * @throws GitLabApiException if any exception occurs
70
+ */
71
+ public Stream <DeployKey > getDeployKeysStream () throws GitLabApiException {
72
+ return (getDeployKeys (getDefaultPerPage ()).stream ());
73
+ }
74
+
63
75
/**
64
76
* Get a list of the deploy keys for the specified project. This method requires admin access.
65
- * Only returns the first page.
66
77
*
67
- * GET /projects/:id/deploy_keys
78
+ * <pre><code>GitLab Endpoint: GET /projects/:id/deploy_keys</code></pre>
68
79
*
69
- * @param projectId the ID of the project
80
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
70
81
* @return a list of DeployKey
71
82
* @throws GitLabApiException if any exception occurs
72
83
*/
73
- public List <DeployKey > getProjectDeployKeys (Integer projectId ) throws GitLabApiException {
74
- return (getProjectDeployKeys (projectId , 1 , getDefaultPerPage ()));
84
+ public List <DeployKey > getProjectDeployKeys (Object projectIdOrPath ) throws GitLabApiException {
85
+ return (getProjectDeployKeys (projectIdOrPath , getDefaultPerPage ()). all ( ));
75
86
}
76
87
77
88
/**
78
89
* Get a list of the deploy keys for the specified project using the specified page and per page settings.
79
90
* This method requires admin access.
80
91
*
81
- * GET /projects/:id/deploy_keys
92
+ * <pre><code>GitLab Endpoint: GET /projects/:id/deploy_keys</code></pre>
82
93
*
83
- * @param projectId the ID of the project
94
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
84
95
* @param page the page to get
85
96
* @param perPage the number of deploy keys per page
86
97
* @return the list of DeployKey in the specified range
87
98
* @throws GitLabApiException if any exception occurs
88
99
*/
89
- public List <DeployKey > getProjectDeployKeys (Integer projectId , int page , int perPage ) throws GitLabApiException {
90
-
91
- if (projectId == null ) {
92
- throw new RuntimeException ("projectId cannot be null" );
93
- }
94
-
95
- Response response = get (Response .Status .OK , getPageQueryParams (page , perPage ), "projects" , projectId , "deploy_keys" );
100
+ public List <DeployKey > getProjectDeployKeys (Object projectIdOrPath , int page , int perPage ) throws GitLabApiException {
101
+ Response response = get (Response .Status .OK , getPageQueryParams (page , perPage ),
102
+ "projects" , getProjectIdOrPath (projectIdOrPath ), "deploy_keys" );
96
103
return (response .readEntity (new GenericType <List <DeployKey >>() {}));
97
104
}
98
105
99
106
/**
100
107
* Get a Pager of the deploy keys for the specified project. This method requires admin access.
101
108
*
102
- * GET /projects/:id/deploy_keys
109
+ * <pre><code>GitLab Endpoint: GET /projects/:id/deploy_keys</code></pre>
103
110
*
104
- * @param projectId the ID of the project
111
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance@param projectId the ID of the project
105
112
* @param itemsPerPage the number of DeployKey instances that will be fetched per page
106
113
* @return a Pager of DeployKey
107
114
* @throws GitLabApiException if any exception occurs
108
115
*/
109
- public Pager <DeployKey > getProjectDeployKeys (Integer projectId , Integer itemsPerPage ) throws GitLabApiException {
110
-
111
- if (projectId == null ) {
112
- throw new RuntimeException ("projectId cannot be null" );
113
- }
116
+ public Pager <DeployKey > getProjectDeployKeys (Object projectIdOrPath , int itemsPerPage ) throws GitLabApiException {
117
+ return (new Pager <DeployKey >(this , DeployKey .class , itemsPerPage , null ,
118
+ "projects" , getProjectIdOrPath (projectIdOrPath ), "deploy_keys" ));
119
+ }
114
120
115
- return (new Pager <DeployKey >(this , DeployKey .class , itemsPerPage , null , "projects" , projectId , "deploy_keys" ));
121
+ /**
122
+ * Get a list of the deploy keys for the specified project. This method requires admin access.
123
+ *
124
+ * <pre><code>GitLab Endpoint: GET /projects/:id/deploy_keys</code></pre>
125
+ *
126
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
127
+ * @return a list of DeployKey
128
+ * @throws GitLabApiException if any exception occurs
129
+ */
130
+ public Stream <DeployKey > getProjectDeployKeysStream (Object projectIdOrPath ) throws GitLabApiException {
131
+ return (getProjectDeployKeys (projectIdOrPath , getDefaultPerPage ()).stream ());
116
132
}
117
133
118
134
/**
119
135
* Get a single deploy key for the specified project.
120
136
*
121
- * GET /projects/:id/deploy_keys/:key_id
137
+ * <pre><code>GitLab Endpoint: GET /projects/:id/deploy_keys/:key_id</code></pre>
122
138
*
123
- * @param projectId the ID of the project
139
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
124
140
* @param keyId the ID of the deploy key to delete
125
141
* @return the DeployKey instance for the specified project ID and key ID
126
142
* @throws GitLabApiException if any exception occurs
127
143
*/
128
- public DeployKey getDeployKey (Integer projectId , Integer keyId ) throws GitLabApiException {
129
-
130
- if (projectId == null ) {
131
- throw new RuntimeException ("projectId cannot be null" );
132
- }
144
+ public DeployKey getDeployKey (Object projectIdOrPath , Integer keyId ) throws GitLabApiException {
133
145
134
146
if (keyId == null ) {
135
147
throw new RuntimeException ("keyId cannot be null" );
136
148
}
137
149
138
- Response response = get (Response .Status .OK , null , "projects" , projectId , "deploy_keys" , keyId );
150
+ Response response = get (Response .Status .OK , null ,
151
+ "projects" , getProjectIdOrPath (projectIdOrPath ), "deploy_keys" , keyId );
139
152
return (response .readEntity (DeployKey .class ));
140
153
}
141
154
142
155
/**
143
156
* Get a single deploy key for the specified project as an Optional instance.
144
157
*
145
- * GET /projects/:id/deploy_keys/:key_id
158
+ * <pre><code>GitLab Endpoint: GET /projects/:id/deploy_keys/:key_id</code></pre>
146
159
*
147
- * @param projectId the ID of the project
160
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
148
161
* @param keyId the ID of the deploy key to delete
149
162
* @return the DeployKey for the specified project ID and key ID as an Optional instance
150
163
*/
151
- public Optional <DeployKey > getOptionalDeployKey (Integer projectId , Integer keyId ) {
164
+ public Optional <DeployKey > getOptionalDeployKey (Object projectIdOrPath , Integer keyId ) {
152
165
try {
153
- return (Optional .ofNullable (getDeployKey (projectId , keyId )));
166
+ return (Optional .ofNullable (getDeployKey (projectIdOrPath , keyId )));
154
167
} catch (GitLabApiException glae ) {
155
168
return (GitLabApi .createOptionalFromException (glae ));
156
169
}
@@ -159,72 +172,62 @@ public Optional<DeployKey> getOptionalDeployKey(Integer projectId, Integer keyId
159
172
/**
160
173
* Creates a new deploy key for a project.
161
174
*
162
- * POST /projects/:id/deploy_keys
175
+ * <pre><code>GitLab Endpoint: POST /projects/:id/deploy_keys</code></pre>
163
176
*
164
- * @param projectId the ID of the project owned by the authenticated user, required
177
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
165
178
* @param title the new deploy key's title, required
166
179
* @param key the new deploy key, required
167
180
* @param canPush can deploy key push to the project's repository, optional
168
181
* @return an DeployKey instance with info on the added deploy key
169
182
* @throws GitLabApiException if any exception occurs
170
183
*/
171
- public DeployKey addDeployKey (Integer projectId , String title , String key , Boolean canPush ) throws GitLabApiException {
172
-
173
- if (projectId == null ) {
174
- throw new RuntimeException ("projectId cannot be null" );
175
- }
184
+ public DeployKey addDeployKey (Object projectIdOrPath , String title , String key , Boolean canPush ) throws GitLabApiException {
176
185
177
186
GitLabApiForm formData = new GitLabApiForm ()
178
187
.withParam ("title" , title , true )
179
188
.withParam ("key" , key , true )
180
189
.withParam ("can_push" , canPush );
181
- Response response = post (Response .Status .CREATED , formData , "projects" , projectId , "deploy_keys" );
190
+ Response response = post (Response .Status .CREATED , formData ,
191
+ "projects" , getProjectIdOrPath (projectIdOrPath ), "deploy_keys" );
182
192
return (response .readEntity (DeployKey .class ));
183
193
}
184
194
185
195
/**
186
196
* Removes a deploy key from the project. If the deploy key is used only for this project,it will be deleted from the system.
187
197
*
188
- * DELETE /projects/:id/deploy_keys/:key_id
198
+ * <pre><code>GitLab Endpoint: DELETE /projects/:id/deploy_keys/:key_id</code></pre>
189
199
*
190
- * @param projectId the ID of the project
200
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
191
201
* @param keyId the ID of the deploy key to delete
192
202
* @throws GitLabApiException if any exception occurs
193
203
*/
194
- public void deleteDeployKey (Integer projectId , Integer keyId ) throws GitLabApiException {
195
-
196
- if (projectId == null ) {
197
- throw new RuntimeException ("projectId cannot be null" );
198
- }
204
+ public void deleteDeployKey (Object projectIdOrPath , Integer keyId ) throws GitLabApiException {
199
205
200
206
if (keyId == null ) {
201
207
throw new RuntimeException ("keyId cannot be null" );
202
208
}
203
209
204
- delete (Response .Status .OK , null , "projects" , projectId , "deploy_keys" , keyId );
210
+ delete (Response .Status .OK , null , "projects" , getProjectIdOrPath ( projectIdOrPath ) , "deploy_keys" , keyId );
205
211
}
206
212
207
213
/**
208
214
* Enables a deploy key for a project so this can be used. Returns the enabled key when successful.
209
215
*
210
- * POST /projects/:id/deploy_keys/:key_id/enable
216
+ * <pre><code>GitLab Endpoint: POST /projects/:id/deploy_keys/:key_id/enable</code></pre>
211
217
*
212
- * @param projectId the ID of the project
218
+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
213
219
* @param keyId the ID of the deploy key to enable
214
220
* @return an DeployKey instance with info on the enabled deploy key
215
221
* @throws GitLabApiException if any exception occurs
216
222
*/
217
- public DeployKey enableDeployKey (Integer projectId , Integer keyId ) throws GitLabApiException {
218
-
219
- if (projectId == null ) {
220
- throw new RuntimeException ("projectId cannot be null" );
221
- }
223
+ public DeployKey enableDeployKey (Object projectIdOrPath , Integer keyId ) throws GitLabApiException {
222
224
223
225
if (keyId == null ) {
224
226
throw new RuntimeException ("keyId cannot be null" );
225
227
}
226
228
227
- Response response = post (Response .Status .CREATED , (Form )null , "projects" , projectId , "deploy_keys" , keyId , "enable" );
229
+ Response response = post (Response .Status .CREATED , (Form )null ,
230
+ "projects" , getProjectIdOrPath (projectIdOrPath ), "deploy_keys" , keyId , "enable" );
228
231
return (response .readEntity (DeployKey .class ));
229
232
}
230
233
}
0 commit comments