Skip to content

Commit

Permalink
Fix formating issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
JosefProchazkaVolvocars committed Jul 18, 2023
1 parent 26e29fc commit 8364ddf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ protected Integer getVerifiedValue(Result res, GerritTrigger trigger) {
* @return the lowest verified value.
*/
@CheckForNull
public Integer getMinimumVerifiedValue(MemoryImprint memoryImprint, boolean onlyBuilt, Integer maxAllowedVerifiedValue) {
public Integer getMinimumVerifiedValue(MemoryImprint memoryImprint, boolean onlyBuilt,
Integer maxAllowedVerifiedValue) {
Integer verified = Integer.MAX_VALUE;
for (Entry entry : memoryImprint.getEntries()) {
if (entry == null) {
Expand Down Expand Up @@ -533,19 +534,13 @@ public String getBuildCompletedCommand(MemoryImprint memoryImprint, TaskListener
// builds were successful, unstable or failed, we find the minimum
// verified/code review value for the NOT_BUILT ones too.
boolean onlyCountBuilt = true;
// If some builds failed, but their verified score is no longer
// available, then Successful builds would bump up the score.
// Set upper boundary on verified values based on builds status.
// JENKINS-66535
Integer maxAllowedVerifiedValue = Integer.MAX_VALUE;
if (memoryImprint.wereAllBuildsSuccessful()) {
command = config.getGerritCmdBuildSuccessful();
} else if (memoryImprint.wereAnyBuildsFailed()) {
command = config.getGerritCmdBuildFailed();
maxAllowedVerifiedValue = config.getGerritBuildFailedVerifiedValue();
} else if (memoryImprint.wereAnyBuildsUnstable()) {
command = config.getGerritCmdBuildUnstable();
maxAllowedVerifiedValue = config.getGerritBuildUnstableVerifiedValue();
} else if (memoryImprint.wereAllBuildsNotBuilt()) {
onlyCountBuilt = false;
command = config.getGerritCmdBuildNotBuilt();
Expand All @@ -554,6 +549,9 @@ public String getBuildCompletedCommand(MemoryImprint memoryImprint, TaskListener
} else {
//Just as bad as failed for now.
command = config.getGerritCmdBuildFailed();
// Some builds could have failed, but are already deleted and not
// available for score calculation.
// Set pessimistic upper boundary on verified value.
maxAllowedVerifiedValue = config.getGerritBuildFailedVerifiedValue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,41 +497,34 @@ public void testGetBuildCompletedCommandMulipleBuildsMessageOrder() throws IOExc
}

/**
* Test that verified value will be saturated in case of Failed, but missing built.
* Test that verified value will be saturated in case of missing built.
* (Conservative approach is to assume Failed build if the build is now missing.)
*/
@Test
public void testGetBuildCompletedMissingFailedBuild() throws IOException, InterruptedException {
int buildResults = 2;
IGerritHudsonTriggerConfig config = Setup.createConfig();
Integer expectedVerifiedVote = config.getGerritBuildFailedVerifiedValue();
Result[] availableResults = new Result[] {Result.SUCCESS, Result.FAILURE};

PatchsetCreated event = Setup.createPatchsetCreated();
TaskListener taskListener = mock(TaskListener.class);
GerritTrigger trigger = mock(GerritTrigger.class);
when(trigger.getGerritBuildSuccessfulVerifiedValue()).thenReturn(null);
when(trigger.getGerritBuildSuccessfulCodeReviewValue()).thenReturn(32);
when(trigger.getCustomUrl()).thenReturn("");
AbstractProject project = mock(AbstractProject.class);
Setup.setTrigger(trigger, project);
MemoryImprint.Entry[] entries = new MemoryImprint.Entry[buildResults];
EnvVars env = Setup.createEnvVars();

// Remaining successful build.
AbstractBuild build = Setup.createBuild(project, taskListener, env);
env.put("BUILD_URL", jenkins.getRootUrl() + build.getUrl());
when(build.getResult()).thenReturn(Result.SUCCESS);
when(build.getResult()).thenReturn(Result.SUCCESS);
entries[0] = Setup.createImprintEntry(project, build);

// Missing failed build.
// Missing build. Possibly Failed, but impossible to know if it is no longer available.
entries[1] = Setup.createImprintEntry(project, null);

MemoryImprint memoryImprint = mock(MemoryImprint.class);
when(memoryImprint.getEvent()).thenReturn(event);
when(memoryImprint.getEntries()).thenReturn(entries);
when(memoryImprint.wereAllBuildsSuccessful()).thenReturn(allAreOfType(Result.SUCCESS, availableResults));
when(memoryImprint.wereAnyBuildsFailed()).thenReturn(anyIsOfType(Result.FAILURE, availableResults));

ParameterExpander instance = new ParameterExpander(config, jenkins);
String result = instance.getBuildCompletedCommand(memoryImprint, taskListener, null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,12 @@ public static MemoryImprint.Entry createAndSetupMemoryImprintEntry(GerritTrigger
return createImprintEntry(project, build);
}

/**
* Create an MemoryImprint.Entry with a given trigger and a null build (missing).
*
* @param trigger the trigger
* @return an entry with the parameters.
*/
public static MemoryImprint.Entry createAndSetupMemoryImprintEntryWithEmptyBuild(GerritTrigger trigger) {
AbstractProject project = mock(AbstractProject.class);
setTrigger(trigger, project);
Expand Down

0 comments on commit 8364ddf

Please sign in to comment.