Search in sources :

Example 6 with SBuildType

use of jetbrains.buildServer.serverSide.SBuildType in project commit-status-publisher by JetBrains.

the class SecurityParametersReportPageExtension method isAvailable.

@Override
public boolean isAvailable(@NotNull final HttpServletRequest request) {
    if (!super.isAvailable(request))
        return false;
    HealthStatusItem item = getStatusItem(request);
    SBuildType bt = (SBuildType) item.getAdditionalData().get("buildType");
    if (bt == null)
        return false;
    return SessionUser.getUser(request).isPermissionGrantedForProject(bt.getProjectId(), Permission.VIEW_BUILD_CONFIGURATION_SETTINGS);
}
Also used : HealthStatusItem(jetbrains.buildServer.serverSide.healthStatus.HealthStatusItem) SBuildType(jetbrains.buildServer.serverSide.SBuildType)

Example 7 with SBuildType

use of jetbrains.buildServer.serverSide.SBuildType in project commit-status-publisher by JetBrains.

the class MissingSettingsReport method report.

@Override
public void report(@NotNull HealthStatusScope scope, @NotNull HealthStatusItemConsumer consumer) {
    for (SBuildType bt : scope.getBuildTypes()) {
        Collection<SBuildFeatureDescriptor> features = bt.getBuildFeaturesOfType(CommitStatusPublisherFeature.TYPE);
        for (SBuildFeatureDescriptor feature : features) {
            if (bt.isEnabled(feature.getId())) {
                Map<String, String> params = feature.getParameters();
                String publisherId = params.get(Constants.PUBLISHER_ID_PARAM);
                if (publisherId == null || !publisherId.equals(SPACE_PUBLISHER_ID))
                    continue;
                CommitStatusPublisherSettings settings = myPublisherManager.findSettings(publisherId);
                if (settings != null) {
                    Map<String, Object> healthItemData = settings.checkHealth(bt, params);
                    if (healthItemData != null) {
                        String identity = REPORT_TYPE + "_BT_" + bt.getInternalId() + "_FEATURE_" + feature.getId();
                        healthItemData.put("buildType", bt);
                        healthItemData.put("featureId", feature.getId());
                        consumer.consumeForBuildType(bt, new HealthStatusItem(identity, CATEGORY, healthItemData));
                    }
                }
            }
        }
    }
}
Also used : SBuildType(jetbrains.buildServer.serverSide.SBuildType) CommitStatusPublisherSettings(jetbrains.buildServer.commitPublisher.CommitStatusPublisherSettings) SBuildFeatureDescriptor(jetbrains.buildServer.serverSide.SBuildFeatureDescriptor)

Example 8 with SBuildType

use of jetbrains.buildServer.serverSide.SBuildType in project commit-status-publisher by JetBrains.

the class NoFQDNServerUrlReport method report.

@Override
public void report(@NotNull HealthStatusScope scope, @NotNull HealthStatusItemConsumer consumer) {
    for (SBuildType bt : scope.getBuildTypes()) {
        Collection<SBuildFeatureDescriptor> features = bt.getBuildFeaturesOfType(CommitStatusPublisherFeature.TYPE);
        for (SBuildFeatureDescriptor feature : features) {
            if (bt.isEnabled(feature.getId())) {
                Map<String, String> params = feature.getParameters();
                String publisherId = params.get(Constants.PUBLISHER_ID_PARAM);
                if (publisherId == null)
                    continue;
                CommitStatusPublisherSettings settings = myPublisherManager.findSettings(publisherId);
                if (null != settings && settings.isFQDNTeamCityUrlRequired()) {
                    String rootUrl = myLinks.getRootUrlByProjectInternalId(bt.getProjectId());
                    if (!URL_WITH_FQDN_PATTERN.matcher(rootUrl).matches()) {
                        String identity = REPORT_TYPE + "_BT_" + bt.getInternalId() + "_FEATURE_" + feature.getId();
                        Map<String, Object> additionalData = new HashMap<>();
                        additionalData.put("rootUrl", rootUrl);
                        additionalData.put("buildType", bt);
                        additionalData.put("publisherType", settings.getName());
                        consumer.consumeForBuildType(bt, new HealthStatusItem(identity, CATEGORY, additionalData));
                    }
                }
            }
        }
    }
}
Also used : SBuildType(jetbrains.buildServer.serverSide.SBuildType) CommitStatusPublisherSettings(jetbrains.buildServer.commitPublisher.CommitStatusPublisherSettings) SBuildFeatureDescriptor(jetbrains.buildServer.serverSide.SBuildFeatureDescriptor)

Example 9 with SBuildType

use of jetbrains.buildServer.serverSide.SBuildType in project commit-status-publisher by JetBrains.

the class DeprecatedAuthReport method report.

