@Override public WorkspaceProject resolveProject(final Repository repository) { if (!repository.getDefaultBranch().isPresent()) { throw new IllegalStateException("New repository should always have a branch."); } return resolveProject(repository.getSpace(), repository.getDefaultBranch().get()); }
@Override public void onNewRepositoryAdded(final Repository repository) { addRepositoryItem(repository, repository.getDefaultBranch()); }
public Module get(final OrganizationalUnit organizationalUnit, final Repository repository) { if (organizationalUnit == null || repository == null || !repository.getDefaultBranch().isPresent()) { return null; } final Object obj = content.get(Pair.newPair(organizationalUnit.getName(), repository.getDefaultBranch().get().getPath()).toString()); if (obj != null && obj instanceof Module) { return (Module) obj; } return null; }
@Override protected DefExplorerQuery createRefreshQuery() { return new DefExplorerQuery(activeOrganizationalUnit, activeRepository, activeModule, activeRepository.getDefaultBranch().get().getName()); }
public void onNewRepository(final @Observes NewRepositoryEvent event) { final Repository newRepository = event.getNewRepository(); aliasBranch.put(newRepository.getAlias(), newRepository.getDefaultBranch()); for (final GuvnorStructureContextChangeHandler handler : handlers.values()) { handler.onNewRepositoryAdded(newRepository); } }
public void onArchiveActiveRepository() { final Optional<Branch> defaultBranch = context.getActiveWorkspaceProject() .map(proj -> proj.getRepository()) .orElseThrow(() -> new IllegalStateException("Cannot check for default branch without an active project.")) .getDefaultBranch(); if (defaultBranch.isPresent()) { view.archive(defaultBranch.get().getPath()); } }
private void updateBranch(final Repository repository) { final String branch = aliasBranch.get(repository.getAlias()); if (branch == null || hasBranchBeenRemoved(repository, branch)) { aliasBranch.put(repository.getAlias(), repository.getDefaultBranch()); } }
private String getNiogitRepoPath(Repository repository) { final Branch branch = repository.getDefaultBranch().get(); final Path path = pathUtil.convert(branch.getPath()); return pathUtil.getNiogitRepoPath(path); }
private Branch resolveBranch(final org.uberfire.java.nio.file.Path repositoryRoot, final Repository repository) { final Branch defaultBranch = repository.getDefaultBranch().get(); if (!Paths.convert(defaultBranch.getPath()).equals(repositoryRoot)) { for (final Branch branch : repository.getBranches()) { if (Paths.convert(branch.getPath()).equals(repositoryRoot)) { return branch; } } } return defaultBranch; }
private Repository mockLegacyRepository() { final Repository legacyRepository = mock(Repository.class); final ArrayList<Branch> branches = new ArrayList<>(); branches.add(legacyMasterBranch); branches.add(legacyDevBranch); doReturn(branches).when(legacyRepository).getBranches(); final ArrayList<OrganizationalUnit> ous = new ArrayList<>(); ous.add(organizationalUnit); doReturn(ous).when(organizationalUnitService).getOrganizationalUnits(legacyRepository); when(legacyRepository.getDefaultBranch()).thenReturn(Optional.of(legacyMasterBranch)); return legacyRepository; }
private void whenProjectExists() { when(repository.getDefaultBranch()).thenReturn("master"); Path path = mock(Path.class); when(path.getFileName()).thenReturn(""); when(path.toURI()).thenReturn("file://project/"); when(repository.getBranchRoot("master")).thenReturn(path); when(projectService.resolveProject(any(Path.class))).thenReturn(mock(MyProject.class)); }
protected void cleanupOrigin(Repository repository) { try { // AF-1715: Cleaning origin to prevent errors while importing the new generated repo. Git git = ((JGitPathImpl) pathUtil.convert(repository.getDefaultBranch().get().getPath())).getFileSystem().getGit(); new RemoveRemote(git,"origin",REMOTE_ORIGIN_REF).execute(); } catch (GitException e) { log.warn("Error cleaning up origin for repository '{}': {}", repository.getAlias(), e); } }
@Test public void testCreateNewAliasIfNecessary() { when(configuredRepositories.getRepositoryByRepositoryAlias(any(), eq("alias"))).thenReturn(repository); doReturn(Optional.of(mock(Branch.class))).when(repository).getDefaultBranch(); doReturn("alias").when(repository).getAlias(); String newAlias = repositoryService.createFreshRepositoryAlias("alias", new Space("alias")); assertEquals("alias-1", newAlias); }
@Test public void testNotCreateNewAliasIfNecessary() { when(configuredRepositories.getRepositoryByRepositoryAlias(any(), eq("other-name"))).thenReturn(repository); doReturn(Optional.of(mock(Branch.class))).when(repository).getDefaultBranch(); doReturn("alias").when(repository).getAlias(); String newAlias = repositoryService.createFreshRepositoryAlias("alias", new Space("alias")); assertEquals("alias", newAlias); }
@Before public void setUp() { when(libraryPlaces.getActiveWorkspace()).thenReturn(project); when(project.getRepository().getDefaultBranch()).thenReturn(Optional.of(branch)); when(branch.getName()).thenReturn("myBranch"); presenter = spy(new DeleteBranchPopUpScreen(view, new CallerMock<>(libraryService), libraryPlaces)); }
@Test public void testReLoadPicksUpRemovedBranch() throws Exception { // This deletes master branch when(repositories.get(0).getBranches()).thenReturn(Arrays.asList("dev")); when(repositories.get(0).getDefaultBranch()).thenReturn("dev"); context.getRepositories(callback); assertEquals("dev", context.getCurrentBranch("my-repo")); assertEquals("master", context.getCurrentBranch("your-repo")); }
@Test public void spaceHasProjectsWithNameSameProject() throws Exception { final boolean hasNoProjects = workspaceProjectService.spaceHasNoProjectsWithName(ou1, "repository1", new WorkspaceProject(ou1, repository1, repository1.getDefaultBranch().get(), null)); assertTrue(hasNoProjects); }
@Test public void spaceHasNoProjectsWithName() throws Exception { final boolean hasNoProjects = workspaceProjectService.spaceHasNoProjectsWithName(ou1, "other-project", new WorkspaceProject(ou1, repository1, repository1.getDefaultBranch().get(), null)); assertTrue(hasNoProjects); }
@Test public void spaceHasProjectsWithName() throws Exception { final boolean hasNoProjects = workspaceProjectService.spaceHasNoProjectsWithName(ou1, "repository1", new WorkspaceProject(ou1, repository2, repository2.getDefaultBranch().get(), null)); assertFalse(hasNoProjects); }
@Test public void testBranches() throws Exception { rootDirectories.add(createPath("default://origin@uf-playground")); rootDirectories.add(createPath("default://master@uf-playground")); rootDirectories.add(createPath("default://branch1@uf-playground")); ConfigGroup configGroup = getConfigGroup(); configGroup.setName("test"); Repository repository = helper.newRepository(configGroup); assertEquals(3, repository.getBranches().size()); assertTrue(repository.getDefaultBranch().get().getPath().toURI().contains("master")); }