Search in sources :

Example 1 with DisplayUser

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

the class MentionMapper method extractMentionsFromComment.

public Set<String> extractMentionsFromComment(String comment) {
    Set<String> mentions = new HashSet<>();
    Matcher matcher = mentionPattern.matcher(comment);
    while (matcher.find()) {
        String matchingId = matcher.group(1);
        Optional<DisplayUser> displayUser = userDisplayManager.get(matchingId);
        displayUser.ifPresent(user -> mentions.add(user.getId()));
    }
    return mentions;
}
Also used : Matcher(java.util.regex.Matcher) DisplayUser(sonia.scm.user.DisplayUser) HashSet(java.util.HashSet)

Example 2 with DisplayUser

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

the class MentionMapper method parseMentionsUserIdsToDisplayNames.

public BasicComment parseMentionsUserIdsToDisplayNames(BasicComment rootComment) {
    BasicComment comment = rootComment.clone();
    for (String mentionUserId : rootComment.getMentionUserIds()) {
        Optional<DisplayUser> user = userDisplayManager.get(mentionUserId);
        user.ifPresent(displayUser -> comment.setComment(comment.getComment().replaceAll("\\[" + mentionUserId + "]", displayUser.getDisplayName())));
    }
    return comment;
}
Also used : DisplayUser(sonia.scm.user.DisplayUser) BasicComment(com.cloudogu.scm.review.comment.service.BasicComment)

Example 3 with DisplayUser

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

the class HitEnricher method appendEmbeddedUserForAuthor.

private void appendEmbeddedUserForAuthor(HalAppender appender, Hit hit) {
    Hit.Field author = hit.getFields().get("author");
    Optional<DisplayUser> displayUser = userDisplayManager.get(((Hit.ValueField) author).getValue().toString());
    if (displayUser.isPresent()) {
        DisplayUser user = displayUser.get();
        appender.appendEmbedded("user", new DisplayedUserDto(user.getId(), user.getDisplayName(), user.getMail()));
    }
}
Also used : Hit(sonia.scm.search.Hit) DisplayUser(sonia.scm.user.DisplayUser) DisplayedUserDto(com.cloudogu.scm.review.pullrequest.dto.DisplayedUserDto)

Example 4 with DisplayUser

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

the class MentionMapperTest method shouldAppendMultipleMentionsForMentionedUser.

@Test
void shouldAppendMultipleMentionsForMentionedUser() {
    DisplayUser user1 = setupExistingUserMock("dent", "Arthur Dent", "dent@hitchhiker.org");
    DisplayUser user2 = setupExistingUserMock("_anonymous", "SCM Anonymous", "anonymous@hitchhiker.org");
    Set<String> userIds = ImmutableSet.of("dent", "_anonymous");
    Set<DisplayUser> mentions = mentionMapper.mapMentions(userIds);
    assertThat(mentions).hasSize(2);
    assertThat(mentions).contains(user1);
    assertThat(mentions).contains(user2);
}
Also used : DisplayUser(sonia.scm.user.DisplayUser) Test(org.junit.jupiter.api.Test)

Example 5 with DisplayUser

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

the class MergeResource method getMergeStrategyInfo.

@GET
@Path("{namespace}/{name}/{pullRequestId}/merge-strategy-info")
@Produces(PullRequestMediaType.MERGE_STRATEGY_INFO)
@Operation(summary = "Get commit message information", description = "Returns commit message information for the given merge strategy", tags = "Pull Request")
@ApiResponse(responseCode = "200", description = "commit message was created", content = @Content(schema = @Schema(implementation = MergeStrategyInfoDto.class)))
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(responseCode = "500", description = "internal server error", content = @Content(mediaType = VndMediaType.ERROR_TYPE, schema = @Schema(implementation = ErrorDto.class)))
public MergeStrategyInfoDto getMergeStrategyInfo(@PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("pullRequestId") String pullRequestId, @QueryParam("strategy") MergeStrategy strategy) {
    MergeService.CommitDefaults commitDefaults = service.createCommitDefaults(new NamespaceAndName(namespace, name), pullRequestId, strategy);
    DisplayUser commitAuthor = commitDefaults.getCommitAuthor();
    return new MergeStrategyInfoDto(service.isCommitMessageDisabled(strategy), commitDefaults.getCommitMessage(), service.createMergeCommitMessageHint(strategy), renderCommitAuthorIfPresent(commitAuthor));
}
Also used : MergeService(com.cloudogu.scm.review.pullrequest.service.MergeService) NamespaceAndName(sonia.scm.repository.NamespaceAndName) DisplayUser(sonia.scm.user.DisplayUser) MergeStrategyInfoDto(com.cloudogu.scm.review.pullrequest.dto.MergeStrategyInfoDto) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Aggregations

DisplayUser (sonia.scm.user.DisplayUser)7 Test (org.junit.jupiter.api.Test)3 BasicComment (com.cloudogu.scm.review.comment.service.BasicComment)1 DisplayedUserDto (com.cloudogu.scm.review.pullrequest.dto.DisplayedUserDto)1 MergeStrategyInfoDto (com.cloudogu.scm.review.pullrequest.dto.MergeStrategyInfoDto)1 MergeService (com.cloudogu.scm.review.pullrequest.service.MergeService)1 CommitDefaults (com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults)1 Operation (io.swagger.v3.oas.annotations.Operation)1 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)1 HashSet (java.util.HashSet)1 Matcher (java.util.regex.Matcher)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Changeset (sonia.scm.repository.Changeset)1 ChangesetPagingResult (sonia.scm.repository.ChangesetPagingResult)1 NamespaceAndName (sonia.scm.repository.NamespaceAndName)1 Person (sonia.scm.repository.Person)1 Hit (sonia.scm.search.Hit)1 User (sonia.scm.user.User)1