Search in sources :

Example 16 with SVcsRoot

use of jetbrains.buildServer.vcs.SVcsRoot in project teamcity-git by JetBrains.

the class SpaceExternalChangeViewerExtensionTest method jetbrainsTeamVcsRoot.

@Test
void jetbrainsTeamVcsRoot() {
    // given
    final VcsRootInstanceImpl vcsRoot = Mockito.mock(VcsRootInstanceImpl.class);
    Mockito.doReturn(Constants.VCS_NAME).when(vcsRoot).getVcsName();
    Mockito.doReturn(selfHosted).when(vcsRoot).getProperty(Constants.FETCH_URL);
    final SProject project = Mockito.mock(SProject.class);
    final SVcsRoot sVcsRoot = Mockito.mock(SVcsRoot.class);
    Mockito.doReturn(sVcsRoot).when(vcsRoot).getParent();
    Mockito.doReturn(project).when(sVcsRoot).getProject();
    final OAuthConnectionDescriptor connection = Mockito.mock(OAuthConnectionDescriptor.class);
    Mockito.doReturn(ImmutableList.of(connection)).when(myOAuthConnectionsManager).getAvailableConnectionsOfType(project, SpaceOAuthProvider.TYPE);
    Mockito.doReturn(ImmutableMap.of(SPACE_SERVER_URL, selfHostedServerUrl, SPACE_CLIENT_ID, "ignore", SPACE_CLIENT_SECRET, "ignore")).when(connection).getParameters();
    // test
    SpaceExternalChangeViewerExtension extension = mySpaceExternalChangeViewerExtension();
    final Map<String, String> availableProperties = extension.getAvailableProperties(vcsRoot);
    assertEquals(availableProperties, ImmutableMap.of(PropertyType.CHANGE_SET_TYPE, "https://jetbrains.team/p/tc/repositories/TeamCity/revision/${changeSetId}", PropertyType.LINK_TEXT, "Open in Space", PropertyType.LINK_ICON_CLASS, "tc-icon_space"));
}
Also used : SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) VcsRootInstanceImpl(jetbrains.buildServer.vcs.impl.VcsRootInstanceImpl) SpaceExternalChangeViewerExtension(jetbrains.buildServer.buildTriggers.vcs.git.SpaceExternalChangeViewerExtension) OAuthConnectionDescriptor(jetbrains.buildServer.serverSide.oauth.OAuthConnectionDescriptor) SProject(jetbrains.buildServer.serverSide.SProject) Test(org.testng.annotations.Test)

Example 17 with SVcsRoot

use of jetbrains.buildServer.vcs.SVcsRoot in project teamcity-git by JetBrains.

the class SpaceExternalChangeViewerExtensionTest method jetbrainsTeamVcsRoot_connectionNotFound.

@Test
void jetbrainsTeamVcsRoot_connectionNotFound() {
    // given
    final VcsRootInstanceImpl vcsRoot = Mockito.mock(VcsRootInstanceImpl.class);
    Mockito.doReturn(Constants.VCS_NAME).when(vcsRoot).getVcsName();
    Mockito.doReturn(selfHosted).when(vcsRoot).getProperty(Constants.FETCH_URL);
    final SProject project = Mockito.mock(SProject.class);
    final SVcsRoot sVcsRoot = Mockito.mock(SVcsRoot.class);
    Mockito.doReturn(sVcsRoot).when(vcsRoot).getParent();
    Mockito.doReturn(project).when(sVcsRoot).getProject();
    // test
    SpaceExternalChangeViewerExtension extension = mySpaceExternalChangeViewerExtension();
    final Map<String, String> availableProperties = extension.getAvailableProperties(vcsRoot);
    assertNull(availableProperties);
}
Also used : SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) VcsRootInstanceImpl(jetbrains.buildServer.vcs.impl.VcsRootInstanceImpl) SpaceExternalChangeViewerExtension(jetbrains.buildServer.buildTriggers.vcs.git.SpaceExternalChangeViewerExtension) SProject(jetbrains.buildServer.serverSide.SProject) Test(org.testng.annotations.Test)

Example 18 with SVcsRoot

use of jetbrains.buildServer.vcs.SVcsRoot in project teamcity-git by JetBrains.

the class SpaceExternalChangeViewerExtensionTest method jetbrainsTeamVcsRoot_twoConnections.

