Search in sources :

Example 1 with DBParam

use of net.java.ao.DBParam in project stashbot by palantir.

the class ConfigurationPersistenceImpl method getPullRequestMetadataWithoutToRef.

/* (non-Javadoc)
     * @see com.palantir.stash.stashbot.config.ConfigurationPersistenceService#getPullRequestMetadataWithoutToRef(com.atlassian.stash.pull.PullRequest)
     */
@Override
public ImmutableList<PullRequestMetadata> getPullRequestMetadataWithoutToRef(PullRequest pr) {
    Long id = pr.getId();
    String fromSha = pr.getFromRef().getLatestChangeset().toString();
    String toSha = pr.getToRef().getLatestChangeset().toString();
    PullRequestMetadata[] prms = ao.find(PullRequestMetadata.class, "PULL_REQUEST_ID = ? and FROM_SHA = ?", id, fromSha);
    if (prms.length == 0) {
        // new/updated PR, create a new object
        log.info("Creating PR Metadata for pull request: " + pullRequestToString(pr));
        PullRequestMetadata prm = ao.create(PullRequestMetadata.class, new DBParam("PULL_REQUEST_ID", id), new DBParam("TO_SHA", toSha), new DBParam("FROM_SHA", fromSha));
        prm.save();
        return ImmutableList.of(prm);
    }
    return ImmutableList.copyOf(prms);
}
Also used : DBParam(net.java.ao.DBParam) PullRequestMetadata(com.palantir.stash.stashbot.persistence.PullRequestMetadata)

Example 2 with DBParam

use of net.java.ao.DBParam in project stashbot by palantir.

the class ConfigurationPersistenceImpl method setJenkinsServerConfiguration.

/* (non-Javadoc)
     * @see com.palantir.stash.stashbot.config.ConfigurationPersistenceService#setJenkinsServerConfiguration(java.lang.String, java.lang.String, java.lang.String, java.lang.String, com.palantir.stash.stashbot.config.JenkinsServerConfiguration.AuthenticationMode, java.lang.String, java.lang.String, java.lang.Integer, java.lang.Boolean)
     */
@Override
public void setJenkinsServerConfiguration(String name, String url, String username, String password, AuthenticationMode authenticationMode, String stashUsername, String stashPassword, Integer maxVerifyChain, Boolean isLocked) throws SQLException {
    if (name == null) {
        name = DEFAULT_JENKINS_SERVER_CONFIG_KEY;
    }
    validateName(name);
    JenkinsServerConfiguration[] configs = ao.find(JenkinsServerConfiguration.class, Query.select().where("NAME = ?", name));
    if (configs.length == 0) {
        log.info("Creating jenkins configuration: " + name);
        ao.create(JenkinsServerConfiguration.class, new DBParam("NAME", name), new DBParam("URL", url), new DBParam("USERNAME", username), new DBParam("PASSWORD", password), new DBParam("STASH_USERNAME", stashUsername), new DBParam("STASH_PASSWORD", stashPassword), new DBParam("MAX_VERIFY_CHAIN", maxVerifyChain), new DBParam("LOCKED", isLocked));
        return;
    }
    // already exists, so update it
    configs[0].setName(name);
    configs[0].setUrl(url);
    configs[0].setUsername(username);
    configs[0].setPassword(password);
    configs[0].setAuthenticationMode(authenticationMode);
    configs[0].setStashUsername(stashUsername);
    configs[0].setStashPassword(stashPassword);
    configs[0].setMaxVerifyChain(maxVerifyChain);
    configs[0].setLocked(isLocked);
    configs[0].save();
}
Also used : DBParam(net.java.ao.DBParam) JenkinsServerConfiguration(com.palantir.stash.stashbot.persistence.JenkinsServerConfiguration)

Example 3 with DBParam

use of net.java.ao.DBParam in project stashbot by palantir.

the class JobTemplateManager method getDefaultVerifyPullRequestJob.

