Skip to content

Commit

Permalink
SONAR-11421 Add sha1 to ProjectAnalysis
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit-sns authored and SonarTech committed Jan 8, 2019
1 parent ba01aad commit ea906c4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ private ProjectAnalysisImpl createProjectAnalysis(CeTask.Status status) {
getAnalysis().map(a -> a.getDate().getTime()).orElse(system2.now()),
ScannerContextImpl.from(reportReader.readContextProperties()),
status == SUCCESS ? createQualityGate() : null,
createBranch());
createBranch(),
reportReader.readMetadata().getScmRevisionId()
);
}

@CheckForNull
Expand Down Expand Up @@ -223,10 +225,11 @@ private static class ProjectAnalysisImpl implements PostProjectAnalysisTask.Proj
private final Branch branch;
@Nullable
private final Analysis analysis;
private final String scmRevisionId;

private ProjectAnalysisImpl(@Nullable Organization organization, CeTask ceTask, Project project,
@Nullable Analysis analysis, long date,
ScannerContext scannerContext, @Nullable QualityGate qualityGate, @Nullable Branch branch) {
ScannerContext scannerContext, @Nullable QualityGate qualityGate, @Nullable Branch branch, String scmRevisionId) {
this.organization = organization;
this.ceTask = requireNonNull(ceTask, "ceTask can not be null");
this.project = requireNonNull(project, "project can not be null");
Expand All @@ -235,6 +238,7 @@ private ProjectAnalysisImpl(@Nullable Organization organization, CeTask ceTask,
this.scannerContext = requireNonNull(scannerContext, "scannerContext can not be null");
this.qualityGate = qualityGate;
this.branch = branch;
this.scmRevisionId = scmRevisionId;
}

@Override
Expand Down Expand Up @@ -283,6 +287,11 @@ public ScannerContext getScannerContext() {
return scannerContext;
}

@Override
public String getScmRevisionId() {
return scmRevisionId;
}

@Override
public String toString() {
return "ProjectAnalysis{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public void setUp() throws Exception {
.setOrganizationsEnabled(new Random().nextBoolean())
.setOrganization(Organization.from(
new OrganizationDto().setKey(organizationKey).setName(organizationName).setUuid(organizationUuid).setDefaultQualityGateUuid("foo")));

reportReader.setMetadata(ScannerReport.Metadata.newBuilder().build());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,10 @@ interface ProjectAnalysis {
* @since 6.1
*/
ScannerContext getScannerContext();

/**
* Revision Id that has been analysed
*/
String getScmRevisionId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,11 @@ public ScannerContext getScannerContext() {
return scannerContext;
}

@Override
public String getScmRevisionId() {
return null;
}

@Override
public String toString() {
return "ProjectAnalysis{" +
Expand Down

0 comments on commit ea906c4

Please sign in to comment.