@Test
void jetbrainsTeamVcsRoot_twoConnections() {
    // given
    final VcsRootInstanceImpl vcsRoot = Mockito.mock(VcsRootInstanceImpl.class);
    Mockito.doReturn(Constants.VCS_NAME).when(vcsRoot).getVcsName();
    Mockito.doReturn(selfHosted).when(vcsRoot).getProperty(Constants.FETCH_URL);
    final SProject project = Mockito.mock(SProject.class);
    final SVcsRoot sVcsRoot = Mockito.mock(SVcsRoot.class);
    Mockito.doReturn(sVcsRoot).when(vcsRoot).getParent();
    Mockito.doReturn(project).when(sVcsRoot).getProject();
    final OAuthConnectionDescriptor connection1 = Mockito.mock(OAuthConnectionDescriptor.class);
    final OAuthConnectionDescriptor connection2 = Mockito.mock(OAuthConnectionDescriptor.class);
    Mockito.doReturn(ImmutableList.of(connection1, connection2)).when(myOAuthConnectionsManager).getAvailableConnectionsOfType(project, SpaceOAuthProvider.TYPE);
    Mockito.doReturn(ImmutableMap.of(SPACE_SERVER_URL, hostedOnJetBrainsSideServerUrl, SPACE_CLIENT_ID, "ignore", SPACE_CLIENT_SECRET, "ignore")).when(connection1).getParameters();
    Mockito.doReturn(ImmutableMap.of(SPACE_SERVER_URL, selfHostedServerUrl, SPACE_CLIENT_ID, "ignore", SPACE_CLIENT_SECRET, "ignore")).when(connection2).getParameters();
    // test
    SpaceExternalChangeViewerExtension extension = mySpaceExternalChangeViewerExtension();
    final Map<String, String> availableProperties = extension.getAvailableProperties(vcsRoot);
    assertEquals(availableProperties, ImmutableMap.of(PropertyType.CHANGE_SET_TYPE, "https://jetbrains.team/p/tc/repositories/TeamCity/revision/${changeSetId}", PropertyType.LINK_TEXT, "Open in Space", PropertyType.LINK_ICON_CLASS, "tc-icon_space"));
}
Also used : SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) VcsRootInstanceImpl(jetbrains.buildServer.vcs.impl.VcsRootInstanceImpl) SpaceExternalChangeViewerExtension(jetbrains.buildServer.buildTriggers.vcs.git.SpaceExternalChangeViewerExtension) OAuthConnectionDescriptor(jetbrains.buildServer.serverSide.oauth.OAuthConnectionDescriptor) SProject(jetbrains.buildServer.serverSide.SProject) Test(org.testng.annotations.Test)

Example 19 with SVcsRoot

use of jetbrains.buildServer.vcs.SVcsRoot in project teamcity-git by JetBrains.

the class GitHubPasswordAuthHealthPage method isAvailable.

@Override
public boolean isAvailable(@NotNull HttpServletRequest request) {
    if (!super.isAvailable(request))
        return false;
    final SVcsRoot vcsRoot = getRootFromRequest(request);
    if (vcsRoot == null)
        return false;
    final SProject project = vcsRoot.getProject();
    return SessionUser.getUser(request).isPermissionGrantedForProject(project.getProjectId(), Permission.EDIT_PROJECT) && // check vcs root still exists
    project.getOwnVcsRoots().contains(vcsRoot);
}
Also used : SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) SProject(jetbrains.buildServer.serverSide.SProject)

Example 20 with SVcsRoot

use of jetbrains.buildServer.vcs.SVcsRoot in project teamcity-git by JetBrains.

the class GitHubPasswordAuthHealthReport method report.

@Override
public void report(@NotNull HealthStatusScope scope, @NotNull HealthStatusItemConsumer resultConsumer) {
    if (!isEnabled())
        return;
    for (SVcsRoot root : scope.getVcsRoots()) {
        if (!isGitRoot(root) || !myRegistry.containsVcsRoot(root.getId()))
            continue;
        final Map<String, Object> additionalData = new HashMap<String, Object>();
        additionalData.put(VCS_ROOT_KEY, root);
        resultConsumer.consumeForVcsRoot(root, new HealthStatusItem(REPORT_TYPE + root.getId(), CATEGORY, SEVERITY, additionalData));
    }
}
Also used : SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) HashMap(java.util.HashMap)

Aggregations

SVcsRoot (jetbrains.buildServer.vcs.SVcsRoot)38 ApiOperation (io.swagger.annotations.ApiOperation)13 BuildTypeOrTemplate (jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate)12 Test (org.testng.annotations.Test)11 NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)10 VcsRootInstance (jetbrains.buildServer.vcs.VcsRootInstance)8 NotNull (org.jetbrains.annotations.NotNull)7 Nullable (org.jetbrains.annotations.Nullable)7 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)5 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)5 SProject (jetbrains.buildServer.serverSide.SProject)4 MockVcsSupport (jetbrains.buildServer.serverSide.impl.MockVcsSupport)4 CheckoutRules (jetbrains.buildServer.vcs.CheckoutRules)4 Logger (com.intellij.openapi.diagnostic.Logger)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 SpaceExternalChangeViewerExtension (jetbrains.buildServer.buildTriggers.vcs.git.SpaceExternalChangeViewerExtension)3 PagerData (jetbrains.buildServer.server.rest.model.PagerData)3 LocatorDimension (jetbrains.buildServer.server.rest.swagger.annotations.LocatorDimension)3 LocatorResource (jetbrains.buildServer.server.rest.swagger.annotations.LocatorResource)3