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;
}
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);
}
Aggregations