org.kohsuke.github.GHCommitState Java Examples
The following examples show how to use
org.kohsuke.github.GHCommitState.
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: AbstractGitHubStatusAction.java From bamboo-github-status with MIT License | 6 votes |
void updateStatus(GHCommitState status, StageExecution stageExecution) { ChainExecution chainExecution = stageExecution.getChainExecution(); PlanResultKey planResultKey = chainExecution.getPlanResultKey(); PlanKey planKey = planResultKey.getPlanKey(); ImmutableChain chain = (ImmutableChain) planManager.getPlanByKey(planKey); for (RepositoryDefinition repo : Configuration.ghReposFrom(chain)) { if (shouldUpdateRepo(chain, repo)) { String sha = chainExecution.getBuildChanges().getVcsRevisionKey(repo.getId()); if (sha != null) { GitHubRepository ghRepo = (GitHubRepository) repo.getRepository(); setStatus(ghRepo, status, sha, planResultKey.getKey(), stageExecution.getName()); } } } }
Example #2
Source File: GitHubNotificationContext.java From github-branch-source-plugin with MIT License | 6 votes |
/** * 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 #3
Source File: JobHelper.java From github-integration-plugin with MIT License | 5 votes |
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 #4
Source File: GitHubNotificationRequest.java From github-branch-source-plugin with MIT License | 5 votes |
/** * @since 2.3.2 */ private GitHubNotificationRequest(String context, String url, String message, GHCommitState state, boolean ignoreError) { this.context = context; this.url = url; this.message = message; this.state = state; this.ignoreError = ignoreError; }
Example #5
Source File: GitHubProvider.java From gocd-build-status-notifier with Apache License 2.0 | 5 votes |
@Override public void updateStatus(String url, PluginSettings pluginSettings, String prIdStr, String revision, String pipelineStage, String result, String trackbackURL) throws Exception { LOGGER.info("Updating status for '%s' to %s", url, result); String repository = getRepository(url); GHCommitState state = getState(result); String endPointToUse = pluginSettings.getEndPoint(); String usernameToUse = pluginSettings.getUsername(); String passwordToUse = pluginSettings.getPassword(); String oauthAccessTokenToUse = pluginSettings.getOauthToken(); if (StringUtils.isEmpty(endPointToUse)) { endPointToUse = System.getProperty("go.plugin.build.status.github.endpoint"); } if (StringUtils.isEmpty(usernameToUse)) { usernameToUse = System.getProperty("go.plugin.build.status.github.username"); } if (StringUtils.isEmpty(passwordToUse)) { passwordToUse = System.getProperty("go.plugin.build.status.github.password"); } if (StringUtils.isEmpty(oauthAccessTokenToUse)) { oauthAccessTokenToUse = System.getProperty("go.plugin.build.status.github.oauth"); } updateCommitStatus(revision, pipelineStage, trackbackURL, repository, state, usernameToUse, passwordToUse, oauthAccessTokenToUse, endPointToUse); }
Example #6
Source File: GitHubProvider.java From gocd-build-status-notifier with Apache License 2.0 | 5 votes |
void updateCommitStatus(String revision, String pipelineStage, String trackbackURL, String repository, GHCommitState state, String usernameToUse, String passwordToUse, String oauthAccessTokenToUse, String endPointToUse) throws Exception { LOGGER.info("Updating commit status for '%s' on '%s'", revision, pipelineStage); GitHub github = createGitHubClient(usernameToUse, passwordToUse, oauthAccessTokenToUse, endPointToUse); GHRepository ghRepository = github.getRepository(repository); ghRepository.createCommitStatus(revision, state, trackbackURL, "", pipelineStage); }
Example #7
Source File: GitHubProvider.java From gocd-build-status-notifier with Apache License 2.0 | 5 votes |
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 #8
Source File: GitHubProviderTest.java From gocd-build-status-notifier with Apache License 2.0 | 5 votes |
@Test public void shouldGetStateFromResult() { assertThat(provider.getState("Unknown"), is(GHCommitState.PENDING)); assertThat(provider.getState("Passed"), is(GHCommitState.SUCCESS)); assertThat(provider.getState("Failed"), is(GHCommitState.FAILURE)); assertThat(provider.getState("Cancelled"), is(GHCommitState.ERROR)); }
Example #9
Source File: GitHubPRBuildStatusPublisher.java From github-integration-plugin with MIT License | 5 votes |
@DataBoundConstructor public GitHubPRBuildStatusPublisher(GitHubPRMessage statusMsg, GHCommitState unstableAs, BuildMessage buildMessage, StatusVerifier statusVerifier, PublisherErrorHandler errorHandler) { super(statusVerifier, errorHandler); if (statusMsg != null && isNotEmpty(statusMsg.getContent())) { this.statusMsg = statusMsg; } this.unstableAs = unstableAs; this.buildMessage = buildMessage; }
Example #10
Source File: BuildStatusActionTest.java From github-autostatus-plugin with MIT License | 5 votes |
/** * Verifies addBuildStatus calls createCommitStatus with a status of pending * * @throws java.io.IOException */ @Test public void testAddBuildStatusGitHub() throws IOException { BuildStatusAction instance = new BuildStatusAction(mockRun, targetUrl, new ArrayList<>()); instance.addBuildStatus(stageName); verify(repository).createCommitStatus(sha, GHCommitState.PENDING, targetUrl, "Building stage", stageName); }
Example #11
Source File: GitHubPRStatusBuilder.java From github-integration-plugin with MIT License | 5 votes |
@Override public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace, @Nonnull Launcher launcher, @Nonnull TaskListener listener) throws InterruptedException, IOException { // No triggers in Run class, but we need it final GitHubPRTrigger trigger = ghPRTriggerFromRun(run); if (isNull(trigger)) { // silently skip. TODO implement error handler, like in publishers return; } GitHubPRCause cause = ghPRCauseFromRun(run); if (isNull(cause)) { return; } // GitHub status for commit try { if (nonNull(statusMessage)) { String url = trigger.getDescriptor().getJenkinsURL() + run.getUrl(); trigger.getRemoteRepository().createCommitStatus( cause.getHeadSha(), GHCommitState.PENDING, url, statusMessage.expandAll(run, listener), run.getParent().getFullName() ); } } catch (Exception e) { listener.getLogger().println("Can't update build description"); LOGGER.error("Can't set commit status", e); } }
Example #12
Source File: JobRunnerForBranchCause.java From github-integration-plugin with MIT License | 5 votes |
@Override public boolean apply(GitHubBranchCause cause) { try { cause.setPollingLogFile(trigger.getPollingLogAction().getPollingLogFile()); StringBuilder sb = new StringBuilder(); sb.append("Jenkins queued the run (").append(cause.getReason()).append(")"); if (trigger.isCancelQueued() && cancelQueuedBuildByBranchName(cause.getBranchName())) { sb.append(". Queued builds aborted"); } QueueTaskFuture<?> queueTaskFuture = startJob(cause); if (isNull(queueTaskFuture)) { LOGGER.error("{} job didn't start", job.getFullName()); } LOGGER.info(sb.toString()); // remote connection if (trigger.isPreStatus()) { trigger.getRemoteRepository() .createCommitStatus(cause.getCommitSha(), GHCommitState.PENDING, null, sb.toString(), job.getFullName()); } } catch (IOException e) { LOGGER.error("Can't trigger build ({})", e.getMessage(), e); return false; } return true; }
Example #13
Source File: WorkflowITest.java From github-integration-plugin with MIT License | 5 votes |
@Test public void testContextStatuses() throws Exception { final WorkflowJob workflowJob = jRule.jenkins.createProject(WorkflowJob.class, "testContextStatuses"); workflowJob.addProperty(getPreconfiguredProperty(ghRule.getGhRepo())); workflowJob.addTrigger(getPreconfiguredPRTrigger()); workflowJob.setDefinition( new CpsFlowDefinition(classpath(this.getClass(), "testContextStatuses.groovy"), false) ); workflowJob.save(); basicTest(workflowJob); GHPullRequest pullRequest = ghRule.getGhRepo().getPullRequest(1); assertThat(pullRequest, notNullValue()); WorkflowRun lastBuild = workflowJob.getLastBuild(); assertThat(lastBuild, notNullValue()); GitHubPRCause cause = lastBuild.getCause(GitHubPRCause.class); assertThat(cause, notNullValue()); List<GHCommitStatus> statuses = pullRequest.getRepository() .listCommitStatuses(cause.getHeadSha()) .asList(); assertThat(statuses, hasSize(7)); // final statuses assertThat("workflow Run.getResult() strange", statuses, hasItem(commitStatus("testContextStatuses", GHCommitState.ERROR, "Run #2 ended normally")) ); assertThat(statuses, hasItem(commitStatus("custom-context1", GHCommitState.SUCCESS, "Tests passed"))); assertThat(statuses, hasItem(commitStatus("custom-context2", GHCommitState.SUCCESS, "Tests passed"))); }
Example #14
Source File: CommitStatusMatcher.java From github-integration-plugin with MIT License | 5 votes |
public CommitStatusMatcher(Matcher<? super Boolean> subMatcher, String context, GHCommitState state, String description) { super(subMatcher, "", ""); this.context = context; this.state = state; this.description = description; }
Example #15
Source File: CommitStatusUpdateRunListener.java From DotCi with MIT License | 5 votes |
@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 #16
Source File: CommitStatusUpdateQueueListener.java From DotCi with MIT License | 5 votes |
private void setCommitStatus(final BuildCause cause, final DynamicProject project) { final BuildCause buildCause = cause; final String sha = buildCause.getSha(); if (sha != null) { final GHRepository githubRepository = getGithubRepository(project); final String context = buildCause.getPullRequestNumber() != null ? "DotCi/PR" : "DotCi/push"; try { githubRepository.createCommitStatus(sha, GHCommitState.PENDING, getJenkinsRootUrl(), "Build in queue.", context); } catch (final IOException e) { LOGGER.log(Level.WARNING, "Failed to Update commit status", e); } } }
Example #17
Source File: CommitStatusUpdateQueueListenerTest.java From DotCi with MIT License | 5 votes |
@Test public void should_set_building_status_on_queue_enter() throws IOException { final GHRepository githubRepository = mock(GHRepository.class); final CommitStatusUpdateQueueListener commitStatusUpdateQueueListener = new CommitStatusUpdateQueueListener() { @Override protected GHRepository getGithubRepository(final DynamicProject project) { return githubRepository; } @Override protected String getJenkinsRootUrl() { return "jenkins.root.url"; } }; final BuildCause buildCause = mock(BuildCause.class); final ArrayList<Action> causeActions = new ArrayList<>(); causeActions.add(new CauseAction(buildCause)); final Queue.WaitingItem queueItem = new Queue.WaitingItem(null, mock(DynamicProject.class), causeActions); when(buildCause.getSha()).thenReturn("sha"); commitStatusUpdateQueueListener.onEnterWaiting(queueItem); verify(githubRepository).createCommitStatus("sha", GHCommitState.PENDING, "jenkins.root.url", "Build in queue.", "DotCi/push"); }
Example #18
Source File: CommitStatusUpdateRunListenerTest.java From DotCi with MIT License | 5 votes |
@Test public void should_set_building_status_on_commit() throws IOException { final DynamicBuild build = newBuild().get(); this.commitStatusUpdateRunListener.onInitialize(build); verify(this.githubRepository).createCommitStatus(build.getSha(), GHCommitState.PENDING, build.getFullUrl(), "Build in progress", "DotCi/push"); }
Example #19
Source File: GitHubStatusPostStage.java From bamboo-github-status with MIT License | 5 votes |
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 #20
Source File: GitHubStatusNotificationStep.java From pipeline-githubnotify-step-plugin with MIT License | 5 votes |
public ListBoxModel doFillStatusItems() { ListBoxModel list = new ListBoxModel(); for (GHCommitState state : GHCommitState.values()) { list.add(state.name(), state.name()); } return list; }
Example #21
Source File: BuildStatusActionTest.java From github-autostatus-plugin with MIT License | 5 votes |
/** * Verifies status is sent for initial stages when notifier is added * * @throws java.io.IOException */ @Test public void testInitialStage() throws IOException { List<BuildStage> model = new ArrayList<BuildStage>(); model.add(new BuildStage(stageName)); BuildStatusAction instance = new BuildStatusAction(mockRun, targetUrl, model); verify(repository).createCommitStatus(sha, GHCommitState.PENDING, targetUrl, "Building stage", stageName); }
Example #22
Source File: BuildStatusActionTest.java From github-autostatus-plugin with MIT License | 5 votes |
/** * Verifies updating a stage with success sends the correct status * * @throws java.io.IOException */ @Test public void testStageSuccessGitHub() throws IOException { BuildStatusAction instance = new BuildStatusAction(mockRun, targetUrl, new ArrayList<>()); instance.addBuildStatus(stageName); instance.updateBuildStatusForStage(stageName, BuildStage.State.CompletedSuccess); verify(repository).createCommitStatus(sha, GHCommitState.PENDING, targetUrl, "Building stage", stageName); verify(repository).createCommitStatus(sha, GHCommitState.SUCCESS, targetUrl, "Stage built successfully", stageName); }
Example #23
Source File: BuildStatusActionTest.java From github-autostatus-plugin with MIT License | 5 votes |
/** * Verifies updating a stage with an error sends the correct status * * @throws java.io.IOException */ @Test public void testStageErrorGitHub() throws IOException { BuildStatusAction instance = new BuildStatusAction(mockRun, targetUrl, new ArrayList<>()); instance.addBuildStatus(stageName); instance.updateBuildStatusForStage(stageName, BuildStage.State.CompletedError); verify(repository).createCommitStatus(sha, GHCommitState.PENDING, targetUrl, "Building stage", stageName); verify(repository).createCommitStatus(sha, GHCommitState.ERROR, targetUrl, "Failed to build stage", stageName); }
Example #24
Source File: BuildStatusActionTest.java From github-autostatus-plugin with MIT License | 5 votes |
/** * Verifies pending status recorded before the notifier was added are sent * * @throws java.io.IOException */ @Test public void testSendUnsentPendingStages() throws IOException { BuildStatusAction instance = new BuildStatusAction(mockRun, targetUrl, new ArrayList<>()); instance.addBuildStatus(stageName); verify(repository).createCommitStatus(sha, GHCommitState.PENDING, targetUrl, "Building stage", stageName); }
Example #25
Source File: GithubConnector.java From apollo with Apache License 2.0 | 5 votes |
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 #26
Source File: BuildStatusActionTest.java From github-autostatus-plugin with MIT License | 5 votes |
/** * Verifies close sends updated status information for "pending" stages * * @throws java.io.IOException */ @Test public void testCloseUpdatesPendingStatuses() throws IOException { BuildStatusAction instance = new BuildStatusAction(mockRun, targetUrl, new ArrayList<>()); instance.addBuildStatus(stageName); instance.close(); verify(repository).createCommitStatus(sha, GHCommitState.SUCCESS, targetUrl, "Stage built successfully", stageName); }
Example #27
Source File: GithubBuildNotifierTest.java From github-autostatus-plugin with MIT License | 5 votes |
/** * Verifies notifier sends pending status * * @throws java.io.IOException */ @Test public void testSendPending() throws IOException { GithubBuildNotifier notifier = new GithubBuildNotifier(repository, sha, targetUrl); BuildStage stageItem = new BuildStage(stageName); notifier.notifyBuildStageStatus(jobName, stageItem); verify(repository).createCommitStatus(sha, GHCommitState.PENDING, targetUrl, "Building stage", stageName); }
Example #28
Source File: GithubBuildNotifierTest.java From github-autostatus-plugin with MIT License | 5 votes |
/** * Verifies notifier sends success status * * @throws java.io.IOException */ @Test public void testSendSuccess() throws IOException { GithubBuildNotifier notifier = new GithubBuildNotifier(repository, sha, targetUrl); BuildStage stageItem = new BuildStage(stageName); stageItem.setBuildState(BuildStage.State.CompletedSuccess); notifier.notifyBuildStageStatus(jobName, stageItem); verify(repository).createCommitStatus(sha, GHCommitState.SUCCESS, targetUrl, "Stage built successfully", stageName); }
Example #29
Source File: GithubBuildNotifierTest.java From github-autostatus-plugin with MIT License | 5 votes |
/** * Verifies notifier sends error status * * @throws java.io.IOException */ @Test public void testSendError() throws IOException { GithubBuildNotifier notifier = new GithubBuildNotifier(repository, sha, targetUrl); BuildStage stageItem = new BuildStage(stageName); stageItem.setBuildState(BuildStage.State.CompletedError); notifier.notifyBuildStageStatus(jobName, stageItem); verify(repository).createCommitStatus(sha, GHCommitState.ERROR, targetUrl, "Failed to build stage", stageName); }
Example #30
Source File: SetCommitStatusStep.java From github-integration-plugin with MIT License | 4 votes |
@DataBoundSetter public void setState(GHCommitState state) { this.state = state; }