Search in sources :

Example 11 with User

use of sonia.scm.user.User in project scm-review-plugin by scm-manager.

the class CurrentUserResolver method getCurrentUserDisplayName.

public static String getCurrentUserDisplayName() {
    PrincipalCollection principals = SecurityUtils.getSubject().getPrincipals();
    String displayName = principals.getPrimaryPrincipal().toString();
    User user = principals.oneByType(User.class);
    if (user != null) {
        displayName = user.getDisplayName();
        if (Strings.isNullOrEmpty(displayName)) {
            displayName = user.getName();
        }
    }
    return displayName;
}
Also used : User(sonia.scm.user.User) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection)

Example 12 with User

use of sonia.scm.user.User in project scm-review-plugin by scm-manager.

the class MergeService method appendSquashContributors.

private void appendSquashContributors(StringBuilder builder, PullRequest pullRequest, Set<Person> contributors) {
    userDisplayManager.get(pullRequest.getAuthor()).ifPresent(prAuthor -> {
        User currentUser = currentUser();
        String committerMail = email.getMailOrFallback(currentUser);
        builder.append("\nAuthor: ").append(prAuthor.getDisplayName()).append(" <").append(prAuthor.getMail()).append(">");
        if (!prAuthor.getDisplayName().equals(currentUser.getDisplayName())) {
            builder.append("\nCommitted-by: ").append(currentUser.getDisplayName());
            builder.append(" <").append(committerMail).append(">");
        }
        appendCoAuthors(builder, contributors, prAuthor);
    });
}
Also used : DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User)

Example 13 with User

use of sonia.scm.user.User in project scm-review-plugin by scm-manager.

the class DefaultPullRequestService method computeSubscriberForNewPullRequest.

private void computeSubscriberForNewPullRequest(PullRequest pullRequest) {
    User user = CurrentUserResolver.getCurrentUser();
    Set<String> subscriber = new HashSet<>(pullRequest.getSubscriber());
    subscriber.addAll(pullRequest.getReviewer().keySet());
    subscriber.add(user.getId());
    pullRequest.setSubscriber(subscriber);
}
Also used : User(sonia.scm.user.User) HashSet(java.util.HashSet)

Example 14 with User

use of sonia.scm.user.User in project scm-review-plugin by scm-manager.

the class MergeResourceTest method shouldCreateSquashCommitMessage.

@Test
void shouldCreateSquashCommitMessage() throws IOException, URISyntaxException {
    when(mergeService.createCommitDefaults(any(), any(), eq(SQUASH))).thenReturn(new CommitDefaults("successful", DisplayUser.from(new User("Arthur Dent"))));
    MockHttpRequest request = createHttpGetRequest(MERGE_URL + "/commit-message/?strategy=SQUASH");
    MockHttpResponse response = new MockHttpResponse();
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContentAsString()).isEqualTo("successful");
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) CommitDefaults(com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults) MockHttpResponse(org.jboss.resteasy.mock.MockHttpResponse) JsonMockHttpResponse(sonia.scm.web.JsonMockHttpResponse) Test(org.junit.jupiter.api.Test)

Example 15 with User

use of sonia.scm.user.User in project scm-review-plugin by scm-manager.

the class PullRequestRootResourceTest method shouldReturnAlreadyExistsResult.

@Test
@SubjectAware(username = "dent")
public void shouldReturnAlreadyExistsResult() throws URISyntaxException, IOException {
    mockLoggedInUser(new User("dent"));
    mockLogCommandForPullRequestCheck(ImmutableList.of(new Changeset()));
    PullRequest pullRequest = createPullRequest();
    when(store.getAll()).thenReturn(ImmutableList.of(pullRequest));
    MockHttpRequest request = MockHttpRequest.get("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/check?source=develop&target=master");
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContentAsString()).contains("\"status\":\"PR_ALREADY_EXISTS\"");
    assertThat(response.getContentAsString()).contains("\"_links\":{\"self\":{\"href\":\"/v2/pull-requests/ns/repo/check?source=develop&target=master\"}}");
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) TestData.createPullRequest(com.cloudogu.scm.review.TestData.createPullRequest) Changeset(sonia.scm.repository.Changeset) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Aggregations

User (sonia.scm.user.User)27 DisplayUser (sonia.scm.user.DisplayUser)23 MockHttpRequest (org.jboss.resteasy.mock.MockHttpRequest)15 Test (org.junit.Test)11 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)9 TestData.createPullRequest (com.cloudogu.scm.review.TestData.createPullRequest)8 Test (org.junit.jupiter.api.Test)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 CommitDefaults (com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults)6 SubjectAware (com.github.sdorra.shiro.SubjectAware)6 Changeset (sonia.scm.repository.Changeset)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)3 MockHttpResponse (org.jboss.resteasy.mock.MockHttpResponse)3 ChangesetPagingResult (sonia.scm.repository.ChangesetPagingResult)3 JsonMockHttpResponse (sonia.scm.web.JsonMockHttpResponse)3 DefaultPullRequestService (com.cloudogu.scm.review.pullrequest.service.DefaultPullRequestService)2 ReviewMark (com.cloudogu.scm.review.pullrequest.service.ReviewMark)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Person (sonia.scm.repository.Person)2