Search in sources :

Example 26 with Project

use of org.gitlab4j.api.models.Project in project OpenUnison by TremoloSecurity.

the class ForkProject method doTask.

@Override
public boolean doTask(User user, Map<String, Object> request) throws ProvisioningException {
    int approvalID = 0;
    if (request.containsKey("APPROVAL_ID")) {
        approvalID = (Integer) request.get("APPROVAL_ID");
    }
    Workflow workflow = (Workflow) request.get("WORKFLOW");
    GitlabUserProvider gitlab = (GitlabUserProvider) GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(this.targetName).getProvider();
    GitLabApi api = gitlab.getApi();
    String localSourceProjectNamespace = task.renderTemplate(this.sourceProjectNamespace, request);
    String localSourceProjectName = task.renderTemplate(this.sourceProjectName, request);
    String localDestinationNamespace = task.renderTemplate(this.destintionNamespace, request);
    try {
        Project existingProject = api.getProjectApi().getProject(localSourceProjectNamespace, localSourceProjectName);
        Project newProject = api.getProjectApi().forkProject(existingProject, localDestinationNamespace);
        GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().logAction(gitlab.getName(), false, ActionType.Add, approvalID, workflow, "gitlab-fork-" + existingProject.getNameWithNamespace() + "-fork", localDestinationNamespace);
        String gitUrl = newProject.getSshUrlToRepo();
        String prefix = gitUrl.substring(0, gitUrl.indexOf("@") + 1);
        String suffix = gitUrl.substring(gitUrl.indexOf(":"));
        String newGitUrl = new StringBuilder().append(prefix).append(this.gitSshHost).append(suffix).toString();
        request.put("gitSshInternalURL", newGitUrl);
        request.put("gitSshUrl", newProject.getSshUrlToRepo());
    } catch (GitLabApiException e) {
        throw new ProvisioningException("Error looking up project " + localSourceProjectNamespace + "/" + localSourceProjectName, e);
    }
    return true;
}
Also used : GitlabUserProvider(com.tremolosecurity.unison.gitlab.provisioning.targets.GitlabUserProvider) Project(org.gitlab4j.api.models.Project) GitLabApi(org.gitlab4j.api.GitLabApi) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) Workflow(com.tremolosecurity.provisioning.core.Workflow) GitLabApiException(org.gitlab4j.api.GitLabApiException)

Example 27 with Project

use of org.gitlab4j.api.models.Project in project nivio by dedica-team.

the class GitLabRepoHandlerTest method setsIconFromAvatar.

@Test
void setsIconFromAvatar() throws GitLabApiException, MalformedURLException, ExecutionException, InterruptedException {
    // given
    Link link = new Link(new URL("https://gitlab.com/bonndan/nivio-private-demo"), "gitlab");
    Project project = new Project();
    String avatarUrl = "https://foo.bar.com/logo.jpg";
    project.setAvatarUrl(avatarUrl);
    when(projectApi.getProject(eq("bonndan/nivio-private-demo"))).thenReturn(project);
    when(mrApi.getMergeRequests(eq("bonndan/nivio-private-demo"))).thenReturn(List.of(mock(MergeRequest.class)));
    // when
    ItemDescription description = (ItemDescription) handler.resolve(link).get();
    assertThat(description.getIcon()).isEqualTo(avatarUrl);
}
Also used : Project(org.gitlab4j.api.models.Project) ItemDescription(de.bonndan.nivio.input.dto.ItemDescription) Link(de.bonndan.nivio.model.Link) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Aggregations

Project (org.gitlab4j.api.models.Project)27 GitLabApiException (org.gitlab4j.api.GitLabApiException)18 IOException (java.io.IOException)12 GitLabApi (org.gitlab4j.api.GitLabApi)8 Group (org.gitlab4j.api.models.Group)6 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)5 Workflow (com.tremolosecurity.provisioning.core.Workflow)5 GitlabUserProvider (com.tremolosecurity.unison.gitlab.provisioning.targets.GitlabUserProvider)5 GitMember (de.catma.repository.git.GitMember)4 ArrayList (java.util.ArrayList)4 EventBus (com.google.common.eventbus.EventBus)3 ItemDescription (de.bonndan.nivio.input.dto.ItemDescription)3 BackgroundService (de.catma.backgroundservice.BackgroundService)3 ForkStatus (de.catma.project.ForkStatus)3 CreateRepositoryResponse (de.catma.repository.git.CreateRepositoryResponse)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3