Java Code Examples for org.kohsuke.github.GHCommitState#SUCCESS

The following examples show how to use org.kohsuke.github.GHCommitState#SUCCESS . 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: GitHubNotificationContext.java    From github-branch-source-plugin with MIT License 6 votes vote down vote up
/**
 * Retrieves default notification state
 * @param listener Listener for the build, if any
 * @return Default notification state
 * @since 2.3.2
 */
public GHCommitState getDefaultState(TaskListener listener) {
    if (null != build && !build.isBuilding()) {
        Result result = build.getResult();
        if (Result.SUCCESS.equals(result)) {
            return GHCommitState.SUCCESS;
        } else if (Result.UNSTABLE.equals(result)) {
            return GHCommitState.FAILURE;
        } else if (Result.FAILURE.equals(result)) {
            return GHCommitState.ERROR;
        } else if (Result.ABORTED.equals(result)) {
            return GHCommitState.ERROR;
        } else if (result != null) { // NOT_BUILT etc.
            return GHCommitState.ERROR;
        }
    }
    return GHCommitState.PENDING;
}
 
Example 2
Source File: GithubConnector.java    From apollo with Apache License 2.0 5 votes vote down vote up
public boolean isCommitStatusOK(String githubRepo, String sha) {
    Optional<CommitDetails> commit = getCommitDetails(githubRepo, sha);

    if (commit.isPresent()) {
        return commit.get().getCommitStatus().getState() == GHCommitState.SUCCESS;
    }

    return false;
}
 
Example 3
Source File: GitHubStatusPostStage.java    From bamboo-github-status with MIT License 5 votes vote down vote up
private static GHCommitState statusOf(StageExecution stageExecution) {
    if (stageExecution.isSuccessful()) {
        return GHCommitState.SUCCESS;
    } else if (Iterables.any(stageExecution.getBuilds(), new Predicate<BuildExecution>() {
        @Override
        public boolean apply(BuildExecution input) {
            return input.getBuildState() == BuildState.UNKNOWN;
        }
    })) {
        return GHCommitState.ERROR;
    } else {
        return GHCommitState.FAILURE;
    }
}
 
Example 4
Source File: GitHubProvider.java    From gocd-build-status-notifier with Apache License 2.0 5 votes vote down vote up
GHCommitState getState(String result) {
    result = result == null ? "" : result;
    GHCommitState state = GHCommitState.PENDING;
    if (result.equalsIgnoreCase("Passed")) {
        state = GHCommitState.SUCCESS;
    } else if (result.equalsIgnoreCase("Failed")) {
        state = GHCommitState.FAILURE;
    } else if (result.equalsIgnoreCase("Cancelled")) {
        state = GHCommitState.ERROR;
    }
    return state;
}
 
Example 5
Source File: JobHelper.java    From github-integration-plugin with MIT License 5 votes vote down vote up
public static GHCommitState getCommitState(final Run<?, ?> run, final GHCommitState unstableAs) {
    GHCommitState state;
    Result result = run.getResult();
    if (isNull(result)) {
        LOG.error("{} result is null.", run);
        state = GHCommitState.ERROR;
    } else if (result.isBetterOrEqualTo(SUCCESS)) {
        state = GHCommitState.SUCCESS;
    } else if (result.isBetterOrEqualTo(UNSTABLE)) {
        state = unstableAs;
    } else {
        state = GHCommitState.FAILURE;
    }
    return state;
}
 
Example 6
Source File: CommitStatusUpdateRunListener.java    From DotCi with MIT License 5 votes vote down vote up
@Override
public void onCompleted(final DynamicBuild build, final TaskListener listener) {
    final String sha1 = build.getSha();
    if (sha1 == null) {
        return;
    }

    final GHRepository repository = getGithubRepository(build);
    final GHCommitState state;
    String msg;
    final Result result = build.getResult();
    if (result.isBetterOrEqualTo(SUCCESS)) {
        state = GHCommitState.SUCCESS;
        msg = "Success";
    } else if (result.isBetterOrEqualTo(UNSTABLE)) {
        state = GHCommitState.FAILURE;
        msg = "Unstable";
    } else {
        state = GHCommitState.FAILURE;
        msg = "Failed";
    }
    if (build.isSkipped()) {
        msg += " - Skipped";
    }
    try {
        listener.getLogger().println("setting commit status on Github for " + repository.getHtmlUrl() + "/commit/" + sha1);
        repository.createCommitStatus(sha1, state, build.getFullUrl(), msg, getContext(build));
    } catch (final Exception e) {
        printErrorToBuildConsole(listener, e);
    }

}
 
Example 7
Source File: GitHubPRBuildStatusPublisher.java    From github-integration-plugin with MIT License 4 votes vote down vote up
@Override
public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace, @Nonnull Launcher launcher,
                    @Nonnull TaskListener listener) throws InterruptedException, IOException {
    PrintStream listenerLogger = listener.getLogger();
    String publishedURL = getTriggerDescriptor().getJenkinsURL();

    if (getStatusVerifier() != null && !getStatusVerifier().isRunAllowed(run)) {
        return;
    }

    if (isEmpty(publishedURL)) {
        return;
    }

    GHCommitState state = getCommitState(run, unstableAs);

    GitHubPRCause c = ghPRCauseFromRun(run);

    String statusMsgValue = getStatusMsg().expandAll(run, listener);
    String buildUrl = publishedURL + run.getUrl();

    LOGGER.info("Setting status of {} to {} with url {} and message: {}",
            c.getHeadSha(), state, buildUrl, statusMsgValue);

    // TODO check permissions to write human friendly message
    final GitHubPRTrigger trigger = ghPRTriggerFromRun(run);
    if (isNull(trigger)) {
        listener.error("Can't get trigger for this run! Silently skipping. " +
                "TODO implement error handler, like in publishers");
        return;
    }

    try {
        trigger.getRemoteRepository().createCommitStatus(c.getHeadSha(), state, buildUrl, statusMsgValue,
                run.getParent().getFullName());
    } catch (IOException ex) {
        if (nonNull(buildMessage)) {
            String comment = null;
            LOGGER.error("Could not update commit status of the Pull Request on GitHub. ", ex);
            if (state == GHCommitState.SUCCESS) {
                comment = buildMessage.getSuccessMsg().expandAll(run, listener);
            } else if (state == GHCommitState.FAILURE) {
                comment = buildMessage.getFailureMsg().expandAll(run, listener);
            }
            listenerLogger.println("Adding comment...");
            LOGGER.info("Adding comment, because: ", ex);
            addComment(c.getNumber(), comment, run, listener);
        } else {
            listenerLogger.println("Could not update commit status of the Pull Request on GitHub." + ex.getMessage());
            LOGGER.error("Could not update commit status of the Pull Request on GitHub.", ex);
        }
        handlePublisherError(run);
    }
}