Search in sources :

Example 11 with SVcsRoot

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

the class BuildTypeRequest method getVcsRootEntryCheckoutRules.

@GET
@Path("/{btLocator}/vcs-root-entries/{vcsRootLocator}/" + VcsRootEntry.CHECKOUT_RULES)
@Produces({ "text/plain" })
@ApiOperation(value = "Get checkout rules of a VCS root of the matching build configuration.", nickname = "getVcsRootCheckoutRules")
public String getVcsRootEntryCheckoutRules(@ApiParam(format = LocatorName.BUILD_TYPE) @PathParam("btLocator") String buildTypeLocator, @ApiParam(format = LocatorName.VCS_ROOT) @PathParam("vcsRootLocator") String vcsRootLocator) {
    final BuildTypeOrTemplate buildType = myBuildTypeFinder.getBuildTypeOrTemplate(null, buildTypeLocator, true);
    final SVcsRoot vcsRoot = myVcsRootFinder.getItem(vcsRootLocator);
    if (!buildType.get().containsVcsRoot(vcsRoot.getId())) {
        throw new NotFoundException("VCS root with id '" + vcsRoot.getExternalId() + "' is not attached to the build type.");
    }
    return buildType.get().getCheckoutRules(vcsRoot).getAsString();
}
Also used : BuildTypeOrTemplate(jetbrains.buildServer.server.rest.util.BuildTypeOrTemplate) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) ApiOperation(io.swagger.annotations.ApiOperation)

Example 12 with SVcsRoot

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

the class VCSLabelingOptions method applyTo.

public void applyTo(final BuildTypeOrTemplate buildType, @NotNull final BeanContext context) {
    if (labelName == null) {
        throw new BadRequestException("Label name is not specified.");
    }
    if (type == null) {
        throw new BadRequestException("Labeling type is not specified.");
    }
    BuildTypeSettings buildTypeSettings = buildType.get();
    for (SBuildFeatureDescriptor feature : buildTypeSettings.getBuildFeatures()) {
        if (feature.getType().equals(VcsLabelingBuildFeature.VCS_LABELING_TYPE)) {
            buildTypeSettings.removeBuildFeature(feature.getId());
        }
    }
    for (SVcsRoot vcsRoot : vcsRoots.getVcsRoots(context.getSingletonService(VcsRootFinder.class))) {
        Map<String, String> params = new HashMap<String, String>();
        params.put(VcsLabelingBuildFeature.VCS_ROOT_ID_PARAM, vcsRoot.getExternalId());
        params.put(VcsLabelingBuildFeature.LABELING_PATTERN_PARAM, labelName);
        if ("SUCCESSFUL_ONLY".equals(type)) {
            params.put(VcsLabelingBuildFeature.SUCCESSFUL_ONLY_PARAM, "true");
        }
        if (branchFilter != null) {
            params.put(VcsLabelingBuildFeature.BRANCH_FILTER_PARAM, branchFilter);
        }
        buildTypeSettings.addBuildFeature(VcsLabelingBuildFeature.VCS_LABELING_TYPE, params);
    }
}
Also used : SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) HashMap(java.util.HashMap) VcsRootFinder(jetbrains.buildServer.server.rest.data.VcsRootFinder) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) SBuildFeatureDescriptor(jetbrains.buildServer.serverSide.SBuildFeatureDescriptor) BuildTypeSettings(jetbrains.buildServer.serverSide.BuildTypeSettings)

Example 13 with SVcsRoot

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

the class SpaceExternalChangeViewerExtension method getAvailableProperties.

