org.kohsuke.github.GHCommitStatus Java Examples

The following examples show how to use org.kohsuke.github.GHCommitStatus. 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: CommitHistoryViewTest.java    From DotCi with MIT License 6 votes vote down vote up
@Test
public void should_group_commit_statueses_by_context() throws IOException {
    final CommitHistoryView commitHistoryView = new CommitHistoryView();
    final DynamicBuild build = mock(DynamicBuild.class);
    final GHRepository githubRepo = mock(GHRepository.class);
    when(build.getGithubRepository()).thenReturn(githubRepo);

    final PagedIterable<GHCommitStatus> commitStatusesList = mock(PagedIterable.class);
    final GHCommitStatus commitStatus1 = mock(GHCommitStatus.class);
    final GHCommitStatus commitStatus2 = mock(GHCommitStatus.class);

    when(commitStatus1.getContext()).thenReturn("Default");
    when(commitStatus2.getContext()).thenReturn("DotCi");

    when(commitStatusesList.asList()).thenReturn(Arrays.asList(commitStatus1, commitStatus2));
    final GHCommit currentCommit = mock(GHCommit.class);
    when(githubRepo.getCommit(null)).thenReturn(currentCommit);
    when(currentCommit.listStatuses()).thenReturn(commitStatusesList);
    when(githubRepo.getLastCommitStatus(null)).thenReturn(commitStatus1);
    commitHistoryView.onLoad(build);
    final Map<String, List<GHCommitStatus>> commitStatuses = commitHistoryView.getCommitStatuses();

    Assert.assertEquals(commitStatuses.get("Default").get(0), commitStatus1);
    Assert.assertEquals(commitStatuses.get("DotCi").get(0), commitStatus2);
}
 
Example #2
Source File: CommitDetails.java    From apollo with Apache License 2.0 5 votes vote down vote up
public CommitDetails(String sha, String commitUrl, String commitMessage, Date commitDate, GHCommitStatus commitStatus, String committerAvatarUrl, String committerName) {
    this.sha = sha;
    this.commitUrl = commitUrl;
    this.commitMessage = commitMessage;
    this.commitDate = commitDate;
    this.commitStatus = commitStatus;
    this.committerAvatarUrl = committerAvatarUrl;
    this.committerName = committerName;
}
 
Example #3
Source File: WorkflowITest.java    From github-integration-plugin with MIT License 5 votes vote down vote up
@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 #4
Source File: CommitHistoryView.java    From DotCi with MIT License 5 votes vote down vote up
public Map<String, List<GHCommitStatus>> getCommitStatuses() throws IOException {
    final GHRepository githubRepository = this.build.getGithubRepository();
    final List<GHCommitStatus> commitStatuses = githubRepository.getCommit(this.build.getSha()).listStatuses().asList();
    final Map<String, List<GHCommitStatus>> groupedStatuses = new HashMap<>();
    for (final GHCommitStatus status : commitStatuses) {
        final String context = status.getContext();
        if (groupedStatuses.get(context) == null) {
            groupedStatuses.put(context, new ArrayList<>());
        }
        groupedStatuses.get(context).add(status);
    }
    groupedStatuses.put("- Latest Status -", Arrays.asList(githubRepository.getLastCommitStatus(this.build.getSha())));
    return groupedStatuses;
}
 
Example #5
Source File: UpdatePullRequests.java    From updatebot with Apache License 2.0 4 votes vote down vote up
@Override
public void run(CommandContext context) throws IOException {
    Status contextStatus = Status.COMPLETE;
    GHRepository ghRepository = context.gitHubRepository();
    if (ghRepository != null) {

        // lets look for a pending issue
        GHIssue issue = getOrFindIssue(context, ghRepository);
        if (issue != null && isOpen(issue)) {
            contextStatus = Status.PENDING;
        }

        List<GHPullRequest> pullRequests = PullRequests.getOpenPullRequests(ghRepository, context.getConfiguration());
        for (GHPullRequest pullRequest : pullRequests) {
            Configuration configuration = context.getConfiguration();
            if (GitHubHelpers.hasLabel(getLabels(pullRequest), configuration.getGithubPullRequestLabel())) {
                context.setPullRequest(pullRequest);

                if (!GitHubHelpers.isMergeable(pullRequest)) {
                    // lets re-run the update commands we can find on the PR
                    CompositeCommand commands = loadCommandsFromPullRequest(context, ghRepository, pullRequest);
                    if (commands != null) {
                        commands.run(context, ghRepository, pullRequest);
                    }
                }

                if (mergeOnSuccess) {
                    try {
                        GHCommitStatus status = getLastCommitStatus(ghRepository, pullRequest);
                        if (status != null) {
                            GHCommitState state = status.getState();
                            if (state != null && state.equals(GHCommitState.SUCCESS)) {
                                String message = Markdown.UPDATEBOT_ICON + " merging this pull request as its CI was successful";
                                pullRequest.merge(message);
                            }
                        }
                    } catch (IOException e) {
                        context.warn(LOG, "Failed to find last commit status for PR " + pullRequest.getHtmlUrl() + " " + e, e);
                    }
                }
                if (isOpen(pullRequest)) {
                    contextStatus = Status.PENDING;
                }
            }
        }
    }
    context.setStatus(contextStatus);
}
 
Example #6
Source File: GitHubHelpers.java    From updatebot with Apache License 2.0 4 votes vote down vote up
public static GHCommitStatus getLastCommitStatus(GHRepository repository, GHPullRequest pullRequest) throws IOException {
    String commitSha = pullRequest.getHead().getRef();
    return repository.getLastCommitStatus(commitSha);
}
 
Example #7
Source File: CommitStatusMatcher.java    From github-integration-plugin with MIT License 4 votes vote down vote up
@Override
protected Boolean featureValueOf(GHCommitStatus commitStatus) {
    return commitStatus.getState().equals(state) &&
            commitStatus.getContext().equals(context) &&
            commitStatus.getDescription().equals(description);
}
 
Example #8
Source File: CommitDetails.java    From apollo with Apache License 2.0 votes vote down vote up
public GHCommitStatus getCommitStatus() { return commitStatus; }