Class GitUtils
- java.lang.Object
-
- org.datadog.jenkins.plugins.datadog.util.git.GitUtils
-
public final class GitUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static StringCHANGE_BRANCHFor a multibranch project corresponding to some kind of change request, this will be set to the name of the actual head on the source control system which may or may not be different from BRANCH_NAME.static StringDD_GIT_BRANCHstatic StringDD_GIT_COMMIT_AUTHOR_DATEstatic StringDD_GIT_COMMIT_AUTHOR_EMAILstatic StringDD_GIT_COMMIT_AUTHOR_NAMEstatic StringDD_GIT_COMMIT_COMMITTER_DATEstatic StringDD_GIT_COMMIT_COMMITTER_EMAILstatic StringDD_GIT_COMMIT_COMMITTER_NAMEstatic StringDD_GIT_COMMIT_MESSAGEstatic StringDD_GIT_COMMIT_SHAstatic StringDD_GIT_DEFAULT_BRANCHstatic StringDD_GIT_REPOSITORY_URLstatic StringDD_GIT_TAGstatic StringGIT_BRANCHstatic StringGIT_BRANCH_ALTstatic StringGIT_COMMITstatic StringGIT_REPOSITORY_URLstatic StringGIT_REPOSITORY_URL_ALT
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static GitMetadatabuildGitMetadata(org.jenkinsci.plugins.gitclient.GitClient gitClient, String branchHint)static GitMetadatabuildGitMetadataWithJenkinsEnvVars(Map<String,String> envVars)static GitMetadatabuildGitMetadataWithUserSuppliedEnvVars(Map<String,String> envVars)static StringfilterSensitiveInfo(String urlStr)Filters the user info given a valid HTTP URL.static booleanisValidCommitSha(String gitCommit)Check if the git commit is a valid commit.static booleanisValidRepositoryURL(String gitRepositoryURL)Check if the git repository URL is a valid repositorystatic org.jenkinsci.plugins.gitclient.GitClientnewGitClient(TaskListener listener, EnvVars envVars, FilePath workspace)Creates a new instance of aGitClient.static StringnormalizeBranch(String branchName)Returns a normalized git branch E.g.static StringnormalizeTag(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
-
-
-
Field Detail
-
DD_GIT_REPOSITORY_URL
public static final String DD_GIT_REPOSITORY_URL
- See Also:
- Constant Field Values
-
DD_GIT_BRANCH
public static final String DD_GIT_BRANCH
- See Also:
- Constant Field Values
-
DD_GIT_TAG
public static final String DD_GIT_TAG
- See Also:
- Constant Field Values
-
DD_GIT_DEFAULT_BRANCH
public static final String DD_GIT_DEFAULT_BRANCH
- See Also:
- Constant Field Values
-
DD_GIT_COMMIT_SHA
public static final String DD_GIT_COMMIT_SHA
- See Also:
- Constant Field Values
-
DD_GIT_COMMIT_MESSAGE
public static final String DD_GIT_COMMIT_MESSAGE
- See Also:
- Constant Field Values
-
DD_GIT_COMMIT_AUTHOR_NAME
public static final String DD_GIT_COMMIT_AUTHOR_NAME
- See Also:
- Constant Field Values
-
DD_GIT_COMMIT_AUTHOR_EMAIL
public static final String DD_GIT_COMMIT_AUTHOR_EMAIL
- See Also:
- Constant Field Values
-
DD_GIT_COMMIT_AUTHOR_DATE
public static final String DD_GIT_COMMIT_AUTHOR_DATE
- See Also:
- Constant Field Values
-
DD_GIT_COMMIT_COMMITTER_NAME
public static final String DD_GIT_COMMIT_COMMITTER_NAME
- See Also:
- Constant Field Values
-
DD_GIT_COMMIT_COMMITTER_EMAIL
public static final String DD_GIT_COMMIT_COMMITTER_EMAIL
- See Also:
- Constant Field Values
-
DD_GIT_COMMIT_COMMITTER_DATE
public static final String DD_GIT_COMMIT_COMMITTER_DATE
- See Also:
- Constant Field Values
-
GIT_REPOSITORY_URL
public static final String GIT_REPOSITORY_URL
- See Also:
- Constant Field Values
-
GIT_REPOSITORY_URL_ALT
public static final String GIT_REPOSITORY_URL_ALT
- See Also:
- Constant Field Values
-
GIT_BRANCH
public static final String GIT_BRANCH
- See Also:
- Constant Field Values
-
GIT_BRANCH_ALT
public static final String GIT_BRANCH_ALT
- See Also:
- Constant Field Values
-
GIT_COMMIT
public static final String GIT_COMMIT
- See Also:
- Constant Field Values
-
CHANGE_BRANCH
public static final String CHANGE_BRANCH
For a multibranch project corresponding to some kind of change request, this will be set to the name of the actual head on the source control system which may or may not be different from BRANCH_NAME. For example in GitHub or Bitbucket this would have the name of the origin branch whereas BRANCH_NAME would be something like PR-24- See Also:
- Constant Field Values
-
-
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 aGitClient.- Parameters:
listener- the task listenerenvVars- the env vars availableworkspace- 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
-
-