Search in sources :

Example 1 with ListWsResponse

use of org.sonarqube.ws.ProjectPullRequests.ListWsResponse in project sonarqube by SonarSource.

the class ListActionTest method pull_requests.

@Test
public void pull_requests() {
    ComponentDto project = db.components().insertPrivateProject();
    userSession.logIn().addProjectPermission(UserRole.USER, project);
    ComponentDto nonMainBranch = db.components().insertProjectBranch(project, b -> b.setKey("branch1").setBranchType(BranchType.BRANCH));
    ComponentDto pullRequestOnNonMainBranch = db.components().insertProjectBranch(project, b -> b.setKey("pull_request_on_branch1").setBranchType(PULL_REQUEST).setMergeBranchUuid(nonMainBranch.uuid()).setPullRequestData(DbProjectBranches.PullRequestData.newBuilder().setBranch("feature/bar").build()));
    ComponentDto pullRequestOnMaster = db.components().insertProjectBranch(project, b -> b.setKey("pull_request_on_master").setBranchType(PULL_REQUEST).setMergeBranchUuid(project.uuid()).setPullRequestData(DbProjectBranches.PullRequestData.newBuilder().setBranch("feature/bar").build()));
    ListWsResponse response = ws.newRequest().setParam("project", project.getKey()).executeProtobuf(ListWsResponse.class);
    assertThat(response.getPullRequestsList()).extracting(PullRequest::getKey, PullRequest::getBase).containsExactlyInAnyOrder(tuple(pullRequestOnNonMainBranch.getPullRequest(), nonMainBranch.getBranch()), tuple(pullRequestOnMaster.getPullRequest(), "master"));
}
Also used : ListWsResponse(org.sonarqube.ws.ProjectPullRequests.ListWsResponse) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 2 with ListWsResponse

use of org.sonarqube.ws.ProjectPullRequests.ListWsResponse in project sonarqube by SonarSource.

the class ListActionTest method status_on_pull_requests.

@Test
public void status_on_pull_requests() {
    ComponentDto project = db.components().insertPrivateProject();
    userSession.logIn().addProjectPermission(UserRole.USER, project);
    ComponentDto nonMainBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH));
    ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST).setMergeBranchUuid(nonMainBranch.uuid()).setPullRequestData(DbProjectBranches.PullRequestData.newBuilder().setBranch("feature/bar").build()));
    db.measures().insertLiveMeasure(pullRequest, qualityGateStatus, m -> m.setData("ERROR"));
    RuleDefinitionDto rule = db.rules().insert();
    db.issues().insert(rule, pullRequest, pullRequest, i -> i.setType(BUG).setResolution(null));
    db.issues().insert(rule, pullRequest, pullRequest, i -> i.setType(BUG).setResolution(RESOLUTION_FIXED));
    db.issues().insert(rule, pullRequest, pullRequest, i -> i.setType(VULNERABILITY).setResolution(null));
    db.issues().insert(rule, pullRequest, pullRequest, i -> i.setType(VULNERABILITY).setResolution(null));
    db.issues().insert(rule, pullRequest, pullRequest, i -> i.setType(CODE_SMELL).setResolution(null));
    db.issues().insert(rule, pullRequest, pullRequest, i -> i.setType(CODE_SMELL).setResolution(null));
    db.issues().insert(rule, pullRequest, pullRequest, i -> i.setType(CODE_SMELL).setResolution(null));
    db.issues().insert(rule, pullRequest, pullRequest, i -> i.setType(CODE_SMELL).setResolution(RESOLUTION_FALSE_POSITIVE));
    indexIssues();
    permissionIndexerTester.allowOnlyAnyone(project);
    ListWsResponse response = ws.newRequest().setParam("project", project.getKey()).executeProtobuf(ListWsResponse.class);
    assertThat(response.getPullRequestsList().stream().map(PullRequest::getStatus)).extracting(Status::getQualityGateStatus, Status::hasBugs, Status::getBugs, Status::hasVulnerabilities, Status::getVulnerabilities, Status::hasCodeSmells, Status::getCodeSmells).containsExactlyInAnyOrder(tuple("ERROR", true, 1L, true, 2L, true, 3L));
}
Also used : ListWsResponse(org.sonarqube.ws.ProjectPullRequests.ListWsResponse) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) Test(org.junit.Test)

Example 3 with ListWsResponse

use of org.sonarqube.ws.ProjectPullRequests.ListWsResponse in project sonarqube by SonarSource.

