use of com.atlassian.stash.repository.Repository in project stashbot by palantir.
the class RepoConfigurationServlet method doGet.
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
Repository rep = getRepository(req);
if (rep == null) {
res.sendError(404);
return;
}
try {
permissionValidationService.validateForRepository(rep, Permission.REPO_ADMIN);
} catch (AuthorisationException notRepoAdmin) {
log.warn("User {} tried to access the stashbot admin page for {}", req.getRemoteUser(), rep.getSlug());
res.sendError(HttpServletResponse.SC_UNAUTHORIZED, "You do not have permission to access this page.");
return;
}
RepositoryConfiguration rc;
JenkinsServerConfiguration theJsc;
try {
rc = configurationPersistanceManager.getRepositoryConfigurationForRepository(rep);
theJsc = configurationPersistanceManager.getJenkinsServerConfiguration(rc.getJenkinsServerName());
} catch (SQLException e1) {
throw new ServletException(e1);
}
res.setContentType("text/html;charset=UTF-8");
try {
List<Map<String, String>> jenkinsServersData = new ArrayList<Map<String, String>>();
for (JenkinsServerConfiguration jsc : configurationPersistanceManager.getAllJenkinsServerConfigurations()) {
HashMap<String, String> m = new HashMap<String, String>();
m.put("text", jsc.getName());
m.put("value", jsc.getName());
if (rc.getJenkinsServerName().equals(jsc.getName())) {
m.put("selected", "true");
}
jenkinsServersData.add(m);
}
pageBuilderService.assembler().resources().requireContext("plugin.page.stashbot");
pageBuilderService.assembler().resources().requireWebResource("com.palantir.stash.stashbot:stashbot-resources");
soyTemplateRenderer.render(res.getWriter(), "com.palantir.stash.stashbot:stashbotConfigurationResources", "plugin.page.stashbot.repositoryConfigurationPanel", ImmutableMap.<String, Object>builder().put("repository", rep).put("ciEnabled", rc.getCiEnabled()).put("publishBranchRegex", rc.getPublishBranchRegex()).put("publishBuildCommand", rc.getPublishBuildCommand()).put("verifyBranchRegex", rc.getVerifyBranchRegex()).put("verifyBuildCommand", rc.getVerifyBuildCommand()).put("prebuildCommand", rc.getPrebuildCommand()).put("jenkinsServerName", rc.getJenkinsServerName()).put("maxVerifyChain", rc.getMaxVerifyChain().toString()).put("rebuildOnUpdate", rc.getRebuildOnTargetUpdate()).put("isVerifyPinned", rc.getVerifyPinned()).put("verifyLabel", rc.getVerifyLabel()).put("isPublishPinned", rc.getPublishPinned()).put("publishLabel", rc.getPublishLabel()).put("isJunit", rc.getJunitEnabled()).put("junitPath", rc.getJunitPath()).put("artifactsEnabled", rc.getArtifactsEnabled()).put("artifactsPath", rc.getArtifactsPath()).put("jenkinsServersData", jenkinsServersData).put("isEmailNotificationsEnabled", rc.getEmailNotificationsEnabled()).put("isEmailForEveryUnstableBuild", rc.getEmailForEveryUnstableBuild()).put("isEmailPerModuleEmail", rc.getEmailPerModuleEmail()).put("emailRecipients", rc.getEmailRecipients()).put("isEmailSendToIndividuals", rc.getEmailSendToIndividuals()).put("isStrictVerifyMode", rc.getStrictVerifyMode()).put("isPreserveJenkinsJobConfig", rc.getPreserveJenkinsJobConfig()).put("isLocked", isLocked(theJsc)).put("verificationEnabled", configurationPersistanceManager.getJobTypeStatusMapping(rc, JobType.VERIFY_COMMIT)).put("verifyPREnabled", configurationPersistanceManager.getJobTypeStatusMapping(rc, JobType.VERIFY_PR)).put("publishEnabled", configurationPersistanceManager.getJobTypeStatusMapping(rc, JobType.PUBLISH)).build());
} catch (SoyException e) {
Throwable cause = e.getCause();
if (cause instanceof IOException) {
throw (IOException) cause;
} else {
throw new ServletException(e);
}
} catch (SQLException e) {
throw new ServletException(e);
}
}
use of com.atlassian.stash.repository.Repository in project stashbot by palantir.
the class IsCiEnabledForRepoCondition method shouldDisplay.
@Override
public boolean shouldDisplay(Map<String, Object> context) {
// request, principal, changeset, repository
Repository repo = (Repository) context.get("repository");
RepositoryConfiguration rc;
if (repo == null) {
return false;
}
try {
rc = cpm.getRepositoryConfigurationForRepository(repo);
} catch (SQLException e) {
rc = null;
log.error("Failed to get RepositoryConfiguration for repo: " + repo.toString(), e);
}
if (rc != null && rc.getCiEnabled()) {
return true;
}
return false;
}
use of com.atlassian.stash.repository.Repository in project stashbot by palantir.
the class ConfigurationTest method getsStoredRepoData.
@Test
public void getsStoredRepoData() throws Exception {
Repository repo = Mockito.mock(Repository.class);
Mockito.when(repo.getId()).thenReturn(10);
RepositoryConfiguration rc = cpm.getRepositoryConfigurationForRepository(repo);
Assert.assertEquals("publishBranchRegex", rc.getPublishBranchRegex());
Assert.assertEquals("publishBuildCommand", rc.getPublishBuildCommand());
Assert.assertEquals("verifyBranchRegex", rc.getVerifyBranchRegex());
Assert.assertEquals("verifyBuildCommand", rc.getVerifyBuildCommand());
Assert.assertTrue(rc.getCiEnabled());
Assert.assertFalse(rc.getPreserveJenkinsJobConfig());
}
use of com.atlassian.stash.repository.Repository in project stashbot by palantir.
the class PullRequestListener method listenForComments.
@EventListener
public void listenForComments(PullRequestCommentEvent event) {
try {
final PullRequest pr = event.getPullRequest();
final Repository repo = pr.getToRef().getRepository();
final RepositoryConfiguration rc = cpm.getRepositoryConfigurationForRepository(repo);
if (!rc.getCiEnabled()) {
log.debug("Pull Request " + pr.toString() + " ignored, CI not enabled for target repo " + repo.toString());
return;
}
Comment c = event.getComment();
if (c.getText().contains(OVERRIDE_STRING)) {
log.debug("Pull Request override set to true for PR " + pr.toString());
cpm.setPullRequestMetadata(pr, null, null, true);
}
} catch (SQLException e) {
log.error("Error getting repository configuration", e);
}
}
use of com.atlassian.stash.repository.Repository in project stashbot by palantir.
the class PullRequestListener method listenForMerged.
// This event signifies that the PR has already been merged, we don't need to worry about VERIFY_PR anymore, only VERIFY_COMMIT or PUBLISH.
@EventListener
public void listenForMerged(PullRequestMergedEvent event) {
try {
final PullRequest pr = event.getPullRequest();
final Repository repo = pr.getToRef().getRepository();
final RepositoryConfiguration rc = cpm.getRepositoryConfigurationForRepository(repo);
if (!rc.getCiEnabled()) {
log.debug("Pull Request " + pr.toString() + " ignored, CI not enabled for target repo " + repo.toString());
return;
}
// just trigger a build of the new commit since the other hook doesn't catch merged PRs.
String mergeSha1 = event.getChangeset().getId();
String targetBranch = pr.getToRef().getId();
boolean publishEnabled = cpm.getJobTypeStatusMapping(rc, JobType.PUBLISH);
boolean verifyEnabled = cpm.getJobTypeStatusMapping(rc, JobType.VERIFY_COMMIT);
if (publishEnabled && targetBranch.matches(rc.getPublishBranchRegex())) {
log.info("Stashbot Trigger: Triggering PUBLISH build for commit " + mergeSha1 + " after merge of branch " + targetBranch);
jenkinsManager.triggerBuild(repo, JobType.PUBLISH, mergeSha1, targetBranch);
} else if (verifyEnabled && targetBranch.matches(rc.getVerifyBranchRegex())) {
// TODO: Build any commits which are new, for now just build latest commit
// Do this by doing a revwalk just like in TriggerJenkinsBuildHook, excluding the build we just published.
log.info("Stashbot Trigger: Triggering VERIFICATION build for commit " + mergeSha1 + " after merge of branch " + targetBranch);
jenkinsManager.triggerBuild(repo, JobType.VERIFY_COMMIT, mergeSha1, targetBranch);
}
return;
} catch (SQLException e) {
log.error("Error getting repository configuration", e);
}
}
Aggregations