@Override
public void report(@NotNull HealthStatusScope scope, @NotNull HealthStatusItemConsumer consumer) {
    for (SBuildType bt : scope.getBuildTypes()) {
        Collection<SBuildFeatureDescriptor> features = bt.getBuildFeaturesOfType(CommitStatusPublisherFeature.TYPE);
        for (SBuildFeatureDescriptor feature : features) {
            if (bt.isEnabled(feature.getId())) {
                Map<String, String> params = feature.getParameters();
                String publisherId = params.get(Constants.PUBLISHER_ID_PARAM);
                if (publisherId == null || !publisherId.equals(Constants.GITHUB_PUBLISHER_ID))
                    continue;
                CommitStatusPublisherSettings settings = myPublisherManager.findSettings(publisherId);
                if (null != settings && GitHubApiAuthenticationType.PASSWORD_AUTH.getValue().equals(params.get(Constants.GITHUB_AUTH_TYPE))) {
                    String identity = REPORT_TYPE + "_BT_" + bt.getInternalId() + "_FEATURE_" + feature.getId();
                    Map<String, Object> additionalData = new HashMap<>();
                    additionalData.put("buildType", bt);
                    additionalData.put("publisherType", settings.getName());
                    consumer.consumeForBuildType(bt, new HealthStatusItem(identity, CATEGORY, additionalData));
                }
            }
        }
    }
}
Also used : SBuildType(jetbrains.buildServer.serverSide.SBuildType) HashMap(java.util.HashMap) CommitStatusPublisherSettings(jetbrains.buildServer.commitPublisher.CommitStatusPublisherSettings) SBuildFeatureDescriptor(jetbrains.buildServer.serverSide.SBuildFeatureDescriptor)

Example 10 with SBuildType

use of jetbrains.buildServer.serverSide.SBuildType in project teamcity-rest by JetBrains.

the class Investigation method getFromPostedAndApply.

