Java Code Examples for org.kohsuke.stapler.StaplerRequest#hasParameter()

The following examples show how to use org.kohsuke.stapler.StaplerRequest#hasParameter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GitScm.java    From blueocean-plugin with MIT License 6 votes vote down vote up
protected StandardCredentials getCredentialForCurrentRequest() {
    final StaplerRequest request = getStaplerRequest();

    String credentialId = null;

    if (request.hasParameter("credentialId")) {
        credentialId = request.getParameter("credentialId");
    } else {
        if (!request.hasParameter("repositoryUrl")) {
            // No linked credential unless a specific repo
            return null;
        }

        String repositoryUrl = request.getParameter("repositoryUrl");
        credentialId = makeCredentialId(repositoryUrl);
    }

    if (credentialId == null) {
        return null;
    }

    return CredentialsUtils.findCredential(credentialId, StandardCredentials.class, new BlueOceanDomainRequirement());
}
 
Example 2
Source File: NonProductionGradeDatabaseWarningAdministrativeMonitor.java    From pipeline-maven-plugin with MIT License 5 votes vote down vote up
/**
 * Depending on whether the user said "yes" or "no", send him to the right place.
 */
@RequirePOST
public void doAct(StaplerRequest req, StaplerResponse rsp) throws IOException {
    if (req.hasParameter("no")) {
        disable(true);
        rsp.sendRedirect(req.getContextPath() + "/manage");
    } else {
        rsp.sendRedirect(req.getContextPath() + "/configureTools");
    }
}
 
Example 3
Source File: GitHubPRRepository.java    From github-integration-plugin with MIT License 5 votes vote down vote up
@Override
public FormValidation doBuild(StaplerRequest req) throws IOException {
    FormValidation result;

    try {
        if (!job.hasPermission(Item.BUILD)) {
            return FormValidation.error("Forbidden");
        }

        final String prNumberParam = "prNumber";
        int prId = 0;
        if (req.hasParameter(prNumberParam)) {
            prId = Integer.valueOf(req.getParameter(prNumberParam));
        }

        if (prId == 0 || !getPulls().containsKey(prId)) {
            return FormValidation.error("No branch to build");
        }

        final GitHubPRPullRequest localPR = getPulls().get(prId);
        final GitHubPRCause cause = new GitHubPRCause(localPR, null, this, false, "Manual run.");

        final JobRunnerForCause runner = new JobRunnerForCause(getJob(), ghPRTriggerFromJob(getJob()));
        final QueueTaskFuture<?> queueTaskFuture = runner.startJob(cause);

        if (nonNull(queueTaskFuture)) {
            result = FormValidation.ok("Build scheduled");
        } else {
            result = FormValidation.warning("Build not scheduled");
        }
    } catch (Exception e) {
        LOG.error("Can't start build", e.getMessage());
        result = FormValidation.error(e, "Can't start build: " + e.getMessage());
    }

    return result;
}
 
Example 4
Source File: GitHubPRRepository.java    From github-integration-plugin with MIT License 5 votes vote down vote up
@RequirePOST
public FormValidation doRebuild(StaplerRequest req) throws IOException {
    FormValidation result;

    try {
        if (!job.hasPermission(Item.BUILD)) {
            return FormValidation.error("Forbidden");
        }

        final String prNumberParam = "prNumber";
        int prId = 0;
        if (req.hasParameter(prNumberParam)) {
            prId = Integer.valueOf(req.getParameter(prNumberParam));
        }

        Map<Integer, List<Run<?, ?>>> builds = getAllPrBuilds();
        List<Run<?, ?>> prBuilds = builds.get(prId);
        if (prBuilds != null && !prBuilds.isEmpty()) {
            if (rebuild(prBuilds.get(0))) {
                result = FormValidation.ok("Rebuild scheduled");
            } else {
                result = FormValidation.warning("Rebuild not scheduled");
            }
        } else {
            result = FormValidation.warning("Build not found");
        }
    } catch (Exception e) {
        LOG.error("Can't start rebuild", e);
        result = FormValidation.error(e, "Can't start rebuild: " + e.getMessage());
    }
    return result;
}
 
