in jenkins-pipeline-shared-libraries/vars/githubscm.groovy [20:41]
def checkoutIfExists(String repository, String author, String branches, String defaultAuthor, String defaultBranches, boolean mergeTarget = false, def credentials = ['token': 'kie-ci1-token', 'usernamePassword': 'kie-ci']) {
assert credentials['token']
assert credentials['usernamePassword']
def sourceAuthor = author
def sourceRepository = getForkedProjectName(defaultAuthor, repository, sourceAuthor, credentials['token']) ?: repository
// Checks source group and branch (for cases where the branch has been created in the author's forked project)
def repositoryScm = getRepositoryScm(sourceRepository, author, branches, credentials['usernamePassword'])
if (repositoryScm == null) {
// Checks target group and and source branch (for cases where the branch has been created in the target project itself
repositoryScm = getRepositoryScm(repository, defaultAuthor, branches, credentials['usernamePassword'])
sourceAuthor = repositoryScm ? defaultAuthor : author
}
if (repositoryScm != null && (!mergeTarget || hasPullRequest(defaultAuthor, repository, author, branches, credentials['token']))) {
if (mergeTarget) {
mergeSourceIntoTarget(sourceRepository, sourceAuthor, branches, repository, defaultAuthor, defaultBranches, credentials['usernamePassword'])
} else {
checkout repositoryScm
}
} else {
checkout(resolveRepository(repository, defaultAuthor, defaultBranches, false, credentials['usernamePassword']))
}
}