Class GitUtils


  • public final class GitUtils
    extends Object
    • Method Detail

      • isValidCommitSha

        public static boolean isValidCommitSha​(String gitCommit)
        Check if the git commit is a valid commit.
        Parameters:
        gitCommit - the git commit to evaluate
        Returns:
        true if the git commit is a valid SHA 40 (HEX)
      • isValidRepositoryURL

        public static boolean isValidRepositoryURL​(String gitRepositoryURL)
        Check if the git repository URL is a valid repository
        Parameters:
        gitRepositoryURL - the current git repository
        Returns:
        true if the git repository url is a valid repository in either http or scp form.
      • buildGitMetadata

        public static GitMetadata buildGitMetadata​(@Nullable
                                                   org.jenkinsci.plugins.gitclient.GitClient gitClient,
                                                   @Nullable
                                                   String branchHint)
      • newGitClient

        @Nullable
        public static org.jenkinsci.plugins.gitclient.GitClient newGitClient​(TaskListener listener,
                                                                             EnvVars envVars,
                                                                             FilePath workspace)
        Creates a new instance of a GitClient.
        Parameters:
        listener - the task listener
        envVars - the env vars available
        workspace - the workspace to use to build the Git client
        Returns:
        gitClient
      • buildGitMetadataWithJenkinsEnvVars

        public static GitMetadata buildGitMetadataWithJenkinsEnvVars​(Map<String,​String> envVars)
      • buildGitMetadataWithUserSuppliedEnvVars

        public static GitMetadata buildGitMetadataWithUserSuppliedEnvVars​(Map<String,​String> envVars)
      • normalizeTag

        public static String normalizeTag​(String tagName)
        Returns a normalized git tag E.g: refs/heads/tags/0.1.0 or origin/tags/0.1.0 returns 0.1.0
        Parameters:
        tagName - the tag name to normalize
        Returns:
        normalized git tag
      • normalizeBranch

        public static String normalizeBranch​(String branchName)
        Returns a normalized git branch E.g. refs/heads/master or origin/master returns master
        Parameters:
        branchName - the branch name to normalize
        Returns:
        normalized git tag
      • filterSensitiveInfo

        public static String filterSensitiveInfo​(String urlStr)
        Filters the user info given a valid HTTP URL.
        Parameters:
        urlStr - input URL
        Returns:
        URL without user info.