This is an automated email from the ASF dual-hosted git repository.

kentontaylor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 24de5cb4a98e1847bf5e4bbe1b3aef296058ef6f
Author: Dave Brondsema <[email protected]>
AuthorDate: Tue Aug 2 12:24:50 2022 -0400

    [#8450] show more info for individual repos
---
 Allura/allura/controllers/repository.py            | 24 ++++++++++++++--
 Allura/docs/api-rest/api.raml                      |  9 ++++--
 Allura/docs/api-rest/examples/scm.json             |  7 +++++
 Allura/docs/api-rest/schemas/scm.json              | 32 ++++++++++++++++++++++
 .../forgegit/tests/functional/test_controllers.py  |  8 +++++-
 5 files changed, 75 insertions(+), 5 deletions(-)

diff --git a/Allura/allura/controllers/repository.py 
b/Allura/allura/controllers/repository.py
index f8fc76daa..1f769408a 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -60,6 +60,8 @@ from allura.controllers.feed import FeedController, FeedArgs
 from .base import BaseController
 import six
 
+from ..app import Application
+
 log = logging.getLogger(__name__)
 
 
@@ -309,8 +311,26 @@ class RepoRestController(RepoRootController, 
AppRestControllerMixin):
 
     @expose('json:')
     def index(self, **kw):
-        all_commits = c.app.repo._impl.new_commits(all_commits=True)
-        return dict(commit_count=len(all_commits))
+        app: Application = c.app
+        repo: M.Repository = app.repo
+        try:
+            all_commits = repo._impl.new_commits(all_commits=True)
+        except Exception:
+            log.exception(f'Error getting commits on {c.app.url}')
+            commit_count = None
+        else:
+            commit_count = len(all_commits)
+        resp = dict(
+            commit_count=commit_count,
+            name=app.config.options.mount_label,
+            type=app.tool_label,
+        )
+        for clone_cat in 
repo.clone_command_categories(anon=c.user.is_anonymous()):
+            respkey = 'clone_url_' + clone_cat['key']
+            resp[respkey] = repo.clone_url(clone_cat['key'],
+                                           username='' if 
c.user.is_anonymous() else c.user.username,
+                                           )
+        return resp
 
     @expose('json:')
     def commits(self, rev=None, limit=25, **kw):
diff --git a/Allura/docs/api-rest/api.raml b/Allura/docs/api-rest/api.raml
index f7f6f53e8..8167cc437 100755
--- a/Allura/docs/api-rest/api.raml
+++ b/Allura/docs/api-rest/api.raml
@@ -124,9 +124,14 @@ documentation:
 
       /{scm_tool}:
         description: |
-          Represents the **Git/Hg/SVN tool** and returns the commit count.
-
+          Represents a **Git/Hg/SVN tool** repo
         displayName: SCM Tool
+        type: {
+          generic: {
+            example: !include examples/scm.json,
+            schema: !include schemas/scm.json
+          }
+        }
         uriParameters:
           scm_tool:
             type: string
diff --git a/Allura/docs/api-rest/examples/scm.json 
b/Allura/docs/api-rest/examples/scm.json
new file mode 100755
index 000000000..a5a2f4b4e
--- /dev/null
+++ b/Allura/docs/api-rest/examples/scm.json
@@ -0,0 +1,7 @@
+{
+  "name": "Code",
+  "type": "Git",
+  "commit_count": 17,
+  "clone_url_https_anon": "https://forge-allura.apache.org/git/p/test/code";,
+  "clone_url_ro": "git://forge-allura.apache.org/git/p/test/code"
+}
\ No newline at end of file
diff --git a/Allura/docs/api-rest/schemas/scm.json 
b/Allura/docs/api-rest/schemas/scm.json
new file mode 100755
index 000000000..0a69b65e7
--- /dev/null
+++ b/Allura/docs/api-rest/schemas/scm.json
@@ -0,0 +1,32 @@
+{
+    "$schema": "http://json-schema.org/draft-04/schema";,
+    "type": "object",
+    "id": "#",
+    "properties": {
+        "name": {
+            "type": "string",
+            "id": "name"
+        },
+        "type": {
+            "type": "string",
+            "id": "type"
+        },
+        "commit_count": {
+            "type": "integer",
+            "id": "commit_count"
+        },
+        "clone_url_https_anon": {
+            "type": "string",
+            "id": "name"
+        },
+        "clone_url_ro": {
+            "type": "string",
+            "id": "name"
+        },
+        "clone_url_*": {
+            "type": "string",
+            "id": "name"
+        }
+    }
+}
+       
\ No newline at end of file
diff --git a/ForgeGit/forgegit/tests/functional/test_controllers.py 
b/ForgeGit/forgegit/tests/functional/test_controllers.py
index 9f0c0f75c..f4854db25 100644
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py
@@ -554,7 +554,13 @@ class TestRootController(_TestCase):
 
 class TestRestController(_TestCase):
     def test_index(self):
-        self.app.get('/rest/p/test/src-git/', status=200)
+        resp = self.app.get('/rest/p/test/src-git/', status=200)
+        assert_equal(resp.json, {
+            'commit_count': 5,
+            'name': 'Git',
+            'type': 'Git',
+            'clone_url_file': '/srv/git/p/test/testgit',
+        })
 
     def test_commits(self):
         self.app.get('/rest/p/test/src-git/commits', status=200)

Reply via email to