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);
}
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();
}
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);
}
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);
}
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);
}
Aggregations