use of com.atlassian.stash.repository.RepositoryCloneLinksRequest in project stashbot by palantir.
the class StashbotUrlBuilder method buildCloneUrl.
public String buildCloneUrl(Repository repo, JenkinsServerConfiguration jsc) {
RepositoryCloneLinksRequest rclr = new RepositoryCloneLinksRequest.Builder().repository(repo).protocol("http").user(null).build();
String url = rs.getCloneLinks(rclr).iterator().next().getHref();
// we build without username because we insert username AND password, and need both, in the case where we are using USERNAME_AND_PASSWORD.
switch(jsc.getAuthenticationMode()) {
case USERNAME_AND_PASSWORD:
url = url.replace("://", "://" + mask(jsc.getStashUsername()) + ":" + mask(jsc.getStashPassword()) + "@");
break;
case CREDENTIAL_MANUALLY_CONFIGURED:
// XXX: do we need to get the git/ssh link instead of the http link here? maybe that's a new mode?
break;
default:
throw new IllegalStateException("Invalid value - update this code after adding an authentication mode");
}
return url;
}
use of com.atlassian.stash.repository.RepositoryCloneLinksRequest in project stashbot by palantir.
the class JenkinsJobXmlFormatter method generateJobXml.
public String generateJobXml(JobTemplate jobTemplate, Repository repo) throws SQLException {
final VelocityContext vc = velocityManager.getVelocityContext();
final RepositoryConfiguration rc = cpm.getRepositoryConfigurationForRepository(repo);
final JenkinsServerConfiguration jsc = cpm.getJenkinsServerConfiguration(rc.getJenkinsServerName());
RepositoryCloneLinksRequest rclr = new RepositoryCloneLinksRequest.Builder().repository(repo).protocol("http").user(null).build();
String repositoryUrl = rs.getCloneLinks(rclr).iterator().next().getHref();
String cleanRepositoryUrl = repositoryUrl;
// Handle the various Authentication modes
switch(jsc.getAuthenticationMode()) {
case USERNAME_AND_PASSWORD:
// manually insert the username and pw we are configured to use
repositoryUrl = repositoryUrl.replace("://", "://" + jsc.getStashUsername() + ":" + jsc.getStashPassword() + "@");
break;
case CREDENTIAL_MANUALLY_CONFIGURED:
vc.put("credentialUUID", jsc.getStashPassword());
break;
}
vc.put("repositoryUrl", repositoryUrl);
vc.put("cleanRepositoryUrl", cleanRepositoryUrl);
vc.put("prebuildCommand", prebuildCommand(rc.getPrebuildCommand()));
// TODO: figure out build command some other way?
switch(jobTemplate.getJobType()) {
case VERIFY_COMMIT:
vc.put("buildCommand", buildCommand(rc.getVerifyBuildCommand()));
break;
case VERIFY_PR:
vc.put("buildCommand", buildCommand(rc.getVerifyBuildCommand()));
break;
case PUBLISH:
vc.put("buildCommand", buildCommand(rc.getPublishBuildCommand()));
break;
case NOOP:
vc.put("buildCommand", buildCommand("/bin/true"));
break;
}
// Add email notification stuff for all build types
vc.put("isEmailNotificationsEnabled", rc.getEmailNotificationsEnabled());
vc.put("emailRecipients", rc.getEmailRecipients());
vc.put("isEmailForEveryUnstableBuild", rc.getEmailForEveryUnstableBuild());
vc.put("isEmailSendToIndividuals", rc.getEmailSendToIndividuals());
vc.put("isEmailPerModuleEmail", rc.getEmailPerModuleEmail());
vc.put("startedCommand", curlCommandBuilder(repo, jobTemplate, rc, repositoryUrl, "inprogress"));
vc.put("successCommand", curlCommandBuilder(repo, jobTemplate, rc, repositoryUrl, "successful"));
vc.put("failedCommand", curlCommandBuilder(repo, jobTemplate, rc, repositoryUrl, "failed"));
vc.put("repositoryLink", navBuilder.repo(repo).browse().buildAbsolute());
vc.put("repositoryName", repo.getProject().getName() + " " + repo.getName());
// Parameters are type-dependent for now
ImmutableList.Builder<Map<String, String>> paramBuilder = new ImmutableList.Builder<Map<String, String>>();
switch(jobTemplate.getJobType()) {
case VERIFY_COMMIT:
// repoId
paramBuilder.add(ImmutableMap.of("name", "repoId", "typeName", JenkinsBuildParamType.StringParameterDefinition.toString(), "description", "stash repository Id", "defaultValue", "unknown"));
// buildHead
paramBuilder.add(ImmutableMap.of("name", "buildHead", "typeName", JenkinsBuildParamType.StringParameterDefinition.toString(), "description", "the change to build", "defaultValue", "head"));
break;
case VERIFY_PR:
// repoId
paramBuilder.add(ImmutableMap.of("name", "repoId", "typeName", JenkinsBuildParamType.StringParameterDefinition.toString(), "description", "stash repository Id", "defaultValue", "unknown"));
// buildHead
paramBuilder.add(ImmutableMap.of("name", "buildHead", "typeName", JenkinsBuildParamType.StringParameterDefinition.toString(), "description", "the change to build", "defaultValue", "head"));
// pullRequestId
paramBuilder.add(ImmutableMap.of("name", "pullRequestId", "typeName", JenkinsBuildParamType.StringParameterDefinition.toString(), "description", "the pull request Id", "defaultValue", ""));
break;
case PUBLISH:
// repoId
paramBuilder.add(ImmutableMap.of("name", "repoId", "typeName", JenkinsBuildParamType.StringParameterDefinition.toString(), "description", "stash repository Id", "defaultValue", "unknown"));
// buildHead
paramBuilder.add(ImmutableMap.of("name", "buildHead", "typeName", JenkinsBuildParamType.StringParameterDefinition.toString(), "description", "the change to build", "defaultValue", "head"));
break;
case NOOP:
// no params
break;
}
vc.put("paramaterList", paramBuilder.build());
// Junit settings
vc.put("isJunit", rc.getJunitEnabled());
vc.put("junitPath", rc.getJunitPath());
// Artifact settings
vc.put("artifactsEnabled", rc.getArtifactsEnabled());
vc.put("artifactsPath", rc.getArtifactsPath());
// insert pinned data
switch(jobTemplate.getJobType()) {
case VERIFY_COMMIT:
case VERIFY_PR:
vc.put("isPinned", rc.getVerifyPinned());
vc.put("label", rc.getVerifyLabel());
break;
case PUBLISH:
vc.put("isPinned", rc.getPublishPinned());
vc.put("label", rc.getPublishLabel());
break;
case NOOP:
vc.put("isPinned", false);
break;
}
StringWriter xml = new StringWriter();
VelocityEngine ve = velocityManager.getVelocityEngine();
Template template = ve.getTemplate(jobTemplate.getTemplateFile());
template.merge(vc, xml);
return xml.toString();
}
Aggregations