Search in sources :

Example 6 with PullRequestStatus

use of io.pivotal.cla.service.github.PullRequestStatus in project pivotal-cla by pivotalsoftware.

the class GitHubHooksControllerTests method markCommitStatusSuccessCorporate.

@Test
@SuppressWarnings("unchecked")
public void markCommitStatusSuccessCorporate() throws Exception {
    User user = WithSigningUserFactory.create();
    when(mockUserRepo.findOne(anyString())).thenReturn(user);
    when(mockTokenRepo.findOne("rwinch/176_test")).thenReturn(new AccessToken("rwinch/176_test", "mock_access_token_value"));
    when(mockGitHub.getOrganizations(anyString())).thenReturn(Arrays.asList("organization"));
    when(mockCorporateSignatureRepository.findSignature(anyString(), anySet(), anyCollectionOf(String.class))).thenReturn(corporateSignature);
    mockMvc.perform(hookRequest().header("X-GitHub-Event", GithubEvents.PULL_REQUEST).content(getPayload("pull_request.json"))).andExpect(status().isOk());
    ArgumentCaptor<PullRequestStatus> statusCaptor = ArgumentCaptor.forClass(PullRequestStatus.class);
    verify(mockGitHub).save(statusCaptor.capture());
    PullRequestStatus status = statusCaptor.getValue();
    assertThat(status.getRepoId()).isEqualTo("rwinch/176_test");
    assertThat(status.getAccessToken()).isEqualTo("mock_access_token_value");
    assertThat(status.getPullRequestId()).isEqualTo(2);
    assertThat(status.getSha()).isEqualTo("a6befb598a35c1c206e1bf7bbb3018f4403b9610");
    assertThat(status.getUrl()).isEqualTo("http://localhost/sign/pivotal?repositoryId=rwinch/176_test&pullRequestId=2");
    assertThat(status.isSuccess()).isTrue();
    assertThat(status.getGitHubUsername()).isEqualTo(user.getGitHubLogin());
}
Also used : User(io.pivotal.cla.data.User) AccessToken(io.pivotal.cla.data.AccessToken) Matchers.anyString(org.mockito.Matchers.anyString) PullRequestStatus(io.pivotal.cla.service.github.PullRequestStatus) Test(org.junit.Test)

Example 7 with PullRequestStatus

use of io.pivotal.cla.service.github.PullRequestStatus in project pivotal-cla by pivotalsoftware.

the class ClaRequest method createUpdatePullRequestStatus.

public ClaPullRequestStatusRequest createUpdatePullRequestStatus(String currentUserGitHubLogin) throws Exception {
    if (pullRequestId == null) {
        return null;
    }
    PullRequestStatus commitStatus = new PullRequestStatus();
    commitStatus.setRepoId(repositoryId);
    commitStatus.setPullRequestId(pullRequestId);
    commitStatus.setUrl(signUrl());
    commitStatus.setSyncUrl(syncUrl());
    commitStatus.setFaqUrl(faqUrl());
    commitStatus.setGitHubUsername(currentUserGitHubLogin);
    commitStatus.setPullRequestState(PullRequestStatus.UNKNOWN_PULL_REQUEST_STATE);
    ClaPullRequestStatusRequest request = new ClaPullRequestStatusRequest();
    request.setClaName(claName);
    request.setCommitStatus(commitStatus);
    return request;
}
Also used : ClaPullRequestStatusRequest(io.pivotal.cla.service.ClaPullRequestStatusRequest) PullRequestStatus(io.pivotal.cla.service.github.PullRequestStatus)

Example 8 with PullRequestStatus

use of io.pivotal.cla.service.github.PullRequestStatus in project pivotal-cla by pivotalsoftware.

the class ClaService method migratePullRequestStatus.

@SneakyThrows
public void migratePullRequestStatus(String claName, MigratePullRequestStatusRequest request) {
    List<PullRequestStatus> commitStatuses = gitHub.createUpdatePullRequestStatuses(request);
    long oneSecondInMs = TimeUnit.SECONDS.toMillis(1L);
    for (PullRequestStatus status : commitStatuses) {
        boolean success = hasSigned(status.getGitHubUsername(), claName);
        status.setSuccess(success);
        gitHub.save(status);
        // necessary to help prevent abuse rate limits
        // https://developer.github.com/guides/best-practices-for-integrators/#dealing-with-abuse-rate-limits
        Thread.sleep(oneSecondInMs);
    }
}
Also used : PullRequestStatus(io.pivotal.cla.service.github.PullRequestStatus) SneakyThrows(lombok.SneakyThrows)

Example 9 with PullRequestStatus

use of io.pivotal.cla.service.github.PullRequestStatus in project pivotal-cla by pivotalsoftware.

the class IclaControllerTests method signWithRepositoryIdWithPullRequestId.

