About API code comments and some behavior.

toras toras9000 at gmail.com
Sun Oct 30 12:00:21 UTC 2022


Hi

I still rely on translation tools.
Perhaps it is hard to read. I hope I can convey it properly.
I also tried attaching the patch, but I should add that I'm inexperienced with python.


 > Yes. Can you confirm this will solve the code problems you reported:
 > https://kallithea-scm.org/repos/kallithea-incoming/changeset/088551a24485247af328f0b8e395fdbbcd62a700 ?

1. Modify create_repo()
   I don't think this change is correct.
   I overwrote api.py and called create_repo, but enable_downloads/enable_statistics seems to have no effect.

   I think the call flow during API execution is as follows.

   api.py : ApiController.create_repo()
     repo.py : RepoModel.create()
       repo.py : (@celerylib.task) create_repo()

   I think that the third function does not refer to form_data, but refers to defs to obtain the default value and use it.
   https://kallithea-scm.org/repos/kallithea/files/2dd317e9cc4b5ff94c1ddae7ee772d20b61259a9/kallithea/model/repo.py#L717
   I think this is probably implemented in conjunction with the web front end.

   I see two options for changes to the create_repo API.
   I think this requires a policy decision.

   Scenario 1:
     The API will no longer accept that parameter.
     Attachment: 1-scenario1.patch

   Scenario 2:
     Support parameter specification in RepoModel.
     Attachment: 1-scenario2.patch

2. Modify update_repo_group()
   I think there are two issues with parent handling.

   The first is.
   Other api parameters can basically target entities by name.
   It seems to me that as the parent_group_id parameter to RepoGroupModel.update(), the API parameter should be passed with name 
resolution instead of passing it as is.
     Attachment: 2-parent_id.patch

   The second is still unresolved and not yet known in detail.
   Only information known at this time is provided.
   The problem is that changing the parent group via the API will leave the database and file system in an inconsistent state.
   At that time, new_path does not seem to indicate the correct path in RepoGroupModel.update(). So the folder is not moved.
   It seems correct when run from the web front end. I still don't know what the difference is.


Supplementation.
It may not be necessary, but I will publish the docker files and scripts that I used in the confirmation work.
https://github.com/toras9000/kallithea_api_test



Thanks
-- 
toras9000

On 2022/10/29 17:36, Mads Kiilerich wrote:
> Hi
> 
> Yes. Can you confirm this will solve the code problems you reported: 
> https://kallithea-scm.org/repos/kallithea-incoming/changeset/088551a24485247af328f0b8e395fdbbcd62a700 ?
> 
> /Mads
> 
> 
> On 29/10/2022 09:28, toras wrote:
>> Hi
>>
>> I then noticed that the enable_downloads/enable_statistics parameters in the create_repo API also had no effect.
>> It seems that no parameters are used and the repository's default settings are used. (I think this is probably the expected 
>> behavior.)
>> I think this one also needs to be removed from the API parameters and description.
>>
>>
>> Thanks
>>
> 
-------------- next part --------------
# HG changeset patch
# User toras9000
# Date 1667130294 -32400
#      Sun Oct 30 20:44:54 2022 +0900
# Branch create_repo_scenario1
# Node ID 6e77e0c3353c51e393b9fe70fc7ed4ce4887139c
# Parent  088551a24485247af328f0b8e395fdbbcd62a700
delete create_repo params

diff --git a/kallithea/controllers/api/api.py b/kallithea/controllers/api/api.py
--- a/kallithea/controllers/api/api.py
+++ b/kallithea/controllers/api/api.py
@@ -1133,8 +1133,6 @@
                     repo_type=None, description='',
                     private=False, clone_uri=None,
                     landing_rev='rev:tip',
-                    enable_statistics=None,
-                    enable_downloads=None,
                     copy_permissions=False):
         """
         Creates a repository. The repository name contains the full path, but the
@@ -1158,10 +1156,6 @@
         :type clone_uri: str
         :param landing_rev: <rev_type>:<rev>
         :type landing_rev: str
-        :param enable_downloads:
-        :type enable_downloads: bool
-        :param enable_statistics:
-        :type enable_statistics: bool
         :param copy_permissions: Copy permission from group that repository is
             being created.
         :type copy_permissions: bool
@@ -1215,10 +1209,6 @@
             private = defs.get('repo_private') or False
         if repo_type is None:
             repo_type = defs.get('repo_type')
-        if enable_statistics is None:
-            enable_statistics = defs.get('repo_enable_statistics')
-        if enable_downloads is None:
-            enable_downloads = defs.get('repo_enable_downloads')
 
         try:
             data = dict(
@@ -1230,8 +1220,6 @@
                 clone_uri=clone_uri,
                 repo_group=group_name,
                 repo_landing_rev=landing_rev,
-                repo_enable_statistics=enable_statistics,
-                repo_enable_downloads=enable_downloads,
                 repo_copy_permissions=copy_permissions,
             )
 
-------------- next part --------------
# HG changeset patch
# User toras9000
# Date 1667130742 -32400
#      Sun Oct 30 20:52:22 2022 +0900
# Branch create_repo_scenario2
# Node ID 05fd460021c81a7bd30694d92425b60562c12167
# Parent  088551a24485247af328f0b8e395fdbbcd62a700
enable options

diff --git a/kallithea/model/repo.py b/kallithea/model/repo.py
--- a/kallithea/model/repo.py
+++ b/kallithea/model/repo.py
@@ -712,11 +712,15 @@
     copy_group_permissions = form_data.get('repo_copy_permissions')
     fork_of = form_data.get('fork_parent_id')
     state = form_data.get('repo_state', db.Repository.STATE_PENDING)
+    enable_statistics = form_data.get('repo_enable_statistics')
+    enable_downloads = form_data.get('repo_enable_downloads')
 
     # repo creation defaults, private and repo_type are filled in form
     defs = db.Setting.get_default_repo_settings(strip_prefix=True)
-    enable_statistics = defs.get('repo_enable_statistics')
-    enable_downloads = defs.get('repo_enable_downloads')
+    if enable_statistics is None:
+        enable_statistics = defs.get('repo_enable_statistics')
+    if enable_downloads is None:
+        enable_downloads = defs.get('repo_enable_downloads')
 
     try:
         db_repo = RepoModel()._create_repo(
-------------- next part --------------
# HG changeset patch
# User toras9000
# Date 1667130941 -32400
#      Sun Oct 30 20:55:41 2022 +0900
# Branch update_repo_group_parent_id
# Node ID 556e7c60bfd847c8969a7b5b34881d3716dcfc84
# Parent  088551a24485247af328f0b8e395fdbbcd62a700
evaluate parent param

diff --git a/kallithea/controllers/api/api.py b/kallithea/controllers/api/api.py
--- a/kallithea/controllers/api/api.py
+++ b/kallithea/controllers/api/api.py
@@ -1791,11 +1791,17 @@
                           parent=None):
         repo_group = get_repo_group_or_error(repogroupid)
 
+        parent_id = None
+        if parent is not None:
+            parent_group = get_repo_group_or_error(parent)
+            parent_id = parent_group.group_id
+
         updates = {}
         try:
             store_update(updates, group_name, 'group_name')
             store_update(updates, description, 'group_description')
-            store_update(updates, parent, 'parent_group_id')
+            if parent_id is not None:
+                store_update(updates, parent_id, 'parent_group_id')
             repo_group = RepoGroupModel().update(repo_group, updates)
             meta.Session().commit()
             return dict(


More information about the kallithea-general mailing list