Search in sources :

Example 6 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class TargetBranchComponentUuidsTest method setup.

@Before
public void setup() {
    underTest = new TargetBranchComponentUuids(analysisMetadataHolder, db.getDbClient());
    Project project = mock(Project.class);
    analysisMetadataHolder.setProject(project);
    analysisMetadataHolder.setBranch(branch);
    ComponentDto projectDto = db.components().insertPublicProject();
    when(project.getUuid()).thenReturn(projectDto.uuid());
    branch1 = db.components().insertProjectBranch(projectDto, b -> b.setKey(BRANCH_KEY));
    ComponentDto pr1branch = db.components().insertProjectBranch(projectDto, b -> b.setKey(PR_KEY).setBranchType(BranchType.PULL_REQUEST).setPullRequestData(DbProjectBranches.PullRequestData.newBuilder().setTarget(BRANCH_KEY).build()).setMergeBranchUuid(projectDto.getMainBranchProjectUuid()));
    branch1File = ComponentTesting.newFileDto(branch1, null, "file").setUuid("branch1File");
    pr1File = ComponentTesting.newFileDto(pr1branch, null, "file").setUuid("file1");
    db.components().insertComponents(branch1File, pr1File);
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) DbTester(org.sonar.db.DbTester) BranchType(org.sonar.db.component.BranchType) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) DbProjectBranches(org.sonar.db.protobuf.DbProjectBranches) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) SnapshotTesting.newAnalysis(org.sonar.db.component.SnapshotTesting.newAnalysis) AnalysisMetadataHolderRule(org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule) ComponentTesting(org.sonar.db.component.ComponentTesting) Before(org.junit.Before) Project(org.sonar.server.project.Project) Mockito.mock(org.mockito.Mockito.mock) Project(org.sonar.server.project.Project) ComponentDto(org.sonar.db.component.ComponentDto) Before(org.junit.Before)

Example 7 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class NotificationFactory method getProject.

private Project getProject() {
    Component project = treeRootHolder.getRoot();
    Branch branch = analysisMetadataHolder.getBranch();
    Project.Builder builder = new Project.Builder(project.getUuid()).setKey(project.getKey()).setProjectName(project.getName());
    if (branch.getType() != PULL_REQUEST && !branch.isMain()) {
        builder.setBranchName(branch.getName());
    }
    return builder.build();
}
Also used : Project(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Project) Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) IssuesChangesNotificationBuilder(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder) Component(org.sonar.ce.task.projectanalysis.component.Component)

Example 8 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class QualityGateEventsStep method notifyUsers.

/**
 * @param rawStatus OK or ERROR + optional text
 */
private void notifyUsers(Component project, QualityGateStatus rawStatus, boolean isNewAlert) {
    QGChangeNotification notification = new QGChangeNotification();
    notification.setDefaultMessage(String.format("Alert on %s: %s", project.getName(), rawStatus.getStatus().getLabel())).setFieldValue("projectName", project.getName()).setFieldValue("projectKey", project.getKey()).setFieldValue("projectVersion", project.getProjectAttributes().getProjectVersion()).setFieldValue("alertName", rawStatus.getStatus().getLabel()).setFieldValue("alertText", rawStatus.getText()).setFieldValue("alertLevel", rawStatus.getStatus().toString()).setFieldValue("isNewAlert", Boolean.toString(isNewAlert));
    Branch branch = analysisMetadataHolder.getBranch();
    if (!branch.isMain()) {
        notification.setFieldValue("branch", branch.getName());
    }
    List<Metric> ratingMetrics = metricRepository.getMetricsByType(MetricType.RATING);
    String ratingMetricsInOneString = ratingMetrics.stream().map(Metric::getName).collect(Collectors.joining(","));
    notification.setFieldValue("ratingMetrics", ratingMetricsInOneString);
    notificationService.deliverEmails(singleton(notification));
    // compatibility with old API
    notificationService.deliver(notification);
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) QGChangeNotification(org.sonar.server.qualitygate.notification.QGChangeNotification) Metric(org.sonar.ce.task.projectanalysis.metric.Metric)

Example 9 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class NewLinesRepositoryTest method setPullRequest.

private void setPullRequest() {
    Branch branch = mock(Branch.class);
    when(branch.getType()).thenReturn(BranchType.PULL_REQUEST);
    analysisMetadataHolder.setBranch(branch);
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch)

Example 10 with Branch

use of org.sonar.ce.task.projectanalysis.analysis.Branch in project sonarqube by SonarSource.

the class BuildComponentTreeStepTest method generate_keys_when_using_new_branch.

@Test
public void generate_keys_when_using_new_branch() {
    Branch branch = mock(Branch.class);
    when(branch.getName()).thenReturn("origin/feature");
    when(branch.isMain()).thenReturn(false);
    when(branch.generateKey(any(), any())).thenReturn("generated");
    analysisMetadataHolder.setRootComponentRef(ROOT_REF).setAnalysisDate(ANALYSIS_DATE).setProject(Project.from(newPrivateProjectDto().setDbKey(REPORT_PROJECT_KEY))).setBranch(branch);
    BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder, reportModulesPath);
    reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, FILE_1_REF));
    reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_PATH_1));
    underTest.execute(new TestComputationStepContext());
    verifyComponentByRef(ROOT_REF, "generated", REPORT_PROJECT_KEY, analysisMetadataHolder.getProject().getName(), null);
    verifyComponentByKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1, "generated", REPORT_DIR_PATH_1);
    verifyComponentByRef(FILE_1_REF, "generated", REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1, REPORT_FILE_NAME_1, null);
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Aggregations

Branch (org.sonar.ce.task.projectanalysis.analysis.Branch)40 Test (org.junit.Test)21 DefaultIssue (org.sonar.core.issue.DefaultIssue)7 ComponentDto (org.sonar.db.component.ComponentDto)7 Before (org.junit.Before)5 BranchType (org.sonar.db.component.BranchType)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Rule (org.junit.Rule)4 Mockito.mock (org.mockito.Mockito.mock)4 Mockito.when (org.mockito.Mockito.when)4 AnalysisMetadataHolderRule (org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule)4 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)4 DbTester (org.sonar.db.DbTester)4 Project (org.sonar.server.project.Project)4 Date (java.util.Date)3 FieldDiffs (org.sonar.core.issue.FieldDiffs)3 ComponentTesting (org.sonar.db.component.ComponentTesting)3 SnapshotTesting.newAnalysis (org.sonar.db.component.SnapshotTesting.newAnalysis)3 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)3 RuleKey (org.sonar.api.rule.RuleKey)2