Class GitUtils


  • public final class GitUtils
    extends Object
    • Method Detail

      • searchRevCommit

        public static org.eclipse.jgit.revwalk.RevCommit searchRevCommit​(@Nullable
                                                                         org.jenkinsci.plugins.gitclient.GitClient gitClient,
                                                                         String gitCommit)
        Return the RevCommit for a certain commit based on the information stored in a certain workspace of a certain node.
        Parameters:
        gitCommit - the Git commit SHA to search info.
        gitClient - the Git client used.
        Returns:
        revCommit
      • searchRepositoryInfo

        public static RepositoryInfo searchRepositoryInfo​(@Nullable
                                                          org.jenkinsci.plugins.gitclient.GitClient gitClient)
        Return the RepositoryInfo for a certain Git repository.
        Parameters:
        gitClient - The Git client to use to obtain the repository information
        Returns:
        repositoryInfo
      • 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
      • isValidCommit

        public static boolean isValidCommit​(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.
      • isRepositoryInfoAlreadyCreated

        public static boolean isRepositoryInfoAlreadyCreated​(Run<?,​?> run,
                                                             String gitRepositoryUrl)
        Check if the GitRepositoryAction has been already created and populated. Typically this method is used to avoid calculating the action multiple times.
        Parameters:
        run - the current run
        gitRepositoryUrl - the current git respository
        Returns:
        true if the action has been created and populated.
      • isCommitInfoAlreadyCreated

        public static boolean isCommitInfoAlreadyCreated​(Run<?,​?> run,
                                                         String gitCommit)
        Check if the GitCommitAction has been already created and populated. Typically this method is used to avoid calculating the action multiple times.
        Parameters:
        run - the current run
        gitCommit - the git commit to check for
        Returns:
        true if the action has been created and populated.
      • resolveGitBranch

        public static String resolveGitBranch​(Map<String,​String> envVars)
        Resolve the value for the git branch based 1: Check user supplied env var 2: Check Jenkins env var 3: Check BuildData already calculated
        Parameters:
        envVars - the user supplied env vars
        Returns:
        the branch value.
      • resolveGitCommit

        public static String resolveGitCommit​(Map<String,​String> envVars)
        Resolve the value for the git commit sha based 1: Check user supplied env var 2: Check Jenkins env var 3: Check BuildData already calculated
        Parameters:
        envVars - the user supplied env vars
        Returns:
        the commit sha value.
      • resolveGitRepositoryUrl

        public static String resolveGitRepositoryUrl​(Map<String,​String> envVars)
        Resolve the value for the git repository url based 1: Check user supplied env var 2: Check Jenkins env var 3: Check BuildData already calculated
        Parameters:
        envVars - the user supplied env vars
        Returns:
        the git repository url value.
      • resolveGitTag

        public static String resolveGitTag​(Map<String,​String> envVars)
        Resolve the value for the git tag based 1: Check user supplied env var 3: Check BuildData already calculated
        Parameters:
        envVars - the user supplied environment variables
        Returns:
        the git tag value.
      • isUserSuppliedGit

        public static boolean isUserSuppliedGit​(Map<String,​String> envVars)
        Check if the env vars map contains any environment variable with Git information supplied by the user manually.
        Parameters:
        envVars - the environment variables
        Returns:
        true if any of the env vars is not empty.