Search in sources :

Example 1 with EventListener

use of com.atlassian.event.api.EventListener 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);
    }
}
Also used : Comment(com.atlassian.stash.comment.Comment) Repository(com.atlassian.stash.repository.Repository) SQLException(java.sql.SQLException) PullRequest(com.atlassian.stash.pull.PullRequest) RepositoryConfiguration(com.palantir.stash.stashbot.persistence.RepositoryConfiguration) EventListener(com.atlassian.event.api.EventListener)

Example 2 with EventListener

use of com.atlassian.event.api.EventListener 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);
    }
}
Also used : Repository(com.atlassian.stash.repository.Repository) SQLException(java.sql.SQLException) PullRequest(com.atlassian.stash.pull.PullRequest) RepositoryConfiguration(com.palantir.stash.stashbot.persistence.RepositoryConfiguration) EventListener(com.atlassian.event.api.EventListener)

Aggregations

EventListener (com.atlassian.event.api.EventListener)2 PullRequest (com.atlassian.stash.pull.PullRequest)2 Repository (com.atlassian.stash.repository.Repository)2 RepositoryConfiguration (com.palantir.stash.stashbot.persistence.RepositoryConfiguration)2 SQLException (java.sql.SQLException)2 Comment (com.atlassian.stash.comment.Comment)1