use of org.gitlab4j.api.models.Project in project catma by forTEXT.
the class GitlabManagerCommon method assignDefaultAccessToRootProject.
private RBACSubject assignDefaultAccessToRootProject(RBACSubject subject, Integer groupId) throws IOException {
try {
Group group = getGitLabApi().getGroupApi().getGroup(groupId);
Project rootProject = getGitLabApi().getProjectApi().getProject(group.getName(), GitProjectManager.getProjectRootRepositoryName(group.getName()));
try {
Member member = getGitLabApi().getProjectApi().getMember(rootProject.getId(), subject.getUserId());
if (member.getAccessLevel().value < RBACRole.ASSISTANT.getAccessLevel()) {
return new GitMember(getGitLabApi().getProjectApi().updateMember(rootProject.getId(), subject.getUserId(), AccessLevel.forValue(RBACRole.ASSISTANT.getAccessLevel())));
} else {
// In both cases we refuse to update the role, and simply do nothing.
return subject;
}
} catch (GitLabApiException e) {
return new GitMember(getGitLabApi().getProjectApi().addMember(rootProject.getId(), subject.getUserId(), AccessLevel.forValue(RBACRole.ASSISTANT.getAccessLevel())));
}
} catch (GitLabApiException e) {
throw new IOException("error assigning default access to root project in group #" + groupId, e);
}
}
use of org.gitlab4j.api.models.Project in project catma by forTEXT.
the class GitlabManagerCommon method unassignFromResource.
@Override
public final void unassignFromResource(RBACSubject subject, String projectId, String resourceId) throws IOException {
try {
Project project = getGitLabApi().getProjectApi().getProject(projectId, resourceId);
if (project == null) {
throw new IOException("Resource unkown " + resourceId);
}
getGitLabApi().getProjectApi().removeMember(project.getId(), subject.getUserId());
} catch (GitLabApiException e) {
throw new IOException("error unassigning from resource #" + resourceId + ", subject " + subject, e);
}
}
use of org.gitlab4j.api.models.Project in project catma by forTEXT.
the class GitLabServerManagerTest method createRepositoryInGroup.
@Test
public void createRepositoryInGroup() throws Exception {
String randomGroupNameAndPath = Randomizer.getGroupName();
String createdGroupPath = this.serverManager.createGroup(randomGroupNameAndPath, randomGroupNameAndPath, null);
this.groupsToDeleteOnTearDown.add(createdGroupPath);
assertNotNull(createdGroupPath);
Group group = this.serverManager.getAdminGitLabApi().getGroupApi().getGroup(createdGroupPath);
assertNotNull(group);
assertEquals(randomGroupNameAndPath, group.getName());
assertEquals(randomGroupNameAndPath, group.getPath());
// to assert that the user is the owner of the new group, get the groups for the user using
// the *user-specific* GitLabApi instance
List<Group> groups = this.serverManager.getUserGitLabApi().getGroupApi().getGroups();
assertEquals(1, groups.size());
assertEquals(group.getId(), groups.get(0).getId());
String randomRepoName = Randomizer.getRepoName();
IRemoteGitServerManager.CreateRepositoryResponse createRepositoryResponse = this.serverManager.createRepository(randomRepoName, null, createdGroupPath);
// we don't add the repositoryId to this.repositoriesToDeleteOnTearDown as deletion of the group will take care
// of that for us
assertNotNull(createRepositoryResponse);
assert createRepositoryResponse.repositoryId > 0;
Project project = this.serverManager.getAdminGitLabApi().getProjectApi().getProject(createRepositoryResponse.repositoryId);
assertNotNull(project);
assertEquals(randomRepoName, project.getName());
assertEquals(this.serverManager.getGitLabUser().getId(), project.getCreatorId());
List<Project> repositoriesInGroup = this.serverManager.getAdminGitLabApi().getGroupApi().getProjects(group.getId());
assertEquals(1, repositoriesInGroup.size());
assertEquals(createRepositoryResponse.repositoryId, (int) repositoriesInGroup.get(0).getId());
}
use of org.gitlab4j.api.models.Project in project catma by forTEXT.
the class GitMarkupCollectionHandlerTest method tearDown.
@After
public void tearDown() throws Exception {
if (this.directoriesToDeleteOnTearDown.size() > 0) {
for (File dir : this.directoriesToDeleteOnTearDown) {
FileUtils.deleteDirectory(dir);
}
this.directoriesToDeleteOnTearDown.clear();
}
if (this.markupCollectionReposToDeleteOnTearDown.size() > 0) {
for (String markupCollectionId : this.markupCollectionReposToDeleteOnTearDown) {
List<Project> projects = this.gitLabServerManager.getAdminGitLabApi().getProjectApi().getProjects(markupCollectionId);
// this getProjects overload does a search
for (Project project : projects) {
this.gitLabServerManager.deleteRepository(project.getId());
}
await().until(() -> this.gitLabServerManager.getAdminGitLabApi().getProjectApi().getProjects().isEmpty());
}
this.markupCollectionReposToDeleteOnTearDown.clear();
}
if (this.projectsToDeleteOnTearDown.size() > 0) {
GitProjectManager gitProjectHandler = new GitProjectManager(RepositoryPropertyKey.GitBasedRepositoryBasePath.getValue(), UserIdentification.userToMap(this.catmaUser.getIdentifier()));
for (String projectId : this.projectsToDeleteOnTearDown) {
gitProjectHandler.delete(projectId);
}
this.projectsToDeleteOnTearDown.clear();
}
// delete the GitLab user that the GitLabServerManager constructor in setUp would have
// created - see GitLabServerManagerTest tearDown() for more info
User user = this.gitLabServerManager.getGitLabUser();
this.gitLabServerManager.getAdminGitLabApi().getUserApi().deleteUser(user.getId());
GitLabServerManagerTest.awaitUserDeleted(this.gitLabServerManager.getAdminGitLabApi().getUserApi(), user.getId());
}
use of org.gitlab4j.api.models.Project in project nivio by dedica-team.
the class GitLabRepoHandler method resolve.
/**
* Loads the open issues from the repo.
*/
@Override
public CompletableFuture<ComponentDescription> resolve(Link link) {
if (api == null) {
return CompletableFuture.failedFuture(new RuntimeException("The GitLab API is not configured properly."));
}
String repoName = getRepoName(link);
ItemDescription itemDescription = new ItemDescription();
try {
Project project = api.getProjectApi().getProject(repoName);
String description = project.getDescription();
itemDescription.setLabel(RepositoryLinkHandler.DESCRIPTION, description);
itemDescription.setDescription(description);
itemDescription.setLabel(RepositoryLinkHandler.OPEN_ISSUES, project.getOpenIssuesCount());
String avatarUrl = project.getAvatarUrl();
if (!StringUtils.isEmpty(avatarUrl)) {
itemDescription.setLabel(RepositoryLinkHandler.ICON, avatarUrl);
itemDescription.setIcon(avatarUrl);
}
int size = api.getMergeRequestApi().getMergeRequests(repoName).size();
itemDescription.setLabel(RepositoryLinkHandler.OPEN_PRS, size);
// TODO link collaborators
} catch (Exception e) {
LOGGER.warn("Failed to grab GitLab data from repo:" + e.getMessage(), e);
return CompletableFuture.failedFuture(e);
}
return CompletableFuture.completedFuture(itemDescription);
}
Aggregations