Use '-' instead of spaces for owners label

Gerrit v2.16 has a stricter label checkers that doesn't allow
spaces in returned values of a submit record.

Uses the standard '-' so that owners rules can generate valid
submit records rendered in the UI.

Change-Id: If4cdb7e13c5bc322e591723d42ecd4d94ee26587
diff --git a/owners/src/main/java/gerrit_owners/PRED_file_owners_2.java b/owners/src/main/java/gerrit_owners/PRED_file_owners_2.java
index a5effb4..4e7263a 100644
--- a/owners/src/main/java/gerrit_owners/PRED_file_owners_2.java
+++ b/owners/src/main/java/gerrit_owners/PRED_file_owners_2.java
@@ -76,7 +76,7 @@
     }
     Account account = user.asIdentifiedUser().state().getAccount();
     String userName = account.getFullName();
-    return userName;
+    return sanitizeAsSubmitLabel(userName);
   }
 
   public Term createFormattedList(Prolog engine, Term key) {
@@ -86,9 +86,13 @@
         iteratorStream(owners.getFileOwners().get(path).iterator())
             .map(id -> getFullNameFromId(engine, id))
             .collect(Collectors.toSet());
-    String ownVerb = ownersNames.size() > 1 ? " own " : " owns ";
-    String userNames = ownersNames.stream().collect(Collectors.joining(", "));
-    return SymbolTerm.create(userNames + ownVerb + (new File(path)).getName());
+    String ownVerb = ownersNames.size() > 1 ? "-own-" : "-owns-";
+    String userNames = ownersNames.stream().collect(Collectors.joining("-"));
+    return SymbolTerm.create(userNames + ownVerb + sanitizeAsSubmitLabel(new File(path).getName()));
+  }
+
+  private String sanitizeAsSubmitLabel(String anyLabelPart) {
+    return anyLabelPart.replaceAll("[\\s_\\.]+", "-");
   }
 
   private static IdentifiedUser.GenericFactory userFactory(Prolog engine) {
diff --git a/owners/src/main/prolog/gerrit_owners.pl b/owners/src/main/prolog/gerrit_owners.pl
index 157f0b6..1fe2a22 100644
--- a/owners/src/main/prolog/gerrit_owners.pl
+++ b/owners/src/main/prolog/gerrit_owners.pl
@@ -24,7 +24,7 @@
 add_owner_approval(In, Out) :-
   owner_path(Path),
   \+ owner_approved(Path),
-  Out = [label('Code-Review from owners', need(_)) | In],
+  Out = [label('Code-Review-from-owners', need(_)) | In],
   !.
 
 add_owner_approval(In, Out) :- In = Out.
@@ -32,7 +32,7 @@
 add_owner_approval(Users, In, Out) :-
   owner_path(Path),
   \+ owner_approved(Users, Path),
-  Out = [label('Code-Review from owners', need(_)) | In],
+  Out = [label('Code-Review-from-owners', need(_)) | In],
   !.
 
 add_owner_approval(_, In, Out) :- In = Out.
@@ -67,7 +67,7 @@
     findall(US,code_review_user(US),Approvers),
     matcher_needed(Approvers,P,W),
     \+ W == [],
-    Out = [label('Code-Review from owners', need(_)) | In], !.
+    Out = [label('Code-Review-from-owners', need(_)) | In], !.
 
 add_match_owner_approval(In,Out) :- Out = In.