Example 5
Source File: GitHubBranchRepository.java    From github-integration-plugin with MIT License 5 votes vote down vote up
@RequirePOST
public FormValidation doBuild(StaplerRequest req) throws IOException {
    FormValidation result;

    try {
        if (!job.hasPermission(Item.BUILD)) {
            return FormValidation.error("Forbidden");
        }

        final String param = "branchName";
        String branchName = null;
        if (req.hasParameter(param)) {
            branchName = req.getParameter(param);
        }
        if (isNull(branchName) || !getBranches().containsKey(branchName)) {
            return FormValidation.error("No branch to build");
        }

        final GitHubBranch localBranch = getBranches().get(branchName);
        final GitHubBranchCause cause = new GitHubBranchCause(localBranch, this, "Manual run.", false);
        final JobRunnerForBranchCause runner = new JobRunnerForBranchCause(getJob(),
                ghBranchTriggerFromJob(job));
        final QueueTaskFuture<?> queueTaskFuture = runner.startJob(cause);

        if (nonNull(queueTaskFuture)) {
            result = FormValidation.ok("Build scheduled");
        } else {
            result = FormValidation.warning("Build not scheduled");
        }
    } catch (Exception e) {
        LOG.error("Can't start build", e.getMessage());
        result = FormValidation.error(e, "Can't start build: " + e.getMessage());
    }

    return result;
}
 
Example 6
Source File: GitHubBranchRepository.java    From github-integration-plugin with MIT License 5 votes vote down vote up
@Override
@RequirePOST
public FormValidation doRebuild(StaplerRequest req) throws IOException {
    FormValidation result;

    try {
        if (!job.hasPermission(Item.BUILD)) {
            return FormValidation.error("Forbidden");
        }

        final String param = "branchName";
        String branchName = "";
        if (req.hasParameter(param)) {
            branchName = req.getParameter(param);
        }

        Map<String, List<Run<?, ?>>> allBuilds = getAllBranchBuilds();
        List<Run<?, ?>> branchBuilds = allBuilds.get(branchName);
        if (branchBuilds != null && !allBuilds.isEmpty()) {
            if (rebuild(branchBuilds.get(0))) {
                result = FormValidation.ok("Rebuild scheduled");
            } else {
                result = FormValidation.warning("Rebuild not scheduled");
            }
        } else {
            result = FormValidation.warning("Build not found");
        }
    } catch (Exception e) {
        LOG.error("Can't start rebuild", e.getMessage());
        result = FormValidation.error(e, "Can't start rebuild: " + e.getMessage());
    }
    return result;
}
 
Example 7
Source File: ActionResolver.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
private WebHookAction onGet(Job<?, ?> project, String restOfPath, StaplerRequest request) {
    Matcher commitMatcher = COMMIT_STATUS_PATTERN.matcher(restOfPath);
    if (restOfPath.isEmpty() && request.hasParameter("ref")) {
        return new BranchBuildPageRedirectAction(project, request.getParameter("ref"));
    } else if (restOfPath.endsWith("status.png")) {
        return onGetStatusPng(project, request);
    } else if (commitMatcher.matches()) {
        return onGetCommitStatus(project, commitMatcher.group("sha1"), commitMatcher.group("statusJson"));
    }
    LOGGER.log(Level.FINE, "Unknown GET request: {0}", restOfPath);
    return new NoopAction();
}
 
Example 8
Source File: ActionResolver.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
private WebHookAction onGetStatusPng(Job<?, ?> project, StaplerRequest request) {
    if (request.hasParameter("ref")) {
        return new BranchStatusPngAction(project, request.getParameter("ref"));
    } else {
        return new CommitStatusPngAction(project, request.getParameter("sha1"));
    }
}