Skip to content

Commit

Permalink
Move build status votes in VerdictCategory
Browse files Browse the repository at this point in the history
- moved build status votes fields to VerdictCategory instead of having
them as private fields in Config/GerritTrigger & mark their
getters/setters deprecated
- remove the entries for the removed status votes from jelly
gerrit-trigger config & add them in VerdictCategory list
instead (all the votes are set within VerdictCategory)
- votes are now part of the VerdictCategory list (categories) so all
deprecated methods are now searching through the list instead
  • Loading branch information
Samuel Dolean authored and shemuwel committed Dec 21, 2023
1 parent 66e67f3 commit 7e32a94
Show file tree
Hide file tree
Showing 13 changed files with 782 additions and 461 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,97 @@
*/
package com.sonyericsson.hudson.plugins.gerrit.trigger;

import com.sonyericsson.hudson.plugins.gerrit.trigger.config.BuildStatus;
import hudson.Extension;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.DataBoundConstructor;

import static com.sonyericsson.hudson.plugins.gerrit.trigger.utils.StringUtil.*;

/**
* A verdict category for setting comments in Gerrit, i.e. code-review, verify
* @author Tomas Westling <[email protected]>
*/
public class VerdictCategory extends AbstractDescribableImpl<VerdictCategory> {
public class VerdictCategory extends AbstractDescribableImpl<VerdictCategory> implements Cloneable {

private String verdictValue;
private String verdictDescription;
private final String verdictValue;
private final String verdictDescription;
private Integer buildStartedVote;
private Integer buildSuccessfulVote;
private Integer buildFailedVote;
private Integer buildUnstableVote;
private Integer buildNotBuiltVote;
private Integer buildAbortedVote;

/**
* Standard constructor.
* @param verdictValue the value in Gerrit for the verdict category.
* @param verdictDescription the text describing the verdict category.
* @param buildStartedVote the vote value for when the build has started.
* @param buildSuccessfulVote the vote value for when the build has been successful.
* @param buildFailedVote the vote value for when the build has failed.
* @param buildUnstableVote the vote value for when the build has been unstable.
* @param buildNotBuiltVote the vote value for when the build has not been built.
* @param buildAbortedVote the vote value for when the build has been aborted.
*/
@DataBoundConstructor
public VerdictCategory(String verdictValue, String verdictDescription) {
public VerdictCategory(String verdictValue,
String verdictDescription,
Integer buildStartedVote,
Integer buildSuccessfulVote,
Integer buildFailedVote,
Integer buildUnstableVote,
Integer buildNotBuiltVote,
Integer buildAbortedVote) {
this(verdictValue, verdictDescription);

this.buildStartedVote = buildStartedVote;
this.buildSuccessfulVote = buildSuccessfulVote;
this.buildFailedVote = buildFailedVote;
this.buildUnstableVote = buildUnstableVote;
this.buildNotBuiltVote = buildNotBuiltVote;
this.buildAbortedVote = buildAbortedVote;
}

/**
* Standard constructor
* @param verdictValue the value in Gerrit for the verdict category.
* @param verdictDescription the text describing the verdict category.
*/
public VerdictCategory(String verdictValue,
String verdictDescription) {
this.verdictValue = verdictValue;
this.verdictDescription = verdictDescription;
}

/**
* Creates a VerdictCategory from a JSONObject.
* @param obj the JSONObject.
* @return a VerdictCategory.
*/
public static VerdictCategory fromJSON(JSONObject obj) {
String value = obj.getString("verdictValue");
String description = obj.getString("verdictDescription");

Integer buildStartedVote = getValueFromFormData(obj, "buildStartedVote");
Integer buildSuccessfulVote = getValueFromFormData(obj, "buildSuccessfulVote");
Integer buildFailedVote = getValueFromFormData(obj, "buildFailedVote");
Integer buildUnstableVote = getValueFromFormData(obj, "buildUnstableVote");
Integer buildNotBuiltVote = getValueFromFormData(obj, "buildNotBuiltVote");
Integer buildAbortedVote = getValueFromFormData(obj, "buildAbortedVote");

return new VerdictCategory(value,
description,
buildStartedVote,
buildSuccessfulVote,
buildFailedVote,
buildUnstableVote,
buildNotBuiltVote,
buildAbortedVote);
}

/**
* Standard getter for the value.
* @return the value.
Expand All @@ -65,17 +130,111 @@ public String getVerdictDescription() {
return verdictDescription;
}

/**
* Creates a VerdictCategory from a JSONObject.
* @param obj the JSONObject.
* @return a VerdictCategory.
*/
public static VerdictCategory createVerdictCategoryFromJSON(JSONObject obj) {
String value = obj.getString("verdictValue");
String description = obj.getString("verdictDescription");
return new VerdictCategory(value, description);
public Integer getBuildStartedVote() {
return buildStartedVote;
}

public void setBuildStartedVote(Integer buildStartedVote) {
this.buildStartedVote = buildStartedVote;
}

public Integer getBuildSuccessfulVote() {
return buildSuccessfulVote;
}

public void setBuildSuccessfulVote(Integer buildSuccessfulVote) {
this.buildSuccessfulVote = buildSuccessfulVote;
}

public Integer getBuildFailedVote() {
return buildFailedVote;
}

public void setBuildFailedVote(Integer buildFailedVote) {
this.buildFailedVote = buildFailedVote;
}

public Integer getBuildUnstableVote() {
return buildUnstableVote;
}

public void setBuildUnstableVote(Integer buildUnstableVote) {
this.buildUnstableVote = buildUnstableVote;
}

public Integer getBuildNotBuiltVote() {
return buildNotBuiltVote;
}

public void setBuildNotBuiltVote(Integer buildNotBuiltVote) {
this.buildNotBuiltVote = buildNotBuiltVote;
}

public Integer getBuildAbortedVote() {
return buildAbortedVote;
}

public void setBuildAbortedVote(Integer buildAbortedVote) {
this.buildAbortedVote = buildAbortedVote;
}

@Override
public VerdictCategory clone() {
return new VerdictCategory(verdictValue,
verdictDescription,
buildStartedVote,
buildSuccessfulVote,
buildFailedVote,
buildUnstableVote,
buildNotBuiltVote,
buildAbortedVote);
}

public Integer getVerdictVote(BuildStatus status) {
switch (status) {
case STARTED:
return buildStartedVote;
case SUCCESSFUL:
return buildSuccessfulVote;
case FAILED:
return buildFailedVote;
case UNSTABLE:
return buildUnstableVote;
case NOT_BUILT:
return buildNotBuiltVote;
case ABORTED:
return buildAbortedVote;
default:
return null;
}
}

public void setVerdictVote(BuildStatus status, Integer vote) {
switch (status) {
case STARTED:
buildStartedVote = vote;
break;
case SUCCESSFUL:
buildSuccessfulVote = vote;
break;
case FAILED:
buildFailedVote = vote;
break;
case UNSTABLE:
buildUnstableVote = vote;
break;
case NOT_BUILT:
buildNotBuiltVote = vote;
break;
case ABORTED:
buildAbortedVote = vote;
break;
default:
break;
}
}


/**
* The Descriptor for a VerdictCategory.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.sonyericsson.hudson.plugins.gerrit.trigger.config;

public enum BuildStatus {
STARTED,
SUCCESSFUL,
FAILED,
UNSTABLE,
NOT_BUILT,
ABORTED,
NOT_REGISTERED;
}
Loading

0 comments on commit 7e32a94

Please sign in to comment.