Search in sources :

Example 16 with IssueChangeDto

use of org.sonar.db.issue.IssueChangeDto in project sonarqube by SonarSource.

the class EditCommentActionTest method fail_when_comment_has_not_user.

@Test
public void fail_when_comment_has_not_user() throws Exception {
    IssueDto issueDto = issueDbTester.insertIssue();
    IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, null, "please fix it");
    userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("You can only edit your own comments");
    call(commentDto.getKey(), "please have a look");
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test)

Example 17 with IssueChangeDto

use of org.sonar.db.issue.IssueChangeDto in project sonarqube by SonarSource.

the class PersistIssuesStep method insertChanges.

private static void insertChanges(IssueChangeMapper mapper, DefaultIssue issue) {
    for (IssueComment comment : issue.comments()) {
        DefaultIssueComment c = (DefaultIssueComment) comment;
        if (c.isNew()) {
            IssueChangeDto changeDto = IssueChangeDto.of(c);
            mapper.insert(changeDto);
        }
    }
    FieldDiffs diffs = issue.currentChange();
    if (!issue.isNew() && diffs != null) {
        IssueChangeDto changeDto = IssueChangeDto.of(issue.key(), diffs);
        mapper.insert(changeDto);
    }
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) FieldDiffs(org.sonar.core.issue.FieldDiffs) DefaultIssueComment(org.sonar.core.issue.DefaultIssueComment) IssueComment(org.sonar.api.issue.IssueComment) DefaultIssueComment(org.sonar.core.issue.DefaultIssueComment)

Example 18 with IssueChangeDto

use of org.sonar.db.issue.IssueChangeDto in project sonarqube by SonarSource.

the class SearchResponseFormat method formatIssueComments.

private static void formatIssueComments(SearchResponseData data, Issues.Issue.Builder wsIssue, IssueDto dto) {
    Issues.Comments.Builder wsComments = Issues.Comments.newBuilder();
    List<IssueChangeDto> comments = data.getCommentsForIssueKey(dto.getKey());
    if (comments != null) {
        Issues.Comment.Builder wsComment = Issues.Comment.newBuilder();
        for (IssueChangeDto comment : comments) {
            String markdown = comment.getChangeData();
            wsComment.clear().setKey(comment.getKey()).setLogin(nullToEmpty(comment.getUserLogin())).setUpdatable(data.isUpdatableComment(comment.getKey())).setCreatedAt(DateUtils.formatDateTime(new Date(comment.getCreatedAt())));
            if (markdown != null) {
                wsComment.setHtmlText(Markdown.convertToHtml(markdown)).setMarkdown(markdown);
            }
            wsComments.addComments(wsComment);
        }
    }
    wsIssue.setComments(wsComments);
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) Date(java.util.Date)

Example 19 with IssueChangeDto

use of org.sonar.db.issue.IssueChangeDto in project sonarqube by SonarSource.

the class IssueStorage method insertChanges.

private void insertChanges(IssueChangeMapper mapper, DefaultIssue issue) {
    for (IssueComment comment : issue.comments()) {
        DefaultIssueComment c = (DefaultIssueComment) comment;
        if (c.isNew()) {
            IssueChangeDto changeDto = IssueChangeDto.of(c);
            mapper.insert(changeDto);
        }
    }
    FieldDiffs diffs = issue.currentChange();
    if (!issue.isNew() && diffs != null) {
        IssueChangeDto changeDto = IssueChangeDto.of(issue.key(), diffs);
        mapper.insert(changeDto);
    }
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) FieldDiffs(org.sonar.core.issue.FieldDiffs) DefaultIssueComment(org.sonar.core.issue.DefaultIssueComment) IssueComment(org.sonar.api.issue.IssueComment) DefaultIssueComment(org.sonar.core.issue.DefaultIssueComment)

Example 20 with IssueChangeDto

use of org.sonar.db.issue.IssueChangeDto in project sonarqube by SonarSource.

the class NewEffortCalculatorTest method new_debt_if_issue_created_before_period.

@Test
public void new_debt_if_issue_created_before_period() {
    // creation: 1d
    // before period: increased to 2d
    // after period: increased to 5d, decreased to 4d then increased to 10d
    // -> new debt is 10d - 2d = 8d
    issue.setEffort(TEN_DAYS).setCreationDate(new Date(PERIOD_DATE - 10000));
    List<IssueChangeDto> changelog = Arrays.asList(newDebtChangelog(ONE_DAY.toMinutes(), TWO_DAYS.toMinutes(), PERIOD_DATE - 9000), newDebtChangelog(TWO_DAYS.toMinutes(), FIVE_DAYS.toMinutes(), PERIOD_DATE + 10000), newDebtChangelog(FIVE_DAYS.toMinutes(), FOUR_DAYS.toMinutes(), PERIOD_DATE + 20000), newDebtChangelog(FOUR_DAYS.toMinutes(), TEN_DAYS.toMinutes(), PERIOD_DATE + 30000));
    long newDebt = underTest.calculate(issue, changelog, PERIOD);
    assertThat(newDebt).isEqualTo(TEN_DAYS.toMinutes() - TWO_DAYS.toMinutes());
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) Date(java.util.Date) Test(org.junit.Test)

Aggregations

IssueChangeDto (org.sonar.db.issue.IssueChangeDto)23 Test (org.junit.Test)18 IssueDto (org.sonar.db.issue.IssueDto)15 Request (org.sonar.api.server.ws.Request)5 Response (org.sonar.api.server.ws.Response)5 TestRequest (org.sonar.server.ws.TestRequest)5 TestResponse (org.sonar.server.ws.TestResponse)5 Date (java.util.Date)4 IssueComment (org.sonar.api.issue.IssueComment)2 DefaultIssueComment (org.sonar.core.issue.DefaultIssueComment)2 FieldDiffs (org.sonar.core.issue.FieldDiffs)2 ComponentDto (org.sonar.db.component.ComponentDto)2 IssueChangeDao (org.sonar.db.issue.IssueChangeDao)2 UserDto (org.sonar.db.user.UserDto)2 IssueIndexer (org.sonar.server.issue.index.IssueIndexer)2 WsTester (org.sonar.server.ws.WsTester)2 DbSession (org.sonar.db.DbSession)1 Component (org.sonar.server.computation.task.projectanalysis.component.Component)1 BulkChangeWsResponse (org.sonarqube.ws.Issues.BulkChangeWsResponse)1