@NotNull
public List<InvestigationWrapper> getFromPostedAndApply(@NotNull final ServiceLocator serviceLocator, final boolean allowMultipleResult) {
    checkIsValid();
    if (target == null) {
        throw new BadRequestException("Invalid 'investigation' entity: 'target' should be specified");
    }
    ProblemTarget.ProblemTargetData targetData;
    try {
        targetData = target.getFromPosted(serviceLocator);
    } catch (BadRequestException e) {
        throw new BadRequestException("Invalid 'investigation' entity: " + e.getMessage());
    }
    ResponsibilityEntry entry = new ResponsibilityEntryEx(TypedFinderBuilder.getEnumValue(state, ResponsibilityEntry.State.class), assignee.getFromPosted(serviceLocator.getSingletonService(UserFinder.class)), serviceLocator.getSingletonService(UserFinder.class).getCurrentUser(), new Date(), assignment == null || assignment.getTextFromPosted() == null ? "" : assignment.getTextFromPosted(), resolution.getFromPostedForInvestigation(serviceLocator));
    ResponsibilityFacadeEx responsibilityFacade = serviceLocator.getSingletonService(ResponsibilityFacadeEx.class);
    InvestigationFinder investigationFinder = serviceLocator.findSingletonService(InvestigationFinder.class);
    assert investigationFinder != null;
    List<InvestigationWrapper> resultEntries = new ArrayList<>(1);
    if (targetData.isAnyProblem()) {
        List<BuildType> buildTypesFromPosted = scope.getBuildTypesFromPosted(serviceLocator);
        if (!allowMultipleResult && buildTypesFromPosted.size() > 1) {
            throw new OnlySingleEntitySupportedException("Invalid 'scope' entity: for this request only single buildType is supported within 'buildTypes' entity");
        }
        for (BuildType buildType : buildTypesFromPosted) {
            responsibilityFacade.setBuildTypeResponsibility(buildType, entry);
            resultEntries.add(investigationFinder.getItem(InvestigationFinder.getLocator((SBuildType) buildType)));
        }
    } else {
        if (scope.buildTypes != null) {
            throw new BadRequestException("Invalid 'investigation' entity: Invalid 'scope' entity: 'buildTypes' should not be specified for not buildType-level investigation");
        }
        SProject project = scope.getProjectFromPosted(serviceLocator);
        List<STest> tests = targetData.getTests();
        if (!tests.isEmpty()) {
            if (!allowMultipleResult && tests.size() > 1) {
                throw new OnlySingleEntitySupportedException("Invalid 'target' entity: for this request only single test is supported within 'tests' entity");
            }
            responsibilityFacade.setTestNameResponsibility(tests.stream().map(sTest -> sTest.getName()).distinct().collect(Collectors.toList()), project.getProjectId(), entry);
            tests.stream().map(test -> // only one item should be found in the project
            investigationFinder.getItem(InvestigationFinder.getLocatorForTest(test.getTestNameId(), project))).distinct().forEachOrdered(resultEntries::add);
        }
        List<Long> problems = targetData.getProblemIds();
        if (!problems.isEmpty()) {
            if (!allowMultipleResult && problems.size() > 1) {
                throw new OnlySingleEntitySupportedException("Invalid 'target' entity: for this request only single problem is supported within 'problems' entity");
            }
            responsibilityFacade.setBuildProblemResponsibility(// seems like only id is used inside
            problems.stream().distinct().map(problemId -> ProblemWrapper.getBuildProblemInfo(problemId.intValue(), project.getProjectId())).collect(Collectors.toList()), project.getProjectId(), entry);
            problems.stream().distinct().map(problemId -> // only one item should be found in the project
            investigationFinder.getItem(InvestigationFinder.getLocatorForProblem(problemId.intValue(), project))).forEachOrdered(resultEntries::add);
        }
    }
    if (!allowMultipleResult && resultEntries.size() != 1) {
        throw new BadRequestException("Invalid 'investigation' entity: Invalid 'target' entity: found " + resultEntries.size() + " result entities, while exactly one is required");
    }
    return resultEntries;
}
Also used : Fields(jetbrains.buildServer.server.rest.model.Fields) User(jetbrains.buildServer.server.rest.model.user.User) Date(java.util.Date) InvestigationFinder(jetbrains.buildServer.server.rest.data.investigations.InvestigationFinder) ArrayList(java.util.ArrayList) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) ResponsibilityEntryEx(jetbrains.buildServer.responsibility.ResponsibilityEntryEx) XmlType(javax.xml.bind.annotation.XmlType) Comment(jetbrains.buildServer.server.rest.model.Comment) STest(jetbrains.buildServer.serverSide.STest) TypedFinderBuilder(jetbrains.buildServer.server.rest.data.TypedFinderBuilder) InvestigationWrapper(jetbrains.buildServer.server.rest.data.investigations.InvestigationWrapper) Api(io.swagger.annotations.Api) SBuildType(jetbrains.buildServer.serverSide.SBuildType) ModelDescription(jetbrains.buildServer.server.rest.swagger.annotations.ModelDescription) XmlAttribute(javax.xml.bind.annotation.XmlAttribute) TeamCityProperties(jetbrains.buildServer.serverSide.TeamCityProperties) ProblemWrapper(jetbrains.buildServer.server.rest.data.problem.ProblemWrapper) ServiceLocator(jetbrains.buildServer.ServiceLocator) BuildType(jetbrains.buildServer.BuildType) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) ValueWithDefault(jetbrains.buildServer.server.rest.util.ValueWithDefault) Collectors(java.util.stream.Collectors) List(java.util.List) ResponsibilityEntry(jetbrains.buildServer.responsibility.ResponsibilityEntry) Resolution(jetbrains.buildServer.server.rest.model.problem.Resolution) ResponsibilityFacadeEx(jetbrains.buildServer.responsibility.ResponsibilityFacadeEx) SProject(jetbrains.buildServer.serverSide.SProject) UserFinder(jetbrains.buildServer.server.rest.data.UserFinder) BeanContext(jetbrains.buildServer.server.rest.util.BeanContext) NotNull(org.jetbrains.annotations.NotNull) ApiModelProperty(io.swagger.annotations.ApiModelProperty) InvestigationRequest(jetbrains.buildServer.server.rest.request.InvestigationRequest) XmlElement(javax.xml.bind.annotation.XmlElement) InvestigationWrapper(jetbrains.buildServer.server.rest.data.investigations.InvestigationWrapper) ResponsibilityFacadeEx(jetbrains.buildServer.responsibility.ResponsibilityFacadeEx) ArrayList(java.util.ArrayList) ResponsibilityEntryEx(jetbrains.buildServer.responsibility.ResponsibilityEntryEx) InvestigationFinder(jetbrains.buildServer.server.rest.data.investigations.InvestigationFinder) SProject(jetbrains.buildServer.serverSide.SProject) Date(java.util.Date) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) ResponsibilityEntry(jetbrains.buildServer.responsibility.ResponsibilityEntry) SBuildType(jetbrains.buildServer.serverSide.SBuildType) BuildType(jetbrains.buildServer.BuildType) STest(jetbrains.buildServer.serverSide.STest) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SBuildType (jetbrains.buildServer.serverSide.SBuildType)20 SProject (jetbrains.buildServer.serverSide.SProject)8 Nullable (org.jetbrains.annotations.Nullable)5 List (java.util.List)4 ServiceLocator (jetbrains.buildServer.ServiceLocator)4 NotNull (org.jetbrains.annotations.NotNull)4 HashMap (java.util.HashMap)3 Collectors (java.util.stream.Collectors)3 CommitStatusPublisherSettings (jetbrains.buildServer.commitPublisher.CommitStatusPublisherSettings)3 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)3 SBuildFeatureDescriptor (jetbrains.buildServer.serverSide.SBuildFeatureDescriptor)3 STest (jetbrains.buildServer.serverSide.STest)3 Logger (com.intellij.openapi.diagnostic.Logger)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ArrayList (java.util.ArrayList)2 Lock (java.util.concurrent.locks.Lock)2 UserFinder (jetbrains.buildServer.server.rest.data.UserFinder)2 Fields (jetbrains.buildServer.server.rest.model.Fields)2 SUser (jetbrains.buildServer.users.SUser)2 BuildState (msteamsnotifications.teamcity.BuildState)2