My favorites
▼
|
Sign in
gerrit
Gerrit Code Review
Project Home
Downloads
Wiki
Issues
Source
Export to GitHub
New issue
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
757
attachment: SumWithBlock.patch
(3.2 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
commit 3f54b2dc3539983b002802bc8e4e548a9c2497ad
Author: Boris
Date: Fri Apr 1 14:43:08 2011 +0200
added SumWithBlock to workflows
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/workflow/CategoryFunction.java b/gerrit-server/src/main/java/com/google/gerrit/server/workflow/CategoryFunction.java
index 6700393..d1a3f686 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/workflow/CategoryFunction.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/workflow/CategoryFunction.java
@@ -31,6 +31,7 @@ public abstract class CategoryFunction {
static {
all.put(SubmitFunction.NAME, new SubmitFunction());
all.put(MaxWithBlock.NAME, new MaxWithBlock());
+ all.put(SumWithBlock.NAME, new SumWithBlock());
all.put(MaxNoBlock.NAME, new MaxNoBlock());
all.put(NoOpFunction.NAME, new NoOpFunction());
all.put(NoBlock.NAME, new NoBlock());
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/workflow/SumWithBlock.java b/gerrit-server/src/main/java/com/google/gerrit/server/workflow/SumWithBlock.java
new file mode 100644
index 0000000..fa810f2
--- /dev/null
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/workflow/SumWithBlock.java
@@ -0,0 +1,57 @@
+// Copyright (C) 2008 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.server.workflow;
+
+import com.google.gerrit.common.data.ApprovalType;
+import com.google.gerrit.reviewdb.ApprovalCategory;
+import com.google.gerrit.reviewdb.PatchSetApproval;
+
+/**
+ * Computes an {@link ApprovalCategory} by looking at the sum of values.
+ * <p>
+ * In order to be considered "approved" this function requires that
+ * <ul>
+ * <li>The maximum negative value is never used;</li>
+ * <li>The sum of all votes is larger than two.</li>
+ * <p>
+ * This function is primarily useful for review fields, with values such as:
+ * <ul>
+ * <li>+1: Vote for approval.</li>
+ * <li>-1: Vote for rejection.</li>
+ * <li>-2: Rejected, must not be submitted.</li>
+ * </ul>
+ * where developers can vote for a change without having to give single devs the
+ * right to merge changes on their own.
+ */
+public class SumWithBlock extends CategoryFunction {
+ public static String NAME = "SumWithBlock";
+
+ @Override
+ public void run(final ApprovalType at, final FunctionState state) {
+ int sum = 0;
+ boolean rejected = false;
+ for (final PatchSetApproval a : state.getApprovals(at)) {
+ state.normalize(at, a);
+
+ sum += a.getValue();
+ rejected |= at.isMaxNegative(a);
+ }
+
+ // The type must not have had its max negative (a forceful reject)
+ // and must have at least a sum of two
+ //
+ state.valid(at, !rejected && sum >= 2);
+ }
+}
Powered by
Google Project Hosting