public static Details getDetails()

in rest-api/src/jetbrains/buildServer/server/rest/model/build/TriggeredBy.java [124:204]


  public static Details getDetails(@NotNull final jetbrains.buildServer.serverSide.TriggeredBy triggeredBy, @NotNull final ServiceLocator serviceLocator) {
    Details result = new Details();
    //see also jetbrains.buildServer.serverSide.impl.ServerTriggeredByProcessor.render()
    final String rawTriggeredBy = triggeredBy.getRawTriggeredBy();
    if (rawTriggeredBy != null && !rawTriggeredBy.startsWith(TriggeredByBuilder.PARAMETERS_PREFIX)) {
      result.type = "unknown";
      result.details = rawTriggeredBy;
    }

    final Map<String, String> triggeredByParams = triggeredBy.getParameters();

    String buildId = triggeredByParams.get(TriggeredByBuilder.BUILD_ID_PARAM_NAME);
    if (buildId != null) {
      try {
        result.build = serviceLocator.getSingletonService(BuildPromotionFinder.class).getBuildPromotion(Long.parseLong(buildId));
      } catch (Exception ignore) {
      }
    }

    String typeInParams = triggeredByParams.get(TriggeredByBuilder.TYPE_PARAM_NAME);
    if (typeInParams != null) {
      result.type = typeInParams;
    }


    String buildTypeId = triggeredByParams.get(TriggeredByBuilder.BUILD_TYPE_ID_PARAM_NAME);
    if (buildTypeId != null) {
      if (typeInParams == null) {
        result.type = "buildType";
      }
      try {
        //this mostly duplicates the data from the "build" sub-node, but can be useful (when build is deleted) and this was also part of API before 2017.1
        result.buildType = serviceLocator.getSingletonService(ProjectManager.class).findBuildTypeById(buildTypeId);
      } catch (AccessDeniedException ignore) {
        //ignoring inability to view the triggering build type
      }
      return result;
    }

    if (triggeredByParams.get("unexpectedFinish") != null ||
        triggeredByParams.get(TriggeredByBuilder.RE_ADDED_AFTER_STOP_NAME) != null) {
      if (typeInParams == null || "unexpectedFinish".equals(typeInParams)) {
        //compatibility with "type" value prior to 2017.1
        result.type = "restarted";
      }
      return result;
    }

    String idePlugin = triggeredByParams.get(TriggeredByBuilder.IDE_PLUGIN_PARAM_NAME);
    if (idePlugin != null) {
      if (typeInParams == null || CORE_TRIGGERED_BY_TYPE_XML_RPC.equals(typeInParams)) {
        //compatibility with "type" value prior to 2017.1
        result.type = TYPE_IDE_PLUGIN_REST;
      }
      result.details = idePlugin;
      return result;
    }

    String vcsName = triggeredByParams.get(TriggeredByBuilder.VCS_NAME_PARAM_NAME);
    if (vcsName != null) {
      if (typeInParams == null) {
        result.type = "vcs";
      }
      result.details = vcsName;
      return result;
    }

    String user = triggeredByParams.get(TriggeredByBuilder.USER_PARAM_NAME);
    if (user != null) {
      if (typeInParams == null) {
        result.type = "user";
      }
      return result;
    }

    if (typeInParams == null) {
      result.type = "unknown";
      result.details = rawTriggeredBy;
    }
    return result;
  }