class GitlabSCMProvider
Concrete implementation of SCMProvider interface for Gitlab
Modifiers | Name | Description |
---|---|---|
private java.lang.String |
gitlabContext |
|
private java.lang.String |
gitlabEndpoint |
|
private int |
gitlabPort |
|
private GitlabSCMProtocol |
gitlabSCMProtocol |
|
private java.lang.String |
internalEndpoint |
|
private java.lang.String |
scmContext |
|
private java.lang.String |
scmHost |
|
private int |
scmPort |
|
private GitlabSCMProtocol |
scmProtocol |
Constructor and description |
---|
GitlabSCMProvider
(int scmPort, GitlabSCMProtocol scmProtocol, java.lang.String scmHost, java.lang.String scmContext = "", GitlabSCMProtocol gitlabSCMProtocol, java.lang.String gitlabEndpoint, int gitlabPort, java.lang.String gitlabContext = "") Constructor for class GitlabSCMProvider. |
Type Params | Return Type | Name and description |
---|---|---|
|
private void |
copyDataFromRepositoryInUrlsTxt(java.lang.String workspace, java.lang.String repoName, java.lang.String namespace, java.lang.String repoFromUrlsTxt) Clone a repository from GitLab and populate it by pulling the data from the corresponding repository in urls.txt FIXME clone using SSH or in a way in which the access token is not stored in .git/config - fine for now as this is for evaluation purposes |
|
void |
createScmRepos(java.lang.String workspace, java.lang.String repoNamespace, java.lang.String codeReviewEnabled, java.lang.String overwriteRepos) Gets a list of repositories from urls.txt, validates them and then calls forkRepositoriesFromUrls to fork each repository in GitLab If urls is empty, non readable or does not exist then exit without doing anything |
|
private void |
deleteAndRecreateRepository(java.lang.String repoName, java.util.List existingProjectsInGroup, int groupNamespaceId) Deletes a GitLab repository and recreates it |
|
private java.lang.String |
extractRepoNameFromUrl(java.lang.String url) Extracts the repository name from an HTTP git repository url e.g for https://github.com/Accenture/adop-cartridge-java-environment-template.git return adop-cartridge-java-environment-template Gerrit repository names will not be extracted from Gerrit urls unless a substring /gerrit/, http(s)/gerrit or .gerrit. exists |
|
private void |
forkRepositoriesFromUrls(java.util.List<java.lang.String> repos, java.lang.String workspace, java.lang.String overwriteRepos, java.lang.String namespace) Given a list of public repositories from urls.txt, this method forks each of them into a GitLab group (common GitLab repository namespace e.g /namespace/repo1, /namespace/repo2) If the group does not already exist then it will be created. |
|
groovy.lang.Closure |
get(java.lang.String projectName, java.lang.String repoName, java.lang.String branchName, java.lang.String credentialId, groovy.lang.Closure extras) Return SCM section closuer for Jenkins DSL |
|
groovy.lang.Closure |
getMultibranch(java.lang.String projectName, java.lang.String repoName, java.lang.String credentialId, groovy.lang.Closure extras) Return a closure representation of the SCM section for multibranch pipelines (Jenkins DSL). |
|
private int |
getRepoId(java.util.List listOfExistingRepos, java.lang.String targetRepoName) Given a list of repository objects parsed from JSON it looks for a repository with a particular name and if it finds it, it extracts its id |
|
java.lang.String |
getScmUrl() Method which returns GitLab repository clone urls for http/https/ssh |
|
boolean |
isGerritUrl(java.lang.String url) Checks whether or not a clone repository url is for Gerrit. |
|
private void |
processRepositories(java.util.List repos, java.util.List existingProjectsInGroup, int groupNamespaceId, java.lang.String workspace, java.lang.String namespace, java.lang.String overwriteRepos) Given a list of repositories from urls.txt and a list of repositories which exist under a group, this method forks each repository in urls.txt to GitLab if it does not exist. |
|
private boolean |
repositoryAlreadyExistsInGroup(java.util.List listOfRepos, java.lang.String targetRepoName) Given a list of repository names and a target repository name, it checks that the list contains the target repository name |
|
groovy.lang.Closure |
trigger(java.lang.String projectName, java.lang.String repoName, java.lang.String branchName) Returns a closure representation of the SCM provider's trigger SCM section for Jenkins DSL. |
|
private boolean |
urlsTxtPermissionsAndPropertiesAreOk(java.io.File urlsFile, java.lang.String urlsFilePath) Checks that urls.txt exists, is readable and non empty |
|
private void |
validate() Validates that all the fields required to create an object out of this class are not null or empty |
|
private void |
validateRepo(java.lang.String repo) Validates a repository clone URL by checking the protocol against the GitLabSCM protocol enum (SSH is not allowed at the moment) |
|
private void |
validateRepos(java.util.List<java.lang.String> repos) Given a list of repositories, this method validates each of them by calling the validate method |
|
private java.lang.String |
validateResponseToGetGroupRequest(java.util.List response, java.lang.String namespace) Validates the response of an HTTP request to search for a group. |
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Constructor for class GitlabSCMProvider.
scmPort
- the scm port used when interacting with the scm provider to, for example clone e.g - HTTP, HTTPS or SSHscmProtocol
- the clone protocol used when interacting with the scm provider to, for example clone e.g - HTTP, HTTPS or SSHscmHost
- the clone url or host (for internal communication) when interacting with the scm provider e.g 10.0.0.1scmContext
- GitLab url context when interacting with the scm provider e.g /gitlab in http://gitlabSCMProtocol
- the cloning protocol used when performing cartridge loading operations - HTTP, HTTPS or SSHgitlabEndpoint
- the url used when performing cartridge loading operations e.g. 10.0.0.1gitlabPort
- the port used when performing cartridge loading operations e.g. 80gitlabContext
- the url context used when performing cartridge loading operations e.g /gitlab in http://Clone a repository from GitLab and populate it by pulling the data from the corresponding repository in urls.txt FIXME clone using SSH or in a way in which the access token is not stored in .git/config - fine for now as this is for evaluation purposes
workspace
- the current workspacerepoName
- the repository namenamespace
- the GitLab group namespacerepoFromUrlsTxt
- the clone url of the repository from urls.txtGets a list of repositories from urls.txt, validates them and then calls forkRepositoriesFromUrls to fork each repository in GitLab If urls is empty, non readable or does not exist then exit without doing anything
workspace
- the current workspacerepoNamespace
- the current namespace (called group namespace in GitLab)codeReviewEnabled
- not used in GitLaboverwriteRepos
- value of the overwriteRepos repos checkbox in jenkins. Can be "true" or "false"Deletes a GitLab repository and recreates it
repoName
- the repository nameexistingProjectsInGroup
- list of existing repositories in that group - used to get the ID of
the repository to be deletedgroupNamespaceId
- The id of the group which is used when recreating the repository in that groupExtracts the repository name from an HTTP git repository url e.g for https://github.com/Accenture/adop-cartridge-java-environment-template.git return adop-cartridge-java-environment-template Gerrit repository names will not be extracted from Gerrit urls unless a substring /gerrit/, http(s)/gerrit or .gerrit. exists
git
- clone repository urlGiven a list of public repositories from urls.txt, this method forks each of them into a GitLab group (common GitLab repository namespace e.g /namespace/repo1, /namespace/repo2) If the group does not already exist then it will be created. If the group already exists and a repository with the same name as one of the repos in urls.txt also exists then only overwrite the repo it if overwriteRepos is set to true
repos
- a list of public repositories to fork from urls.txtworkspace
- the current workspaceoverwriteRepos
- value of the overwrite repos checkbox in jenkins.namespace
- the Group namespace e.g myrepos for myrepos/reponameReturn SCM section closuer for Jenkins DSL
projectName
- name of the project.repoName
- name of the repository to clone.branchName
- name of branch.credentialId
- name of the credential in the Jenkins credential manager to use.extras
- extra closures to add to the SCM section.Return a closure representation of the SCM section for multibranch pipelines (Jenkins DSL).
projectName
- name of the project.repoName
- name of the repository to checkout.credentialId
- name of the credential in the Jenkins credential manager to use.extras
- extra closures to add to the multibranch SCM section.Given a list of repository objects parsed from JSON it looks for a repository with a particular name and if it finds it, it extracts its id
List
- of Repository objectsthe
- repository name to be searched for in the listMethod which returns GitLab repository clone urls for http/https/ssh
Checks whether or not a clone repository url is for Gerrit. It only captures the simplest cases where the string does not contain .git and one or of the substrings /gerrit/, http(s)/gerrit .gerrit. are present
url
- the repository url to be checkedGiven a list of repositories from urls.txt and a list of repositories which exist under a group, this method forks each repository in urls.txt to GitLab if it does not exist. If it does exist, it overwrites it if overwriteRepos in Jenkins was set to true
repos
- A list of public repositories to forkexistingProjectsInGroup
- A list of all the repositories that already exist in a given GitLab namespacegroupNamespaceId
- The id of the group which is needed for API requests on that groupworkspace
- The current workspacenamespace
- The GitLab group namespaceoverwriteRepos
- true if the box overwriteRepos in Jenkins was ticked, false otherwiseGiven a list of repository names and a target repository name, it checks that the list contains the target repository name
List
- of Repositoriesthe
- repository name to be searched for in the listReturns a closure representation of the SCM provider's trigger SCM section for Jenkins DSL. This particular SCM provider only requires a branch name as manual configuration is needed on the repository's side to integrate it with the desired Jenkins job via a webhook
projectName
- project name.repoName
- repository name.branchName
- branch name to trigger.Checks that urls.txt exists, is readable and non empty
urlsFile
- the file as an objecturlsFilePath
- the path to the fileValidates that all the fields required to create an object out of this class are not null or empty
Validates a repository clone URL by checking the protocol against the GitLabSCM protocol enum (SSH is not allowed at the moment)
Repository
- nameGiven a list of repositories, this method validates each of them by calling the validate method
A
- list of repositories to validateValidates the response of an HTTP request to search for a group. Makes sure that only one group was returned
response
- a list of JSON objects after parsing the response to the REST requestnamespace
- The group namespace (common namespace for a collection of repositories e.g /namespace/repo1, /namespace/repo2