Merge branch 'stable-2.16' into stable-3.0

* stable-2.16:
  Do not reject commit upon connectivity problems

Change-Id: Ie4a844b61782f0b8118d0014696ad933a60820a2
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/its/InitIts.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/its/InitIts.java
index 9fb2b3d..fbb6e39 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/its/InitIts.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/its/InitIts.java
@@ -15,7 +15,7 @@
 package com.googlesource.gerrit.plugins.its.base.its;
 
 import com.google.common.base.Strings;
-import com.google.gerrit.common.data.RefConfigSection;
+import com.google.gerrit.common.data.AccessSection;
 import com.google.gerrit.pgm.init.api.AllProjectsConfig;
 import com.google.gerrit.pgm.init.api.AllProjectsNameOnInitProvider;
 import com.google.gerrit.pgm.init.api.ConsoleUI;
@@ -140,7 +140,7 @@
               branch,
               "Branches for which the issue tracker integration"
                   + " should be enabled (ref, ref pattern or regular expression)");
-      validRef = RefConfigSection.isValid(v);
+      validRef = AccessSection.isValidRefSectionName(v);
       if (validRef) {
         branch = v;
       } else {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/its/ItsConfig.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/its/ItsConfig.java
index 552065e..6a5eda4 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/its/ItsConfig.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/its/ItsConfig.java
@@ -16,7 +16,7 @@
 
 import static java.util.stream.Collectors.toList;
 
-import com.google.gerrit.common.data.RefConfigSection;
+import com.google.gerrit.common.data.AccessSection;
 import com.google.gerrit.extensions.annotations.PluginName;
 import com.google.gerrit.extensions.api.projects.CommentLinkInfo;
 import com.google.gerrit.reviewdb.client.Project;
@@ -134,7 +134,7 @@
       return true;
     }
     for (String refPattern : refPatterns) {
-      if (RefConfigSection.isValid(refPattern) && match(refName, refPattern)) {
+      if (AccessSection.isValidRefSectionName(refPattern) && match(refName, refPattern)) {
         return true;
       }
     }
@@ -182,8 +182,7 @@
    */
   public Pattern getIssuePattern() {
     Optional<String> match =
-        getCommentLinkInfo(getCommentLinkName())
-            .stream()
+        getCommentLinkInfo(getCommentLinkName()).stream()
             .filter(input -> input.match != null && !input.match.trim().isEmpty())
             .map(input -> input.match)
             .reduce((a, b) -> b);
@@ -268,8 +267,7 @@
     NameKey projectName = currentProjectName.get();
     if (projectName != null) {
       List<CommentLinkInfo> commentlinks = projectCache.get(projectName).getCommentLinks();
-      return commentlinks
-          .stream()
+      return commentlinks.stream()
           .filter(input -> input.name.equals(commentlinkName))
           .collect(toList());
     }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/util/CommitMessageFetcher.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/util/CommitMessageFetcher.java
index 905a2a3..7049e51 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/util/CommitMessageFetcher.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/util/CommitMessageFetcher.java
@@ -1,6 +1,6 @@
 package com.googlesource.gerrit.plugins.its.base.util;
 
-import com.google.gerrit.reviewdb.client.Project.NameKey;
+import com.google.gerrit.reviewdb.client.Project;
 import com.google.gerrit.server.git.GitRepositoryManager;
 import com.google.inject.Inject;
 import java.io.IOException;
@@ -22,7 +22,7 @@
   }
 
   public String fetch(String projectName, String commitId) throws IOException {
-    try (Repository repo = repoManager.openRepository(new NameKey(projectName))) {
+    try (Repository repo = repoManager.openRepository(Project.nameKey(projectName))) {
       try (RevWalk revWalk = new RevWalk(repo)) {
         RevCommit commit = revWalk.parseCommit(ObjectId.fromString(commitId));
         return commit.getFullMessage();
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/util/ItsProjectExtractor.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/util/ItsProjectExtractor.java
index e872f8d..734582a 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/util/ItsProjectExtractor.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/util/ItsProjectExtractor.java
@@ -29,6 +29,6 @@
   }
 
   public Optional<String> getItsProject(String gerritProjectName) {
-    return itsConfig.getItsProjectName(new Project.NameKey(gerritProjectName));
+    return itsConfig.getItsProjectName(Project.nameKey(gerritProjectName));
   }
 }
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 f87f7b5..f1b2c0d 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;
@@ -86,10 +87,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/java/com/googlesource/gerrit/plugins/its/base/workflow/ActionExecutor.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/ActionExecutor.java
index 355d1f3..33e82ae 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/ActionExecutor.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/ActionExecutor.java
@@ -80,7 +80,7 @@
   private void execute(
       Action action, String target, ActionRequest actionRequest, Map<String, String> properties)
       throws IOException {
-    ItsFacade its = itsFactory.getFacade(new Project.NameKey(properties.get("project")));
+    ItsFacade its = itsFactory.getFacade(Project.nameKey(properties.get("project")));
     action.execute(its, target, actionRequest, properties);
   }
 
@@ -89,7 +89,7 @@
     try {
       Action action = getAction(actionRequest.getName());
       if (action == null) {
-        ItsFacade its = itsFactory.getFacade(new Project.NameKey(properties.get("project")));
+        ItsFacade its = itsFactory.getFacade(Project.nameKey(properties.get("project")));
         its.performAction(issue, actionRequest.getUnparsed());
       } else if (action.getType() == ActionType.ISSUE) {
         execute(action, issue, actionRequest, properties);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/ItsRulesProjectCacheImpl.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/ItsRulesProjectCacheImpl.java
index 7e37397..14307a0 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/ItsRulesProjectCacheImpl.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/ItsRulesProjectCacheImpl.java
@@ -98,7 +98,7 @@
 
     @Override
     public List<Rule> load(String projectName) throws IOException {
-      ProjectState project = projectCache.checkedGet(new Project.NameKey(projectName));
+      ProjectState project = projectCache.checkedGet(Project.nameKey(projectName));
       List<Rule> projectRules = readRulesFrom(project);
       if (projectRules.isEmpty()) {
         for (ProjectState parent : project.parents()) {
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 3e61bc1..df88c2f 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
@@ -260,7 +260,7 @@
     RefUpdateAttribute refUpdateAttribute = new RefUpdateAttribute();
     refUpdateAttribute.newRev = "1234567891123456789212345678931234567894";
     refUpdateAttribute.oldRev = "9876543211987654321298765432139876543214";
-    refUpdateAttribute.refName = "testRef";
+    refUpdateAttribute.refName = "refs/heads/master";
 
     replayMocks();
 
@@ -272,7 +272,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);
   }