public JobTemplate getDefaultVerifyPullRequestJob() {
    JobTemplate[] jobs = ao.find(JobTemplate.class, Query.select().where("NAME = ?", DEFAULT_VERIFY_PR_JOB_NAME));
    if (jobs.length == 1) {
        return jobs[0];
    }
    // Create the default verify job
    JobTemplate jjt = ao.create(JobTemplate.class, new DBParam("NAME", DEFAULT_VERIFY_PR_JOB_NAME), new DBParam("TEMPLATE_FILE", DEFAULT_VERIFY_PR_JOB_FILE), new DBParam("JOB_TYPE", JobType.VERIFY_PR));
    jjt.save();
    return jjt;
}
Also used : DBParam(net.java.ao.DBParam) JobTemplate(com.palantir.stash.stashbot.persistence.JobTemplate)

Example 4 with DBParam

use of net.java.ao.DBParam in project stashbot by palantir.

the class ConfigurationPersistenceImpl method getRepositoryConfigurationForRepository.

/* (non-Javadoc)
     * @see com.palantir.stash.stashbot.config.ConfigurationPersistenceService#getRepositoryConfigurationForRepository(com.atlassian.stash.repository.Repository)
     */
@Override
public RepositoryConfiguration getRepositoryConfigurationForRepository(Repository repo) throws SQLException {
    RepositoryConfiguration[] repos = ao.find(RepositoryConfiguration.class, Query.select().where("REPO_ID = ?", repo.getId()));
    if (repos.length == 0) {
        // just use the defaults
        RepositoryConfiguration rc = ao.create(RepositoryConfiguration.class, new DBParam("REPO_ID", repo.getId()));
        rc.save();
        // default the 3 base job types to enabled
        setJobTypeStatusMapping(rc, JobType.VERIFY_COMMIT, true);
        setJobTypeStatusMapping(rc, JobType.VERIFY_PR, true);
        setJobTypeStatusMapping(rc, JobType.PUBLISH, true);
        return rc;
    }
    return repos[0];
}
Also used : DBParam(net.java.ao.DBParam) RepositoryConfiguration(com.palantir.stash.stashbot.persistence.RepositoryConfiguration)

Example 5 with DBParam

use of net.java.ao.DBParam in project stashbot by palantir.

the class ConfigurationPersistenceImpl method getPullRequestMetadata.

/* (non-Javadoc)
     * @see com.palantir.stash.stashbot.config.ConfigurationPersistenceService#getPullRequestMetadata(int, java.lang.Long, java.lang.String, java.lang.String)
     */
@Override
public PullRequestMetadata getPullRequestMetadata(int repoId, Long prId, String fromSha, String toSha) {
    // We have to check repoId being equal to -1 so that this works with old data.
    PullRequestMetadata[] prms = ao.find(PullRequestMetadata.class, "(REPO_ID = ? OR REPO_ID = -1) AND PULL_REQUEST_ID = ? and TO_SHA = ? and FROM_SHA = ?", repoId, prId, toSha, fromSha);
    if (prms.length == 0) {
        // new/updated PR, create a new object
        log.info("Creating PR Metadata for pull request: repo id:" + repoId + "pr id: " + prId + ", fromSha: " + fromSha + ", toSha: " + toSha);
        PullRequestMetadata prm = ao.create(PullRequestMetadata.class, new DBParam("REPO_ID", repoId), new DBParam("PULL_REQUEST_ID", prId), new DBParam("TO_SHA", toSha), new DBParam("FROM_SHA", fromSha));
        prm.save();
        return prm;
    }
    return prms[0];
}
Also used : DBParam(net.java.ao.DBParam) PullRequestMetadata(com.palantir.stash.stashbot.persistence.PullRequestMetadata)

Aggregations

DBParam (net.java.ao.DBParam)16 JobTemplate (com.palantir.stash.stashbot.persistence.JobTemplate)4 JenkinsServerConfiguration (com.palantir.stash.stashbot.persistence.JenkinsServerConfiguration)3 RepositoryConfiguration (com.palantir.stash.stashbot.persistence.RepositoryConfiguration)3 PullRequestMetadata (com.palantir.stash.stashbot.persistence.PullRequestMetadata)2 SearchUpdater (com.palantir.stash.codesearch.updater.SearchUpdater)1 JobType (com.palantir.stash.stashbot.jobtemplate.JobType)1 JobMapping (com.palantir.stash.stashbot.persistence.JobMapping)1 Test (org.junit.Test)1