java.lang.Object
org.thoughtslive.jenkins.plugins.hubot.util.Common

public class Common extends Object
Common utility functions.
Author:
Naresh Rayapati
  • Constructor Details

    • Common

      public Common()
  • Method Details

    • sanitizeURL

      public static String sanitizeURL(String url)
      Attaches the "/" at end of given url.
      Parameters:
      url - url as a string.
      Returns:
      url which ends with "/"
    • log

      public static void log(PrintStream logger, Object message)
      Write a message to the given print stream.
      Parameters:
      logger - PrintStream
      message - to log.
    • getJobName

      public static String getJobName(EnvVars envVars)
    • getBuildNumber

      public static String getBuildNumber(PrintStream logger, EnvVars envVars)
      Returns build number from the given Environment Vars.
      Parameters:
      logger - PrintStream
      envVars - EnvVars
      Returns:
      build number of current job.
    • parseResponse

      public static <T> ResponseData<T> parseResponse(retrofit2.Response<T> response) throws IOException
      Converts Retrofit's Response to ResponseData
      Parameters:
      response - instance of Response
      Returns:
      an instance of ResponseData
      Throws:
      IOException
    • buildErrorResponse

      public static <T> ResponseData<T> buildErrorResponse(Exception e)
      Builds error response from the given exception.
      Parameters:
      e - instance of Exception
      Returns:
      an instance of ResponseData
    • getRootCause

      public static Throwable getRootCause(Throwable throwable)
      Returns actual Cause from the given exception.
      Returns:
      Throwable
    • prepareBuildUserName

      public static String prepareBuildUserName(List<Cause> causes, EnvVars envVars)
      Return the current build user.
      Parameters:
      causes - build causes.
      envVars - environment variables.
      Returns:
      user name.
    • prepareBuildCause

      public static String prepareBuildCause(List<Cause> causes)
      Retrun the build cause.
      Returns:
      build cause.
    • prepareBuildUserId

      public static String prepareBuildUserId(List<Cause> causes, EnvVars envVars)
      Return the current build user Id.
      Parameters:
      causes - build causes.
      envVars - environment variables.
      Returns:
      user name.
    • expandMacros

      public static Map expandMacros(String tokens, Run<?,?> run, FilePath ws, TaskListener listener)
      Expands given macro, see Token Marco plugin.
    • logResponse

      public static <T> ResponseData<T> logResponse(ResponseData<T> response, PrintStream logger, boolean failOnError) throws AbortException
      Log code and error message if any.
      Returns:
      response data.
      Throws:
      AbortException