@Nullable
@Override
public Map<String, String> getAvailableProperties(@NotNull VcsRoot vcs) {
    final VcsRootInstance vcsRoot = (VcsRootInstance) vcs;
    if (!Constants.VCS_NAME.equals(vcsRoot.getVcsName()))
        return null;
    String url = vcsRoot.getProperty(Constants.FETCH_URL);
    if (url == null)
        return null;
    URIish uri;
    try {
        uri = new URIish(url);
    } catch (URISyntaxException e) {
        return null;
    }
    final String gitPath = uri.getPath();
    if (uri.getHost().endsWith(".jetbrains.space")) {
        // Space is on the Jetbrains side
        final String[] strings = gitPath.substring(1).split("/");
        if (strings.length == 3) {
            final String orgName = strings[0];
            final String project = strings[1];
            final String repository = strings[2].replaceFirst("\\.git$", "");
            final String repositoryUrl = String.format("https://%s.jetbrains.space/p/%s/repositories/%s", orgName, project, repository);
            return createResponse(repositoryUrl);
        }
    } else {
        final SVcsRoot vcsRootParent = vcsRoot.getParent();
        final List<OAuthConnectionDescriptor> connections = myOAuthConnectionsManager.getAvailableConnectionsOfType(vcsRootParent.getProject(), SpaceOAuthProvider.TYPE);
        if (connections.isEmpty())
            return null;
        for (OAuthConnectionDescriptor connection : connections) {
            final SpaceConnectDescriber spaceConnectDescriber = new SpaceConnectDescriber(connection);
            final String spaceAddress = spaceConnectDescriber.getAddress();
            if (uri.getHost().contains(spaceAddress)) {
                // Selfhosted Space
                final String[] strings = gitPath.substring(1).split("/");
                if (strings.length == 2) {
                    final String project = strings[0];
                    final String repository = strings[1].replaceFirst("\\.git$", "");
                    final String repositoryUrl = String.format("https://%s/p/%s/repositories/%s", spaceAddress, project, repository);
                    return createResponse(repositoryUrl);
                }
            }
        }
    }
    return null;
}
Also used : URIish(org.eclipse.jgit.transport.URIish) SpaceConnectDescriber(jetbrains.buildServer.serverSide.oauth.space.SpaceConnectDescriber) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) OAuthConnectionDescriptor(jetbrains.buildServer.serverSide.oauth.OAuthConnectionDescriptor) URISyntaxException(java.net.URISyntaxException) VcsRootInstance(jetbrains.buildServer.vcs.VcsRootInstance) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with SVcsRoot

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

the class GitHubPasswordAuthHealthPage method fillModel.

@Override
public void fillModel(@NotNull Map<String, Object> model, @NotNull HttpServletRequest request) {
    super.fillModel(model, request);
    final SVcsRoot vcsRoot = getRootFromRequest(request);
    if (vcsRoot == null)
        return;
    final String passwordProperty = vcsRoot.getProperty(Constants.PASSWORD);
    model.put("isPasswordContainsReference", StringUtil.isNotEmpty(passwordProperty) && ReferencesResolverUtil.containsReference(passwordProperty));
}
Also used : SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot)

Example 15 with SVcsRoot

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

the class SGitVcsRoot method getOrRefreshToken.

@Nullable
protected ExpiringAccessToken getOrRefreshToken(@NotNull String tokenId) {
    VcsRoot vcsRoot = getOriginalRoot();
    if (myTokenRefresher == null)
        return null;
    SVcsRoot parentRoot = vcsRoot instanceof SVcsRoot ? (SVcsRoot) vcsRoot : vcsRoot instanceof VcsRootInstance ? ((VcsRootInstance) vcsRoot).getParent() : null;
    if (parentRoot == null) {
        return myTokenRefresher.getRefreshableToken(vcsRoot.getExternalId(), tokenId);
    } else {
        return myTokenRefresher.getRefreshableToken(parentRoot.getProject(), tokenId);
    }
}
Also used : SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) SVcsRoot(jetbrains.buildServer.vcs.SVcsRoot) VcsRoot(jetbrains.buildServer.vcs.VcsRoot) VcsRootInstance(jetbrains.buildServer.vcs.VcsRootInstance) Nullable(org.jetbrains.annotations.Nullable)

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