the class ListActionTest method pull_request.

@Test
public void pull_request() {
    ComponentDto project = db.components().insertPrivateProject();
    db.components().insertProjectBranch(project, b -> b.setKey("123").setBranchType(PULL_REQUEST).setMergeBranchUuid(project.uuid()).setPullRequestData(DbProjectBranches.PullRequestData.newBuilder().setBranch("feature/bar").build()));
    userSession.logIn().addProjectPermission(UserRole.USER, project);
    ListWsResponse response = ws.newRequest().setParam("project", project.getDbKey()).executeProtobuf(ListWsResponse.class);
    assertThat(response.getPullRequestsList()).extracting(PullRequest::getKey, PullRequest::getBranch, PullRequest::getIsOrphan, PullRequest::hasUrl, PullRequest::hasTitle).containsExactlyInAnyOrder(tuple("123", "feature/bar", false, false, false));
}
Also used : ListWsResponse(org.sonarqube.ws.ProjectPullRequests.ListWsResponse) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 4 with ListWsResponse

use of org.sonarqube.ws.ProjectPullRequests.ListWsResponse in project sonarqube by SonarSource.

the class ListActionTest method does_not_fail_when_only_browse_permission_on_project.

@Test
public void does_not_fail_when_only_browse_permission_on_project() {
    ComponentDto project = db.components().insertPrivateProject();
    db.components().insertProjectBranch(project, b -> b.setKey("123").setBranchType(PULL_REQUEST).setMergeBranchUuid(project.uuid()).setPullRequestData(DbProjectBranches.PullRequestData.newBuilder().setBranch("feature/bar").build()));
    userSession.logIn().addProjectPermission(UserRole.USER, project);
    ListWsResponse response = ws.newRequest().setParam("project", project.getKey()).executeProtobuf(ListWsResponse.class);
    assertThat(response.getPullRequestsList()).extracting(PullRequest::getKey).containsExactlyInAnyOrder("123");
}
Also used : ListWsResponse(org.sonarqube.ws.ProjectPullRequests.ListWsResponse) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 5 with ListWsResponse

use of org.sonarqube.ws.ProjectPullRequests.ListWsResponse in project sonarqube by SonarSource.

the class ListActionTest method status_on_pull_request_with_no_issue.

@Test
public void status_on_pull_request_with_no_issue() {
    ComponentDto project = db.components().insertPrivateProject();
    userSession.logIn().addProjectPermission(UserRole.USER, project);
    ComponentDto nonMainBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH));
    db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST).setMergeBranchUuid(nonMainBranch.uuid()).setPullRequestData(DbProjectBranches.PullRequestData.newBuilder().setBranch("feature/bar").build()));
    indexIssues();
    permissionIndexerTester.allowOnlyAnyone(project);
    ListWsResponse response = ws.newRequest().setParam("project", project.getKey()).executeProtobuf(ListWsResponse.class);
    assertThat(response.getPullRequestsList().stream().map(PullRequest::getStatus)).extracting(Status::getBugs, Status::getVulnerabilities, Status::getCodeSmells).containsExactlyInAnyOrder(tuple(0L, 0L, 0L));
}
Also used : ListWsResponse(org.sonarqube.ws.ProjectPullRequests.ListWsResponse) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 ComponentDto (org.sonar.db.component.ComponentDto)10 ListWsResponse (org.sonarqube.ws.ProjectPullRequests.ListWsResponse)10 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)2 String.format (java.lang.String.format)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 Assertions.tuple (org.assertj.core.api.Assertions.tuple)1 Before (org.junit.Before)1 Rule (org.junit.Rule)1 RESOLUTION_FALSE_POSITIVE (org.sonar.api.issue.Issue.RESOLUTION_FALSE_POSITIVE)1 RESOLUTION_FIXED (org.sonar.api.issue.Issue.RESOLUTION_FIXED)1 ALERT_STATUS_KEY (org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY)1 PROJECT (org.sonar.api.resources.Qualifiers.PROJECT)1 ResourceTypes (org.sonar.api.resources.ResourceTypes)1 BUG (org.sonar.api.rules.RuleType.BUG)1 CODE_SMELL (org.sonar.api.rules.RuleType.CODE_SMELL)1 VULNERABILITY (org.sonar.api.rules.RuleType.VULNERABILITY)1 Change (org.sonar.api.server.ws.Change)1 WebService (org.sonar.api.server.ws.WebService)1