@Test
@SuppressWarnings("unchecked")
public void signWithRepositoryIdWithPullRequestId() throws Exception {
    String repositoryId = "rwinch/176_test";
    when(mockClaRepository.findByNameAndPrimaryTrue(cla.getName())).thenReturn(cla);
    when(mockClaRepository.findOne(cla.getId())).thenReturn(cla);
    when(mockIndividualSignatureRepository.findSignaturesFor(any(), eq(WithSigningUserFactory.create()), eq(cla.getName()))).thenReturn(Collections.<IndividualSignature>emptyList(), Arrays.asList(individualSignature));
    when(mockTokenRepo.findOne(repositoryId)).thenReturn(new AccessToken(repositoryId, "access-token-123"));
    when(mockGitHub.getShaForPullRequest(any(PullRequestStatus.class))).thenReturn("abc123");
    int pullRequestId = 2;
    SignIclaPage signPage = SignIclaPage.go(getDriver(), cla.getName(), repositoryId, pullRequestId);
    signPage = signPage.form().name("Rob Winch").email("rob@gmail.com").mailingAddress("123 Seasame St").country("USA").telephone("123.456.7890").confirm().sign(SignIclaPage.class);
    signPage.assertAt();
    signPage.assertPullRequestLink(repositoryId, pullRequestId);
    ArgumentCaptor<PullRequestStatus> updatePullRequestCaptor = ArgumentCaptor.forClass(PullRequestStatus.class);
    verify(mockGitHub).save(updatePullRequestCaptor.capture());
    PullRequestStatus updatePr = updatePullRequestCaptor.getValue();
    String commitStatusUrl = "http://localhost/sign/" + cla.getName() + "?repositoryId=" + repositoryId + "&pullRequestId=" + pullRequestId;
    assertThat(updatePr.getUrl()).isEqualTo(commitStatusUrl);
    assertThat(updatePr.getGitHubUsername()).isEqualTo(WithSigningUserFactory.create().getGitHubLogin());
    assertThat(updatePr.getPullRequestId()).isEqualTo(pullRequestId);
    assertThat(updatePr.getRepoId()).isEqualTo(repositoryId);
}
Also used : AccessToken(io.pivotal.cla.data.AccessToken) SignIclaPage(io.pivotal.cla.webdriver.pages.SignIclaPage) PullRequestStatus(io.pivotal.cla.service.github.PullRequestStatus) Test(org.junit.Test)

Example 10 with PullRequestStatus

use of io.pivotal.cla.service.github.PullRequestStatus in project pivotal-cla by pivotalsoftware.

the class GitHubHooksControllerTests method markCommitStatusSuccessIndividual.

@Test
public void markCommitStatusSuccessIndividual() throws Exception {
    User user = WithSigningUserFactory.create();
    when(mockUserRepo.findOne(anyString())).thenReturn(user);
    when(mockTokenRepo.findOne("rwinch/176_test")).thenReturn(new AccessToken("rwinch/176_test", "mock_access_token_value"));
    when(mockIndividualSignatureRepository.findSignaturesFor(any(), any(), anyString())).thenReturn(Arrays.asList(individualSignature));
    mockMvc.perform(hookRequest().header("X-GitHub-Event", GithubEvents.PULL_REQUEST).content(getPayload("pull_request.json"))).andExpect(status().isOk());
    ArgumentCaptor<PullRequestStatus> statusCaptor = ArgumentCaptor.forClass(PullRequestStatus.class);
    verify(mockGitHub).save(statusCaptor.capture());
    PullRequestStatus status = statusCaptor.getValue();
    assertThat(status.getRepoId()).isEqualTo("rwinch/176_test");
    assertThat(status.getAccessToken()).isEqualTo("mock_access_token_value");
    assertThat(status.getPullRequestId()).isEqualTo(2);
    assertThat(status.getSha()).isEqualTo("a6befb598a35c1c206e1bf7bbb3018f4403b9610");
    assertThat(status.getUrl()).isEqualTo("http://localhost/sign/pivotal?repositoryId=rwinch/176_test&pullRequestId=2");
    assertThat(status.isSuccess()).isTrue();
    assertThat(status.getGitHubUsername()).isEqualTo(user.getGitHubLogin());
    assertThat(status.getPullRequestBody()).isNotEmpty();
}
Also used : User(io.pivotal.cla.data.User) AccessToken(io.pivotal.cla.data.AccessToken) PullRequestStatus(io.pivotal.cla.service.github.PullRequestStatus) Test(org.junit.Test)

Aggregations

PullRequestStatus (io.pivotal.cla.service.github.PullRequestStatus)13 AccessToken (io.pivotal.cla.data.AccessToken)10 Test (org.junit.Test)9 User (io.pivotal.cla.data.User)6 WithSigningUser (io.pivotal.cla.security.WithSigningUser)2 ClaPullRequestStatusRequest (io.pivotal.cla.service.ClaPullRequestStatusRequest)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Gson (com.google.gson.Gson)1 PullRequestId (io.pivotal.cla.egit.github.core.PullRequestId)1 RepositoryAware (io.pivotal.cla.egit.github.core.event.RepositoryAware)1 WithAdminUser (io.pivotal.cla.security.WithAdminUser)1 ContributingUrlsResponse (io.pivotal.cla.service.github.ContributingUrlsResponse)1 CreatePullRequestHookRequest (io.pivotal.cla.service.github.CreatePullRequestHookRequest)1 SignCclaPage (io.pivotal.cla.webdriver.pages.SignCclaPage)1 SignClaPage (io.pivotal.cla.webdriver.pages.SignClaPage)1 SignIclaPage (io.pivotal.cla.webdriver.pages.SignIclaPage)1 AdminLinkClaPage (io.pivotal.cla.webdriver.pages.admin.AdminLinkClaPage)1 SneakyThrows (lombok.SneakyThrows)1 PullRequest (org.eclipse.egit.github.core.PullRequest)1 Repository (org.eclipse.egit.github.core.Repository)1