Search in sources :

Example 1 with Branch

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

the class Build method getFieldValue.

@Nullable
public static String getFieldValue(@NotNull final BuildPromotion buildPromotion, @Nullable final String field, @NotNull final BeanContext beanContext) {
    final Build build = new Build(buildPromotion, Fields.ALL, beanContext);
    if ("number".equals(field)) {
        // supporting number here in addition to BuildRequest as this method is used from other requests classes as well
        return build.getNumber();
    } else if ("status".equals(field)) {
        return build.getStatus();
    } else if ("statusText".equals(field)) {
        return build.getStatusText();
    } else if ("id".equals(field)) {
        return String.valueOf(build.getId());
    } else if ("state".equals(field)) {
        return build.getState().toString();
    } else if ("failedToStart".equals(field)) {
        return String.valueOf(build.isFailedToStart());
    } else if ("startEstimateDate".equals(field)) {
        return build.getStartEstimate();
    } else if (FINISH_ESTIMATE.equals(field)) {
        return build.getFinishEstimate();
    } else if ("percentageComplete".equals(field)) {
        return String.valueOf(build.getPercentageComplete());
    } else if ("personal".equals(field)) {
        return String.valueOf(build.isPersonal());
    } else if ("usedByOtherBuilds".equals(field)) {
        return String.valueOf(build.isUsedByOtherBuilds());
    } else if ("queuedDate".equals(field)) {
        return build.getQueuedDate();
    } else if ("startDate".equals(field)) {
        return build.getStartDate();
    } else if ("finishDate".equals(field)) {
        return build.getFinishDate();
    } else if ("buildTypeId".equals(field)) {
        return build.getBuildTypeId();
    } else if ("buildTypeInternalId".equals(field)) {
        return buildPromotion.getBuildTypeId();
    } else if ("branchName".equals(field)) {
        return build.getBranchName();
    } else if ("branch".equals(field)) {
        Branch branch = buildPromotion.getBranch();
        return branch == null ? "" : branch.getName();
    } else if ("defaultBranch".equals(field)) {
        return String.valueOf(build.getDefaultBranch());
    } else if ("unspecifiedBranch".equals(field)) {
        return String.valueOf(build.getUnspecifiedBranch());
    } else if (PROMOTION_ID.equals(field) || "promotionId".equals(field)) {
        // Experimental support only
        return (String.valueOf(build.getPromotionId()));
    } else if ("modificationId".equals(field)) {
        // Experimental support only
        return String.valueOf(buildPromotion.getLastModificationId());
    } else if ("chainModificationId".equals(field)) {
        // Experimental support only
        return String.valueOf(((BuildPromotionEx) buildPromotion).getChainModificationId());
    } else if ("commentText".equals(field)) {
        // Experimental support only
        final Comment comment = build.getComment();
        return comment == null ? null : comment.text;
    } else if ("collectChangesError".equals(field)) {
        // Experimental support only
        return ((BuildPromotionEx) buildPromotion).getCollectChangesError();
    } else if ("changesCollectingInProgress".equals(field)) {
        // Experimental support only
        return String.valueOf(((BuildPromotionEx) buildPromotion).isChangesCollectingInProgress());
    } else if ("changeCollectingNeeded".equals(field)) {
        // Experimental support only
        return String.valueOf(((BuildPromotionEx) buildPromotion).isChangeCollectingNeeded());
    } else if ("revision".equals(field)) {
        // Experimental support only
        final List<BuildRevision> revisions = buildPromotion.getRevisions();
        return revisions.size() != 1 ? String.valueOf(revisions.get(0).getRevision()) : null;
    } else if ("settingsHash".equals(field)) {
        // Experimental support only to get settings digest
        return new String(Hex.encodeHex(((BuildPromotionEx) buildPromotion).getSettingsDigest(false)));
    } else if ("currentSettingsHash".equals(field)) {
        // Experimental support only to get settings digest
        return new String(Hex.encodeHex(((BuildPromotionEx) buildPromotion).getBuildSettings().getDigest()));
    }
    final SBuild associatedBuild = buildPromotion.getAssociatedBuild();
    final SQueuedBuild queuedBuild = buildPromotion.getQueuedBuild();
    if ("triggeredBy.username".equals(field)) {
        // Experimental support only
        if (associatedBuild != null) {
            final SUser user = associatedBuild.getTriggeredBy().getUser();
            return user == null ? null : user.getUsername();
        }
        if (queuedBuild != null) {
            final SUser user = queuedBuild.getTriggeredBy().getUser();
            return user == null ? null : user.getUsername();
        }
        return null;
    } else if ("triggeredBy.raw".equals(field)) {
        // Experimental support only
        if (associatedBuild != null) {
            return associatedBuild.getTriggeredBy().getRawTriggeredBy();
        }
        if (queuedBuild != null) {
            return queuedBuild.getTriggeredBy().getRawTriggeredBy();
        }
        return null;
    }
    throw new NotFoundException("Field '" + field + "' is not supported. Supported are: number, status, statusText, id, startDate, finishDate, buildTypeId, branchName.");
}
Also used : BaseBuild(jetbrains.buildServer.serverSide.impl.BaseBuild) Branch(jetbrains.buildServer.serverSide.Branch) SUser(jetbrains.buildServer.users.SUser) RevisionsNotFoundException(jetbrains.buildServer.vcs.impl.RevisionsNotFoundException) NotFoundException(jetbrains.buildServer.server.rest.errors.NotFoundException) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

NotFoundException (jetbrains.buildServer.server.rest.errors.NotFoundException)1 Branch (jetbrains.buildServer.serverSide.Branch)1 BaseBuild (jetbrains.buildServer.serverSide.impl.BaseBuild)1 SUser (jetbrains.buildServer.users.SUser)1 RevisionsNotFoundException (jetbrains.buildServer.vcs.impl.RevisionsNotFoundException)1 Nullable (org.jetbrains.annotations.Nullable)1