Add refSuffix and refPrefix properties to RefUpdatedEvent

Those new properties can be used as values or conditions.

They can be combined to manage ITS issue fix versions.
On git tag event, we would add the tag name to the ITS issue
fix versions. We could build the following rule:

[rule "add-fixed-version"]
        event-type = ref-updated
        refPrefix = refs/tags/
        action = add-property-to-field refSuffix fixVersions

Here refPrefix would allow to filter only git tag creation
(i.e. filtering out branch creation) and refSuffix would contain
the short tag name to use as the fix version in the ITS issue.

Change-Id: I166fbacdafa341a48fb1680f73e4064f166b72b7
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/util/PropertyAttributeExtractor.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/util/PropertyAttributeExtractor.java
index 2a72273..e85ec6a 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/util/PropertyAttributeExtractor.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/util/PropertyAttributeExtractor.java
@@ -15,6 +15,7 @@
 package com.googlesource.gerrit.plugins.its.base.util;
 
 import com.google.common.collect.ImmutableMap;
+import com.google.gerrit.reviewdb.client.RefNames;
 import com.google.gerrit.server.data.AccountAttribute;
 import com.google.gerrit.server.data.ApprovalAttribute;
 import com.google.gerrit.server.data.ChangeAttribute;
@@ -80,10 +81,14 @@
   }
 
   Map<String, String> extractFrom(RefUpdateAttribute refUpdateAttribute) {
+    String refName = refUpdateAttribute.refName;
+    String refShortName = RefNames.shortName(refName);
     return ImmutableMap.<String, String>builder()
         .put("revision", refUpdateAttribute.newRev)
         .put("revisionOld", refUpdateAttribute.oldRev)
         .put("ref", refUpdateAttribute.refName)
+        .put("refSuffix", refShortName)
+        .put("refPrefix", refName.substring(0, refName.length() - refShortName.length()))
         .build();
   }
 
diff --git a/src/main/resources/Documentation/config-rulebase-common.md b/src/main/resources/Documentation/config-rulebase-common.md
index 17baf77..d232e57 100644
--- a/src/main/resources/Documentation/config-rulebase-common.md
+++ b/src/main/resources/Documentation/config-rulebase-common.md
@@ -425,8 +425,15 @@
 : full name of the project from which a ref was updated.
 
 `ref`
-: git ref that has been updated (Typcially the branch, as for example
-  `master`).
+: git ref that has been updated (Typically the branch, as for example
+  `refs/heads/master`).
+
+`refSuffix`
+: short name of the git ref that has been updated (Typically the branch or the
+tag, as for example `master`).
+
+`refPrefix`
+: prefix of the git ref that has been updated (Example for a branch `refs/heads/`).
 
 `revision`
 : git commit hash the rev is pointing to now.
diff --git a/src/test/java/com/googlesource/gerrit/plugins/its/base/util/PropertyAttributeExtractorTest.java b/src/test/java/com/googlesource/gerrit/plugins/its/base/util/PropertyAttributeExtractorTest.java
index 721e788..1734126 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/its/base/util/PropertyAttributeExtractorTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/its/base/util/PropertyAttributeExtractorTest.java
@@ -215,7 +215,7 @@
     RefUpdateAttribute refUpdateAttribute = new RefUpdateAttribute();
     refUpdateAttribute.newRev = "1234567891123456789212345678931234567894";
     refUpdateAttribute.oldRev = "9876543211987654321298765432139876543214";
-    refUpdateAttribute.refName = "testRef";
+    refUpdateAttribute.refName = "refs/heads/master";
 
     replayMocks();
 
@@ -227,7 +227,9 @@
         new ImmutableMap.Builder<String, String>()
             .put("revision", "1234567891123456789212345678931234567894")
             .put("revisionOld", "9876543211987654321298765432139876543214")
-            .put("ref", "testRef")
+            .put("ref", "refs/heads/master")
+            .put("refSuffix", "master")
+            .put("refPrefix", "refs/heads/")
             .build();
     assertEquals("Properties do not match", expected, actual);
   }