Skip to content

Commit

Permalink
Extract standard "Code review" & "Verified" labels
Browse files Browse the repository at this point in the history
- for reuse in global context
  • Loading branch information
shemuwel committed Dec 21, 2023
1 parent abfaa28 commit 9fe5b96
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import static com.sonymobile.tools.gerrit.gerritevents.watchdog.WatchTimeExceptionData.Time.MIN_HOUR;
import static com.sonymobile.tools.gerrit.gerritevents.watchdog.WatchTimeExceptionData.Time.MIN_MINUTE;
import static com.sonyericsson.hudson.plugins.gerrit.trigger.utils.StringUtil.PLUGIN_IMAGES_URL;

import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants;
import hudson.Extension;
import hudson.Functions;
import hudson.RelativePath;
Expand Down Expand Up @@ -467,8 +469,8 @@ public void start() {
categories = new LinkedList<VerdictCategory>();
}
if (categories.isEmpty()) {
categories.add(new VerdictCategory("Code-Review", "Code Review"));
categories.add(new VerdictCategory("Verified", "Verified"));
categories.add(new VerdictCategory(Constants.CODE_REVIEW_LABEL, Constants.CODE_REVIEW_LABEL));
categories.add(new VerdictCategory(Constants.VERIFIED_LABEL, Constants.VERIFIED_LABEL));
}
config.setCategories(categories);
gerritEventManager = PluginImpl.getHandler_();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ public final class Constants {
*/
public static final String TAG_VALUE = "autogenerated:jenkins-gerrit-trigger";

/**
* Code-Review review label
*/
public static final String CODE_REVIEW_LABEL = "Code-Review";

/**
* Verified review label
*/
public static final String VERIFIED_LABEL = "Verified";
/** Internal */
private Constants() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@
*/
public class BuildCompletedRestCommandJob extends AbstractRestCommandJob {

private static final String LABEL_CODEREVIEW = "Code-Review";
private static final String LABEL_VERIFIED = "Verified";

private final BuildMemory.MemoryImprint memoryImprint;
private final TaskListener listener;
private final ParameterExpander parameterExpander;
Expand Down Expand Up @@ -85,15 +82,15 @@ protected ReviewInput createReview() {
Integer crValue = parameterExpander.getMinimumCodeReviewValue(memoryImprint, true);
if (crValue != null && crValue != Integer.MAX_VALUE) {
scoredLabels.add(new ReviewLabel(
LABEL_CODEREVIEW,
Constants.CODE_REVIEW_LABEL,
crValue));
}
}
if (config.isRestVerified()) {
Integer verValue = parameterExpander.getMinimumVerifiedValue(memoryImprint, true, Integer.MAX_VALUE);
if (verValue != null && verValue != Integer.MAX_VALUE) {
scoredLabels.add(new ReviewLabel(
LABEL_VERIFIED,
Constants.VERIFIED_LABEL,
verValue));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@
*/
public class BuildStartedRestCommandJob extends AbstractRestCommandJob {


private static final String LABEL_CODEREVIEW = "Code-Review";
private static final String LABEL_VERIFIED = "Verified";

private final Run build;
private final BuildsStartedStats stats;
private final TaskListener listener;
Expand Down Expand Up @@ -92,15 +88,15 @@ protected ReviewInput createReview() {
Integer crValue = parameterExpander.getBuildStartedCodeReviewValue(build);
if (crValue != null && crValue != Integer.MAX_VALUE) {
scoredLabels.add(new ReviewLabel(
LABEL_CODEREVIEW,
Constants.CODE_REVIEW_LABEL,
crValue));
}
}
if (config.isRestVerified()) {
Integer verValue = parameterExpander.getBuildStartedVerifiedValue(build);
if (verValue != null && verValue != Integer.MAX_VALUE) {
scoredLabels.add(new ReviewLabel(
LABEL_VERIFIED,
Constants.VERIFIED_LABEL,
verValue));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer;
import com.sonyericsson.hudson.plugins.gerrit.trigger.Messages;
import com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.IGerritHudsonTriggerConfig;
import com.sonyericsson.hudson.plugins.gerrit.trigger.events.ManualPatchsetCreated;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTriggerParameters;
Expand Down Expand Up @@ -712,11 +713,11 @@ public static enum Approval {
/**
* A Code Review Approval type <i>Code-Review</i>.
*/
CODE_REVIEW("Code-Review"),
CODE_REVIEW(Constants.CODE_REVIEW_LABEL),
/**
* A Verified Approval type <i>Verified</i>.
*/
VERIFIED("Verified");
VERIFIED(Constants.VERIFIED_LABEL);
private String type;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer;
import com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Config;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.CompareType;
Expand Down Expand Up @@ -129,8 +130,8 @@ private void runTest() throws Exception {

j.assertStringContains(json.getString("message"), "Build Successful");
JSONObject labels = json.getJSONObject("labels");
assertEquals(1, labels.getInt("Code-Review"));
assertEquals(1, labels.getInt("Verified"));
assertEquals(1, labels.getInt(Constants.CODE_REVIEW_LABEL));
assertEquals(1, labels.getInt(Constants.VERIFIED_LABEL));
}
/**
* The test with a locked down instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer;
import com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Config;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.CompareType;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.GerritProject;
Expand Down Expand Up @@ -105,7 +106,7 @@ public void testTriggerWorkflow() throws Exception {
Assert.assertTrue(message.startsWith("Build Successful"));
Assert.assertTrue(message.contains("job/WFJob/1/"));
JSONObject labels = verifiedMessage.getJSONObject("labels");
assertEquals(1, labels.getInt("Verified"));
assertEquals(1, labels.getInt(Constants.VERIFIED_LABEL));
} finally {
gerritServer.stop();
}
Expand Down Expand Up @@ -145,7 +146,7 @@ public void testWorkflowStepSetsCustomUrl() throws Exception {
Assert.assertTrue(message.startsWith("Build Successful"));
Assert.assertTrue(message.contains("myCustomUrl"));
JSONObject labels = verifiedMessage.getJSONObject("labels");
assertEquals(1, labels.getInt("Verified"));
assertEquals(1, labels.getInt(Constants.VERIFIED_LABEL));
} finally {
gerritServer.stop();
}
Expand Down Expand Up @@ -187,7 +188,7 @@ public void testWorkflowStepSetsUnsuccessfulMessage() throws Exception {
Assert.assertTrue(message.startsWith("Build Failed"));
Assert.assertTrue(message.contains("myMessage"));
JSONObject labels = verifiedMessage.getJSONObject("labels");
assertEquals(0, labels.getInt("Verified"));
assertEquals(0, labels.getInt(Constants.VERIFIED_LABEL));
} finally {
gerritServer.stop();
}
Expand Down Expand Up @@ -228,7 +229,7 @@ public void testWorkflowStepSetsUnsuccessfulMessageWithSuccessfulBuild() throws
Assert.assertTrue(message.startsWith("Build Successful"));
Assert.assertFalse(message.contains("myMessage"));
JSONObject labels = verifiedMessage.getJSONObject("labels");
assertEquals(1, labels.getInt("Verified"));
assertEquals(1, labels.getInt(Constants.VERIFIED_LABEL));
} finally {
gerritServer.stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static org.mockito.Mockito.any;
import com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer;
import com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants;
import com.sonyericsson.hudson.plugins.gerrit.trigger.mock.Setup;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
Expand Down Expand Up @@ -66,19 +67,19 @@ public void testGetCodeReview() throws Exception {

JSONArray approvals = new JSONArray();
JSONObject crw = new JSONObject();
crw.put("type", "Code-Review");
crw.put("type", Constants.CODE_REVIEW_LABEL);
crw.put("value", "2");
approvals.add(crw);
crw = new JSONObject();
crw.put("type", "Code-Review");
crw.put("type", Constants.CODE_REVIEW_LABEL);
crw.put("value", "1");
approvals.add(crw);
crw = new JSONObject();
crw.put("type", "Verified");
crw.put("type", Constants.VERIFIED_LABEL);
crw.put("value", "1");
approvals.add(crw);
crw = new JSONObject();
crw.put("type", "Code-Review");
crw.put("type", Constants.CODE_REVIEW_LABEL);
crw.put("value", "-1");
approvals.add(crw);
currentPatchSet.put("approvals", approvals);
Expand Down Expand Up @@ -128,19 +129,19 @@ public void testGetVerified() throws Exception {

JSONArray approvals = new JSONArray();
JSONObject crw = new JSONObject();
crw.put("type", "Verified");
crw.put("type", Constants.VERIFIED_LABEL);
crw.put("value", "2");
approvals.add(crw);
crw = new JSONObject();
crw.put("type", "Verified");
crw.put("type", Constants.VERIFIED_LABEL);
crw.put("value", "1");
approvals.add(crw);
crw = new JSONObject();
crw.put("type", "Code-Review");
crw.put("type", Constants.CODE_REVIEW_LABEL);
crw.put("value", "1");
approvals.add(crw);
crw = new JSONObject();
crw.put("type", "Verified");
crw.put("type", Constants.VERIFIED_LABEL);
crw.put("value", "-1");
approvals.add(crw);
currentPatchSet.put("approvals", approvals);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package com.sonyericsson.hudson.plugins.gerrit.trigger.mock;

import com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.CompareType;
Expand Down Expand Up @@ -158,7 +159,7 @@ public static FreeStyleProject createGerritTriggeredJobForCommentAdded(JenkinsRu
List<GerritProject> projects = new LinkedList<GerritProject>();
projects.add(new GerritProject(CompareType.ANT, "**",
Collections.singletonList(new Branch(CompareType.ANT, "**")), null, null, null, false));
PluginCommentAddedEvent event = new PluginCommentAddedEvent("Code-Review", "1");
PluginCommentAddedEvent event = new PluginCommentAddedEvent(Constants.CODE_REVIEW_LABEL, "1");
List<PluginGerritEvent> list = new LinkedList<PluginGerritEvent>();
list.add(event);
p.addTrigger(new GerritTrigger(projects, null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package com.sonyericsson.hudson.plugins.gerrit.trigger.mock;

import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTriggerDescriptor;
import com.sonymobile.tools.gerrit.gerritevents.dto.attr.Account;
import com.sonymobile.tools.gerrit.gerritevents.dto.attr.Approval;
Expand Down Expand Up @@ -497,7 +498,7 @@ public static CommentAdded createCommentAdded() {
event.setPatchset(patch);
List<Approval> approvals = new LinkedList<Approval>();
Approval approval = new Approval();
approval.setType("Code-Review");
approval.setType(Constants.CODE_REVIEW_LABEL);
approval.setValue("1");
approvals.add(approval);
event.setApprovals(approvals);
Expand Down Expand Up @@ -722,7 +723,7 @@ public static ToGerritRunListener createFailureMessageRunListener(final Abstract
* @return the List.
*/
public static List<VerdictCategory> createCodeReviewVerdictCategoryList() {
VerdictCategory cat = new VerdictCategory("Code-Review", "Code review");
VerdictCategory cat = new VerdictCategory(Constants.CODE_REVIEW_LABEL, Constants.CODE_REVIEW_LABEL);
List<VerdictCategory> list = new LinkedList<VerdictCategory>();
list.add(cat);
return list;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package com.sonyericsson.hudson.plugins.gerrit.trigger.project;

import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants;
import org.htmlunit.html.DomElement;
import org.htmlunit.html.HtmlElement;
import org.htmlunit.html.HtmlPage;
Expand Down Expand Up @@ -82,7 +83,7 @@ public void testPopulateDropDown() throws Exception {
final List<HtmlElement> elements = page.getDocumentElement()
.getElementsByAttribute("select", "name", "_.verdictCategory");
assertThat(elements, hasSize(1));
List<String> expected = Arrays.asList("Verified", "Code-Review");
List<String> expected = Arrays.asList(Constants.VERIFIED_LABEL, Constants.CODE_REVIEW_LABEL);
verifyOptions((HtmlSelect)elements.get(0), expected);
}
}
Expand Down Expand Up @@ -115,7 +116,7 @@ public void testPopulateDropDownFromTwoServers() throws Exception {
final List<HtmlElement> elements = page.getDocumentElement()
.getElementsByAttribute("select", "name", "_.verdictCategory");
assertThat(elements, hasSize(1));
List<String> expected = Arrays.asList("Verified", "Code-Review", "Code-Review2", "Verified2");
List<String> expected = Arrays.asList(Constants.VERIFIED_LABEL, Constants.CODE_REVIEW_LABEL, "Code-Review2", "Verified2");
verifyOptions((HtmlSelect)elements.get(0), expected);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer;
import com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTriggerParameters;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch;
Expand Down Expand Up @@ -368,7 +369,7 @@ public void testCommitMessageParameterModeNone() throws Exception {
@Test
public void testCommentTextParameterModeDefault() throws Exception {
assertSame(GerritTriggerParameters.ParameterMode.BASE64, trigger.getCommentTextParameterMode());
trigger.getTriggerOnEvents().add(new PluginCommentAddedEvent("Code-Review", "1"));
trigger.getTriggerOnEvents().add(new PluginCommentAddedEvent(Constants.CODE_REVIEW_LABEL, "1"));
String expected = "Triggering comment";
CommentAdded event = Setup.createCommentAdded();
event.setComment(expected);
Expand All @@ -390,7 +391,7 @@ public void testCommentTextParameterModeDefault() throws Exception {
@Test
public void testCommentTextParameterModePlain() throws Exception {
trigger.setCommentTextParameterMode(GerritTriggerParameters.ParameterMode.PLAIN);
trigger.getTriggerOnEvents().add(new PluginCommentAddedEvent("Code-Review", "1"));
trigger.getTriggerOnEvents().add(new PluginCommentAddedEvent(Constants.CODE_REVIEW_LABEL, "1"));
String expected = "Triggering comment";
CommentAdded event = Setup.createCommentAdded();
event.setComment(expected);
Expand All @@ -412,7 +413,7 @@ public void testCommentTextParameterModePlain() throws Exception {
@Test
public void testCommentTextParameterModeNone() throws Exception {
trigger.setCommentTextParameterMode(GerritTriggerParameters.ParameterMode.NONE);
trigger.getTriggerOnEvents().add(new PluginCommentAddedEvent("Code-Review", "1"));
trigger.getTriggerOnEvents().add(new PluginCommentAddedEvent(Constants.CODE_REVIEW_LABEL, "1"));
String expected = "Triggering comment";
CommentAdded event = Setup.createCommentAdded();
event.setComment(expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer;
import com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Config;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.CompareType;
Expand Down Expand Up @@ -68,7 +69,7 @@ private FreeStyleProject createJob(String pattern) throws IOException {
job.getBuildersList().add(new ParametersBuilder());
GerritTrigger trigger = Setup.createDefaultTrigger(job);
trigger.setTopicAssociation(new TopicAssociation());
trigger.getTriggerOnEvents().add(new PluginCommentAddedEvent("Code-Review", "1"));
trigger.getTriggerOnEvents().add(new PluginCommentAddedEvent(Constants.CODE_REVIEW_LABEL, "1"));
trigger.setGerritProjects(Collections.singletonList(new GerritProject(CompareType.ANT, pattern,
Collections.singletonList(new Branch(CompareType.ANT, "**")),
Collections.emptyList(), Collections.emptyList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer;
import com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Config;
import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Constants;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.CompareType;
Expand Down Expand Up @@ -67,7 +68,7 @@ private FreeStyleProject createJob(String pattern) throws IOException {

GerritTrigger trigger = Setup.createDefaultTrigger(job);
trigger.setTopicAssociation(new TopicAssociation());
trigger.getTriggerOnEvents().add(new PluginCommentAddedEvent("Code-Review", "1"));
trigger.getTriggerOnEvents().add(new PluginCommentAddedEvent(Constants.CODE_REVIEW_LABEL, "1"));
trigger.setGerritProjects(Collections.singletonList(new GerritProject(CompareType.ANT, pattern,
Collections.singletonList(new Branch(CompareType.ANT, "**")),
Collections.<Topic>emptyList(), Collections.<FilePath>emptyList(),
Expand Down
Loading

0 comments on commit 9fe5b96

Please sign in to comment.