Fix file path of weblinks for code owner config files

When creating weblinks we need to pass in the file path without any
leading slash.

Bug: Google b/345161989
Change-Id: I63981d439c4a4cff569e7a32ba7b2ee7640c243e
Signed-off-by: Edwin Kempin <ekempin@google.com>
diff --git a/java/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerConfigFileJson.java b/java/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerConfigFileJson.java
index ed59a8e..9dedada 100644
--- a/java/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerConfigFileJson.java
+++ b/java/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerConfigFileJson.java
@@ -24,6 +24,7 @@
 import com.google.gerrit.plugins.codeowners.backend.CodeOwnerConfig;
 import com.google.gerrit.plugins.codeowners.backend.CodeOwnerConfigImport;
 import com.google.gerrit.plugins.codeowners.backend.UnresolvedImportFormatter;
+import com.google.gerrit.plugins.codeowners.util.JgitPath;
 import com.google.gerrit.server.WebLinks;
 import com.google.inject.Inject;
 import java.util.List;
@@ -63,7 +64,10 @@
 
     ImmutableList<WebLinkInfo> fileLinks =
         webLinks.getFileLinks(
-            info.project, info.branch, codeOwnerConfig.revision().getName(), info.path);
+            info.project,
+            info.branch,
+            codeOwnerConfig.revision().getName(),
+            JgitPath.of(info.path).get());
     info.webLinks = !fileLinks.isEmpty() ? fileLinks : null;
 
     return info;
diff --git a/javatests/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerConfigFileJsonIT.java b/javatests/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerConfigFileJsonIT.java
index fa1d9c8..615a3dd 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerConfigFileJsonIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerConfigFileJsonIT.java
@@ -557,11 +557,16 @@
   }
 
   private WebLinkInfo createWebLink(CodeOwnerConfig codeOwnerConfig) {
+    String path = codeOwnerConfigOperations.codeOwnerConfig(codeOwnerConfig.key()).getFilePath();
+    if (path.startsWith("/")) {
+      path = path.substring(1);
+    }
+
     return createWebLink(
         codeOwnerConfig.key().project().get(),
         codeOwnerConfig.key().branchNameKey().branch(),
         codeOwnerConfig.revision().getName(),
-        codeOwnerConfigOperations.codeOwnerConfig(codeOwnerConfig.key()).getFilePath());
+        path);
   }
 
   private WebLinkInfo createWebLink(