use of org.gitlab4j.api.models.ProtectedTag in project legend-sdlc by finos.
the class GitLabProjectApi method checkUserReleasePermission.
private boolean checkUserReleasePermission(GitLabProjectId projectId, ProjectAuthorizationAction action, AccessLevel accessLevel) {
try {
List<ProtectedTag> protectedTags = withRetries(() -> getGitLabApi(projectId.getGitLabMode()).getTagsApi().getProtectedTags(projectId.getGitLabId()));
if (protectedTags == null || protectedTags.isEmpty()) {
// By default user can perform a release if the user has developer access or above https://docs.gitlab.com/ee/user/permissions.html#release-permissions-with-protected-tags
return defaultReleaseAction(accessLevel);
}
protectedTags = protectedTags.stream().filter(a -> a.getName().startsWith("release") || a.getName().startsWith("version")).collect(Collectors.toList());
for (ProtectedTag tag : protectedTags) {
if (tag.getCreateAccessLevels().isEmpty()) {
return defaultReleaseAction(accessLevel);
}
// with th release protected tag the user must have the min access_level
List<ProtectedTag.CreateAccessLevel> matchedTags = tag.getCreateAccessLevels().stream().filter(a -> a.getAccess_level().value >= accessLevel.value).collect(Collectors.toList());
// if the machedTags are empty or null user access does not match any of the protected tags
if (matchedTags.isEmpty()) {
return defaultReleaseAction(accessLevel);
}
// User does not meet all criteria not authorized for the action
if (matchedTags.size() != tag.getCreateAccessLevels().size()) {
return false;
}
}
} catch (Exception e) {
throw buildException(e, () -> "Failed to get protected tags for " + projectId.getGitLabId());
}
return false;
}
use of org.gitlab4j.api.models.ProtectedTag in project choerodon-starters by open-hand.
the class TagsApi method protectTag.
/**
* Protects a single repository tag or several project repository tags using a wildcard protected tag.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/protected_tags</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param name the name of the tag or wildcard
* @param createAccessLevel the access level allowed to create
* @return a ProtectedTag instance
* @throws GitLabApiException if any exception occurs
*/
public ProtectedTag protectTag(Object projectIdOrPath, String name, AccessLevel createAccessLevel) throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("name", name, true).withParam("create_access_level", createAccessLevel);
Response response = post(Response.Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "protected_tags");
return (response.readEntity(ProtectedTag.class));
}
Aggregations