Class GitUtils
- java.lang.Object
-
- org.datadog.jenkins.plugins.datadog.util.git.GitUtils
-
public final class GitUtils extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
isCommitInfoAlreadyCreated(Run<?,?> run, String gitCommit)
Check if the GitCommitAction has been already created and populated.static boolean
isRepositoryInfoAlreadyCreated(Run<?,?> run, String gitRepositoryUrl)
Check if the GitRepositoryAction has been already created and populated.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.static boolean
isValidCommit(String gitCommit)
Check if the git commit is a valid commit.static boolean
isValidRepositoryURL(String gitRepositoryURL)
Check if the git repository URL is a valid repositorystatic org.jenkinsci.plugins.gitclient.GitClient
newGitClient(TaskListener listener, EnvVars envVars, FilePath workspace)
Creates a new instance of aGitClient
.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 calculatedstatic 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 calculatedstatic 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 calculatedstatic String
resolveGitTag(Map<String,String> envVars)
Resolve the value for the git tag based 1: Check user supplied env var 3: Check BuildData already calculatedstatic RepositoryInfo
searchRepositoryInfo(org.jenkinsci.plugins.gitclient.GitClient gitClient)
Return theRepositoryInfo
for a certain Git repository.static org.eclipse.jgit.revwalk.RevCommit
searchRevCommit(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.
-
-
-
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 theRepositoryInfo
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 aGitClient
.- Parameters:
listener
- the task listenerenvVars
- the env vars availableworkspace
- 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 rungitRepositoryUrl
- 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 rungitCommit
- 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.
-
-