From f19906ab27500dc0fb18539f38aa72d255ba76c8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= <skunk@xover.mud.at>
Date: Thu, 11 Jan 2018 20:57:01 +0100
Subject: [PATCH] Repositories: improve configuration of gitea - declare path
 and url

---
 conf.php-dist        |  5 ++++-
 src/repositories.php | 17 +++++++++++------
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/conf.php-dist b/conf.php-dist
index d053c2f2..d0339532 100644
--- a/conf.php-dist
+++ b/conf.php-dist
@@ -15,7 +15,10 @@ $repositories = array(
 );
 
 // Repositories which should be included from gitea
-$repositoriesGitea = "/home/gitea/gitea-repositories";
+$repositoriesGitea = array(
+  'path' => "/home/gitea/gitea-repositories",
+  'url' => "https://www.openstreetbrowser.org/dev",
+);
 
 // Set to true to reload categories on every page visit.
 $config['categoriesAlwaysReload'] = true;
diff --git a/src/repositories.php b/src/repositories.php
index 4bf761f3..07a47532 100644
--- a/src/repositories.php
+++ b/src/repositories.php
@@ -16,20 +16,25 @@ function getRepositories () {
   }
 
   if (isset($repositoriesGitea)) {
-    $d1 = opendir($repositoriesGitea);
+    $d1 = opendir($repositoriesGitea['path']);
     while ($f1 = readdir($d1)) {
       if (substr($f1, 0, 1) !== '.') {
-        $d2 = opendir("{$repositoriesGitea}/{$f1}");
+        $d2 = opendir("{$repositoriesGitea['path']}/{$f1}");
         while ($f2 = readdir($d2)) {
           if (substr($f2, 0, 1) !== '.') {
             $f2id = substr($f2, 0, -4);
 
-            $result["{$f1}/{$f2id}"] = array(
-              'path' => "{$repositoriesGitea}/{$f1}/{$f2}",
+            $r = array(
+              'path' => "{$repositoriesGitea['path']}/{$f1}/{$f2}",
               'type' => 'git',
-	      'repositoryUrl' => 'https://www.openstreetbrowser.org/dev/{{ repositoryId }}',
-	      'categoryUrl' => 'https://www.openstreetbrowser.org/dev/{{ repositoryId }}/src/{{ categoryId }}.json',
             );
+
+            if (array_key_exists('url', $repositoriesGitea)) {
+	      $r['repositoryUrl'] = "{$repositoriesGitea['url']}/{{ repositoryId }}";
+	      $r['categoryUrl'] = "{$repositoriesGitea['url']}/{{ repositoryId }}/src/{{ categoryId }}.json";
+            }
+
+            $result["{$f1}/{$f2id}"] = $r;
           }
         }
         closedir($d2);