Repository: gitlabform/gitlabform
Issue category: Feature Request

Issue:
Migrate `project_settings` config to use python-gitlab library
Goal of this issue is to migrate the `project_settings` configuration section to use [python-gitlab library](https://python-gitlab.readthedocs.io/en/stable/) instead of using homegrown API in this project.

High level Tasks:

- Update `gitlabform/processors/project/project_settings_processor.py` to use the python-gitlab library
    - To use python-gitlab use `self.gl` instead of `self.gitlab`. For reference, see some of the other processors that are already using python-gitlab library (i.e. `branches_processor.py`)
- Any cleanup necessary from switching to python-gitlab related to this processor




Hints:

Patch:
diff --git a/gitlabform/gitlab/projects.py b/gitlabform/gitlab/projects.py
index 4cf21b23..649121ba 100644
--- a/gitlabform/gitlab/projects.py
+++ b/gitlabform/gitlab/projects.py
@@ -126,21 +126,6 @@ def get_project_settings(self, project_and_group_name):
         except NotFoundException:
             return dict()
 
-    def put_project_settings(self, project_and_group_name, project_settings):
-        # project_settings has to be like this:
-        # {
-        #     'setting1': value1,
-        #     'setting2': value2,
-        # }
-        # ..as documented at: https://docs.gitlab.com/ce/api/projects.html#edit-project
-        return self._make_requests_to_api(
-            "projects/%s",
-            project_and_group_name,
-            "PUT",
-            data=None,
-            json=project_settings,
-        )
-
     def get_groups_from_project(self, project_and_group_name):
         # couldn't find an API call that was giving me directly
         # the shared groups, so I'm using directly the GET /projects/:id call
diff --git a/gitlabform/processors/project/project_settings_processor.py b/gitlabform/processors/project/project_settings_processor.py
index 57364dee..9407e05c 100644
--- a/gitlabform/processors/project/project_settings_processor.py
+++ b/gitlabform/processors/project/project_settings_processor.py
@@ -1,12 +1,50 @@
+from logging import debug
+from typing import Callable
 from gitlabform.gitlab import GitLab
-from gitlabform.processors.single_entity_processor import SingleEntityProcessor
+from gitlabform.processors.abstract_processor import AbstractProcessor
+from gitlabform.processors.util.difference_logger import DifferenceLogger
 
+from gitlab.v4.objects import Project
 
-class ProjectSettingsProcessor(SingleEntityProcessor):
+
+class ProjectSettingsProcessor(AbstractProcessor):
     def __init__(self, gitlab: GitLab):
-        super().__init__(
-            "project_settings",
-            gitlab,
-            get_method_name="get_project_settings",
-            edit_method_name="put_project_settings",
+        super().__init__("project_settings", gitlab)
+        self.get_entity_in_gitlab: Callable = getattr(self, "get_project_settings")
+
+    def _process_configuration(self, project_path: str, configuration: dict):
+        debug("Processing project settings...")
+        project: Project = self.gl.get_project_by_path_cached(project_path)
+
+        project_settings_in_config = configuration.get("project_settings", {})
+        project_settings_in_gitlab = project.asdict()
+        debug(project_settings_in_gitlab)
+        debug(f"project_settings BEFORE: ^^^")
+
+        if self._needs_update(project_settings_in_gitlab, project_settings_in_config):
+            debug("Updating project settings")
+            for key, value in project_settings_in_config.items():
+                debug(f"Updating setting {key} to value {value}")
+                setattr(project, key, value)
+            project.save()
+
+            debug(project.asdict())
+            debug(f"project_settings AFTER: ^^^")
+
+        else:
+            debug("No update needed for project settings")
+
+    def get_project_settings(self, project_path: str):
+        return self.gl.get_project_by_path_cached(project_path).asdict()
+
+    def _print_diff(
+        self, project_or_project_and_group: str, entity_config, diff_only_changed: bool
+    ):
+        entity_in_gitlab = self.get_project_settings(project_or_project_and_group)
+
+        DifferenceLogger.log_diff(
+            f"{self.configuration_name} changes",
+            entity_in_gitlab,
+            entity_config,
+            only_changed=diff_only_changed,
         )


Test patch: