|
11 | 11 | import javax.ws.rs.core.Response; |
12 | 12 |
|
13 | 13 | import org.gitlab4j.api.GitLabApi.ApiVersion; |
| 14 | +import org.gitlab4j.api.models.AccessLevel; |
| 15 | +import org.gitlab4j.api.models.ProtectedTag; |
14 | 16 | import org.gitlab4j.api.models.Release; |
15 | 17 | import org.gitlab4j.api.models.Tag; |
16 | 18 | import org.gitlab4j.api.utils.FileUtils; |
17 | 19 |
|
18 | 20 | /** |
19 | | - * This class provides an entry point to all the GitLab Tags API calls. |
20 | | - * |
21 | | - * See https://docs.gitlab.com/ce/api/tags.html for more information on the GitLab Tags API. |
| 21 | + * This class provides an entry point to all the GitLab Tags and Protected Tags API calls. |
| 22 | + * @see <a href="https://docs.gitlab.com/ce/api/tags.html">Tags API at GitLab</a> |
| 23 | + * @see <a href="https://docs.gitlab.com/ce/api/protected_tags.html">Protected Tags API at GitLab</a> |
22 | 24 | */ |
23 | 25 | public class TagsApi extends AbstractApi { |
24 | 26 |
|
@@ -63,7 +65,7 @@ public List<Tag> getTags(Object projectIdOrPath, int page, int perPage) throws G |
63 | 65 | * |
64 | 66 | * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path |
65 | 67 | * @param itemsPerPage the number of Project instances that will be fetched per page |
66 | | - * @return the list of tags for the specified project ID |
| 68 | + * @return the Pager of tags for the specified project ID |
67 | 69 | * @throws GitLabApiException if any exception occurs |
68 | 70 | */ |
69 | 71 | public Pager<Tag> getTags(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException { |
@@ -237,4 +239,123 @@ public Release updateRelease(Object projectIdOrPath, String tagName, String rele |
237 | 239 | return (response.readEntity(Release.class)); |
238 | 240 | } |
239 | 241 |
|
| 242 | + /** |
| 243 | + * Gets a list of protected tags from a project. |
| 244 | + * |
| 245 | + * <pre><code>GitLab Endpoint: GET /projects/:id/protected_tags</code></pre> |
| 246 | + * |
| 247 | + * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path |
| 248 | + * @return a List of protected tags for the specified project ID |
| 249 | + * @throws GitLabApiException if any exception occurs |
| 250 | + */ |
| 251 | + public List<ProtectedTag> getProtectedTags(Object projectIdOrPath) throws GitLabApiException { |
| 252 | + return (getProtectedTags(projectIdOrPath, getDefaultPerPage()).all()); |
| 253 | + } |
| 254 | + |
| 255 | + /** |
| 256 | + * Gets a list of protected tags from a project and in the specified page range. |
| 257 | + * |
| 258 | + * <pre><code>GitLab Endpoint: GET /projects/:id/protected_tags</code></pre> |
| 259 | + * |
| 260 | + * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path |
| 261 | + * @param page the page to get |
| 262 | + * @param perPage the number of Tag instances per page |
| 263 | + * @return a List of tags for the specified project ID and page range |
| 264 | + * @throws GitLabApiException if any exception occurs |
| 265 | + */ |
| 266 | + public List<ProtectedTag> getProtectedTags(Object projectIdOrPath, int page, int perPage) throws GitLabApiException { |
| 267 | + Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), |
| 268 | + "projects", getProjectIdOrPath(projectIdOrPath), "protected_tags"); |
| 269 | + return (response.readEntity(new GenericType<List<ProtectedTag>>() { })); |
| 270 | + } |
| 271 | + |
| 272 | + /** |
| 273 | + * Get a Pager of protected tags for a project. |
| 274 | + * |
| 275 | + * <pre><code>GitLab Endpoint: GET /projects/:id/protected_tags</code></pre> |
| 276 | + * |
| 277 | + * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path |
| 278 | + * @param itemsPerPage the number of Project instances that will be fetched per page |
| 279 | + * @return the Pager of protected tags for the specified project ID |
| 280 | + * @throws GitLabApiException if any exception occurs |
| 281 | + */ |
| 282 | + public Pager<ProtectedTag> getProtectedTags(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException { |
| 283 | + return (new Pager<ProtectedTag>(this, ProtectedTag.class, itemsPerPage, null, "projects", getProjectIdOrPath(projectIdOrPath), "protected_tags")); |
| 284 | + } |
| 285 | + |
| 286 | + /** |
| 287 | + * Get a Stream of protected tags for a project. |
| 288 | + * |
| 289 | + * <pre><code>GitLab Endpoint: GET /projects/:id/protected_tags/:name</code></pre> |
| 290 | + * |
| 291 | + * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path |
| 292 | + * @return a Stream of protected tags for the specified project ID |
| 293 | + * @throws GitLabApiException if any exception occurs |
| 294 | + */ |
| 295 | + public Stream<ProtectedTag> getProtectedTagsStream(Object projectIdOrPath) throws GitLabApiException { |
| 296 | + return (getProtectedTags(projectIdOrPath, getDefaultPerPage()).stream()); |
| 297 | + } |
| 298 | + |
| 299 | + /** |
| 300 | + * Gets a single protected tag or wildcard protected tag |
| 301 | + * |
| 302 | + * <pre><code>GitLab Endpoint: GET /projects/:id/protected_tags/:name</code></pre> |
| 303 | + * |
| 304 | + * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path |
| 305 | + * @param name the name of the tag or wildcard |
| 306 | + * @return a ProtectedTag instance with info on the specified protected tag |
| 307 | + * @throws GitLabApiException if any exception occurs |
| 308 | + */ |
| 309 | + public ProtectedTag getProtectedTag(Object projectIdOrPath, String name) throws GitLabApiException { |
| 310 | + Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "protected_tags", urlEncode(name)); |
| 311 | + return (response.readEntity(ProtectedTag.class)); |
| 312 | + } |
| 313 | + |
| 314 | + /** |
| 315 | + * Get an Optional instance holding a protected tag or wildcard protected tag. |
| 316 | + * |
| 317 | + * <pre><code>GitLab Endpoint: GET /projects/:id/protected_tags/:name</code></pre> |
| 318 | + * |
| 319 | + * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path |
| 320 | + * @param name the name of the tag or wildcard |
| 321 | + * @return an Optional instance with the specified protected tag as the value |
| 322 | + * @throws GitLabApiException if any exception occurs |
| 323 | + */ |
| 324 | + public Optional<ProtectedTag> getOptionalProtectedTag(Object projectIdOrPath, String name) throws GitLabApiException { |
| 325 | + try { |
| 326 | + return (Optional.ofNullable(getProtectedTag(projectIdOrPath, name))); |
| 327 | + } catch (GitLabApiException glae) { |
| 328 | + return (GitLabApi.createOptionalFromException(glae)); |
| 329 | + } |
| 330 | + } |
| 331 | + |
| 332 | + /** |
| 333 | + * Protects a single repository tag or several project repository tags using a wildcard protected tag. |
| 334 | + * |
| 335 | + * <pre><code>GitLab Endpoint: GET /projects/:id/protected_tags</code></pre> |
| 336 | + * |
| 337 | + * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path |
| 338 | + * @param name the name of the tag or wildcard |
| 339 | + * @param createAccessLevel the access level allowed to create |
| 340 | + * @return a ProtectedTag instance |
| 341 | + * @throws GitLabApiException if any exception occurs |
| 342 | + */ |
| 343 | + public ProtectedTag protectTag(Object projectIdOrPath, String name, AccessLevel createAccessLevel) throws GitLabApiException { |
| 344 | + Form formData = new GitLabApiForm().withParam("name", name, true).withParam("create_access_Level", createAccessLevel); |
| 345 | + Response response = post(Response.Status.OK, formData, "projects", getProjectIdOrPath(projectIdOrPath), "protected_tags"); |
| 346 | + return (response.readEntity(ProtectedTag.class)); |
| 347 | + } |
| 348 | + |
| 349 | + /** |
| 350 | + * Unprotects the given protected tag or wildcard protected tag. |
| 351 | + * |
| 352 | + * <pre><code>GitLab Endpoint: GET /projects/:id/protected_tags/:name</code></pre> |
| 353 | + * |
| 354 | + * @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path |
| 355 | + * @param name the name of the tag or wildcard |
| 356 | + * @throws GitLabApiException if any exception occurs |
| 357 | + */ |
| 358 | + public void unprotectTag(Object projectIdOrPath, String name) throws GitLabApiException { |
| 359 | + delete(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "protected_tags", urlEncode(name)); |
| 360 | + } |
240 | 361 | } |
0 commit comments