gitlabform 4.2.3__tar.gz → 4.2.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. {gitlabform-4.2.3 → gitlabform-4.2.5}/PKG-INFO +1 -1
  2. gitlabform-4.2.5/gitlabform/processors/util/labels_processor.py +121 -0
  3. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform.egg-info/PKG-INFO +1 -1
  4. {gitlabform-4.2.3 → gitlabform-4.2.5}/pyproject.toml +1 -1
  5. gitlabform-4.2.3/gitlabform/processors/util/labels_processor.py +0 -87
  6. {gitlabform-4.2.3 → gitlabform-4.2.5}/LICENSE +0 -0
  7. {gitlabform-4.2.3 → gitlabform-4.2.5}/README.md +0 -0
  8. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/__init__.py +0 -0
  9. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/configuration/__init__.py +0 -0
  10. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/configuration/common.py +0 -0
  11. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/configuration/core.py +0 -0
  12. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/configuration/groups.py +0 -0
  13. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/configuration/projects.py +0 -0
  14. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/configuration/transform.py +0 -0
  15. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/constants.py +0 -0
  16. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/gitlab/__init__.py +0 -0
  17. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/gitlab/commits.py +0 -0
  18. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/gitlab/core.py +0 -0
  19. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/gitlab/group_badges.py +0 -0
  20. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/gitlab/group_ldap_links.py +0 -0
  21. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/gitlab/group_variables.py +0 -0
  22. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/gitlab/groups.py +0 -0
  23. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/gitlab/merge_requests.py +0 -0
  24. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/gitlab/pipelines.py +0 -0
  25. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/gitlab/project_badges.py +0 -0
  26. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/gitlab/project_deploy_keys.py +0 -0
  27. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/gitlab/project_merge_requests_approvals.py +0 -0
  28. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/gitlab/project_protected_environments.py +0 -0
  29. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/gitlab/project_security_settings.py +0 -0
  30. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/gitlab/projects.py +0 -0
  31. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/gitlab/python_gitlab.py +0 -0
  32. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/gitlab/variables.py +0 -0
  33. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/lists/__init__.py +0 -0
  34. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/lists/filter.py +0 -0
  35. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/lists/groups.py +0 -0
  36. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/lists/projects.py +0 -0
  37. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/output.py +0 -0
  38. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/__init__.py +0 -0
  39. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/abstract_processor.py +0 -0
  40. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/application/__init__.py +0 -0
  41. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/application/application_settings_processor.py +0 -0
  42. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/defining_keys.py +0 -0
  43. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/group/__init__.py +0 -0
  44. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/group/group_badges_processor.py +0 -0
  45. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/group/group_hooks_processor.py +0 -0
  46. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/group/group_labels_processor.py +0 -0
  47. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/group/group_ldap_links_processor.py +0 -0
  48. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/group/group_members_processor.py +0 -0
  49. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/group/group_push_rules_processor.py +0 -0
  50. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/group/group_saml_links_processor.py +0 -0
  51. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/group/group_settings_processor.py +0 -0
  52. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/group/group_variables_processor.py +0 -0
  53. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/multiple_entities_processor.py +0 -0
  54. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/project/__init__.py +0 -0
  55. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/project/badges_processor.py +0 -0
  56. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/project/branches_processor.py +0 -0
  57. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/project/deploy_keys_processor.py +0 -0
  58. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/project/files_processor.py +0 -0
  59. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/project/hooks_processor.py +0 -0
  60. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/project/integrations_processor.py +0 -0
  61. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/project/job_token_scope_processor.py +0 -0
  62. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/project/members_processor.py +0 -0
  63. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/project/merge_requests_approval_rules.py +0 -0
  64. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/project/merge_requests_approvals.py +0 -0
  65. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/project/project_labels_processor.py +0 -0
  66. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/project/project_processor.py +0 -0
  67. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/project/project_push_rules_processor.py +0 -0
  68. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/project/project_security_settings.py +0 -0
  69. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/project/project_settings_processor.py +0 -0
  70. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/project/resource_groups_processor.py +0 -0
  71. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/project/schedules_processor.py +0 -0
  72. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/project/tags_processor.py +0 -0
  73. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/project/variables_processor.py +0 -0
  74. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/shared/__init__.py +0 -0
  75. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/shared/protected_environments_processor.py +0 -0
  76. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/single_entity_processor.py +0 -0
  77. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/util/__init__.py +0 -0
  78. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/util/decorators.py +0 -0
  79. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/processors/util/difference_logger.py +0 -0
  80. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/run.py +0 -0
  81. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform/util.py +0 -0
  82. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform.egg-info/SOURCES.txt +0 -0
  83. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform.egg-info/dependency_links.txt +0 -0
  84. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform.egg-info/entry_points.txt +0 -0
  85. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform.egg-info/requires.txt +0 -0
  86. {gitlabform-4.2.3 → gitlabform-4.2.5}/gitlabform.egg-info/top_level.txt +0 -0
  87. {gitlabform-4.2.3 → gitlabform-4.2.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gitlabform
3
- Version: 4.2.3
3
+ Version: 4.2.5
4
4
  Summary: 🏗 Specialized configuration as a code tool for GitLab projects, groups and more using hierarchical configuration written in YAML
5
5
  Author: Greg Dubicki and Contributors
6
6
  Project-URL: Homepage, https://gitlabform.github.io/gitlabform/
@@ -0,0 +1,121 @@
1
+ from cli_ui import debug as verbose, info, warning
2
+ from typing import Dict, List, Callable
3
+
4
+ from gitlab.base import RESTObjectList, RESTObject
5
+ from gitlab.v4.objects import Group, Project, ProjectLabel, GroupLabel
6
+
7
+
8
+ class LabelsProcessor:
9
+
10
+ # Groups and Projects share the same API for .labels within python-gitlab
11
+ def process_labels(
12
+ self,
13
+ configured_labels: Dict,
14
+ enforce: bool,
15
+ group_or_project: Group | Project,
16
+ needs_update: Callable, # self._needs_update passed from AbstractProcessor called process_labels
17
+ ):
18
+ # Only get Labels created directly on the project/group
19
+ existing_group_labels = group_or_project.labels.list(get_all=True, include_ancestor_groups=False)
20
+ existing_group_and_parent_labels = group_or_project.labels.list(get_all=True)
21
+ existing_label_keys: List = []
22
+
23
+ if isinstance(group_or_project, Group):
24
+ parent_object_type = "Group"
25
+ else:
26
+ parent_object_type = "Project"
27
+
28
+ gitlab_labels_to_delete: List = []
29
+
30
+ for label_to_update in existing_group_labels:
31
+ label_name_in_gl = label_to_update.name
32
+ updated_label = False
33
+ verbose(f"Checking if {label_name_in_gl} is in Configuration to update or delete")
34
+
35
+ for key, configured_label in configured_labels.items():
36
+ configured_label_name = configured_label.get("name")
37
+ # Key in YAML may not match the "name" value in Gitlab or YAML, so we must match on both
38
+ if self.configured_label_matches_gitlab_label(configured_label_name, key, label_name_in_gl):
39
+ # label exists in GL, so update
40
+ existing_label_keys.append(key)
41
+ updated_label = True
42
+
43
+ if needs_update(label_to_update.asdict(), configured_label):
44
+ self.update_existing_label(
45
+ configured_label,
46
+ self.get_label(group_or_project, label_to_update),
47
+ parent_object_type,
48
+ )
49
+ else:
50
+ verbose(f"No update required for label: {label_name_in_gl}")
51
+ break
52
+
53
+ if not updated_label:
54
+ gitlab_labels_to_delete.append(label_to_update)
55
+
56
+ # Delete labels no longer in config
57
+ for label_to_delete in gitlab_labels_to_delete:
58
+ label_name_in_gl = label_to_delete.name
59
+
60
+ verbose(f"{label_name_in_gl} not in configured labels")
61
+ # only delete labels when enforce is true, because user's maybe automatically applying labels based
62
+ # on Repo state, for example: Compliance Framework labels based on language or CI-template status
63
+ if enforce:
64
+ info(f"Removing {label_name_in_gl} from {parent_object_type}")
65
+ self.get_label(group_or_project, label_to_delete).delete()
66
+
67
+ # add new labels
68
+
69
+ for label_key in configured_labels.keys():
70
+ if label_key not in existing_label_keys:
71
+ info(f"Creating new label with key: {label_key}, on {parent_object_type}")
72
+ self.create_new_label(
73
+ configured_labels, group_or_project, label_key, parent_object_type, existing_group_and_parent_labels
74
+ )
75
+
76
+ @staticmethod
77
+ def configured_label_matches_gitlab_label(configured_label_name: str, key: str, label_name_in_gl: str):
78
+ return (
79
+ configured_label_name is not None and label_name_in_gl == configured_label_name
80
+ ) or label_name_in_gl == key
81
+
82
+ @staticmethod
83
+ def get_label(group_or_project, listed_label) -> GroupLabel | ProjectLabel:
84
+ return group_or_project.labels.get(listed_label.id)
85
+
86
+ @staticmethod
87
+ def update_existing_label(
88
+ configured_label,
89
+ full_label: GroupLabel | ProjectLabel,
90
+ parent_object_type: str,
91
+ ):
92
+ info(f"Updating {full_label.name} on {parent_object_type}")
93
+
94
+ # label APIs in python-gitlab do not supply an update() method
95
+ for key in configured_label:
96
+ full_label.__setattr__(key, configured_label[key])
97
+
98
+ full_label.save()
99
+
100
+ def create_new_label(
101
+ self,
102
+ configured_labels,
103
+ group_or_project: Group | Project,
104
+ label_key: str,
105
+ parent_object_type: str,
106
+ existing_group_and_parent_labels: RESTObjectList | list[RESTObject],
107
+ ):
108
+ label = configured_labels.get(label_key)
109
+ configured_label_name = label.get("name")
110
+ found_existing_label = False
111
+ for existing_label in existing_group_and_parent_labels:
112
+ if self.configured_label_matches_gitlab_label(configured_label_name, label_key, existing_label.name):
113
+ warning(
114
+ f"Label {existing_label.name} already exists either in {group_or_project.name} or on Parent Group, so will not create"
115
+ )
116
+ found_existing_label = True
117
+ break
118
+
119
+ if not found_existing_label:
120
+ info(f"Adding label with key: {label_key} to {parent_object_type}")
121
+ group_or_project.labels.create({"name": label_key, **label})
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gitlabform
3
- Version: 4.2.3
3
+ Version: 4.2.5
4
4
  Summary: 🏗 Specialized configuration as a code tool for GitLab projects, groups and more using hierarchical configuration written in YAML
5
5
  Author: Greg Dubicki and Contributors
6
6
  Project-URL: Homepage, https://gitlabform.github.io/gitlabform/
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "gitlabform"
7
- version = "4.2.3"
7
+ version = "4.2.5"
8
8
  authors = [{ name = "Greg Dubicki and Contributors" }]
9
9
  description = "🏗 Specialized configuration as a code tool for GitLab projects, groups and more using hierarchical configuration written in YAML"
10
10
  keywords = ["cli", "yaml", "gitlab", "configuration-as-code"]
@@ -1,87 +0,0 @@
1
- from cli_ui import debug as verbose, info
2
- from typing import Dict, List, Callable
3
-
4
- from gitlab.v4.objects import Group, Project, ProjectLabel, GroupLabel
5
-
6
-
7
- class LabelsProcessor:
8
-
9
- # Groups and Projects share the same API for .labels within python-gitlab
10
- def process_labels(
11
- self,
12
- configured_labels: Dict,
13
- enforce: bool,
14
- group_or_project: Group | Project,
15
- needs_update: Callable, # self._needs_update passed from AbstractProcessor called process_labels
16
- ):
17
- # Only get Labels created directly on the project/group
18
- existing_labels = group_or_project.labels.list(get_all=True, include_ancestor_groups=False)
19
- existing_label_names: List = []
20
-
21
- if isinstance(group_or_project, Group):
22
- parent_object_type = "Group"
23
- else:
24
- parent_object_type = "Project"
25
-
26
- if existing_labels:
27
- for listed_label in existing_labels:
28
- # list and get single label return the same data from Gitlab so we can save on API calls
29
- # by only GETting again when we need to make an update or delete
30
- # https://docs.gitlab.com/api/labels/ && https://docs.gitlab.com/api/group_labels/
31
- verbose(f"Processing existing label in Gitlab: {listed_label.name}")
32
- label_name = listed_label.name
33
-
34
- if label_name not in configured_labels.keys():
35
- verbose(f"{label_name} not in configured labels")
36
- # only delete labels when enforce is true, because user's maybe automatically applying labels based
37
- # on Repo state, for example: Compliance Framework labels based on language or CI-template status
38
- if enforce:
39
- info(f"Removing {label_name} from {parent_object_type}")
40
- self.get_label(group_or_project, listed_label).delete()
41
- else:
42
- configured_label = configured_labels.get(label_name)
43
- existing_label_names.append(label_name)
44
-
45
- if needs_update(listed_label.asdict(), configured_label):
46
- self.update_existing_label(
47
- configured_label,
48
- self.get_label(group_or_project, listed_label),
49
- parent_object_type,
50
- )
51
- else:
52
- verbose(f"No update required for label: {label_name}")
53
-
54
- # add new labels
55
- for label_name in configured_labels.keys():
56
- if label_name not in existing_label_names:
57
- info(f"Creating new label: {label_name}, on {parent_object_type}")
58
- self.create_new_label(configured_labels, group_or_project, label_name, parent_object_type)
59
-
60
- @staticmethod
61
- def get_label(group_or_project, listed_label) -> GroupLabel | ProjectLabel:
62
- return group_or_project.labels.get(listed_label.id)
63
-
64
- @staticmethod
65
- def update_existing_label(
66
- configured_label,
67
- full_label: GroupLabel | ProjectLabel,
68
- parent_object_type: str,
69
- ):
70
- info(f"Updating {full_label.name} on {parent_object_type}")
71
-
72
- # label APIs in python-gitlab do not supply an update() method
73
- for key in configured_label:
74
- full_label.__setattr__(key, configured_label[key])
75
-
76
- full_label.save()
77
-
78
- @staticmethod
79
- def create_new_label(
80
- configured_labels,
81
- group_or_project: Group | Project,
82
- label_name: str,
83
- parent_object_type: str,
84
- ):
85
- label = configured_labels.get(label_name)
86
- info(f"Adding {label_name} to {parent_object_type}")
87
- group_or_project.labels.create({"name": label_name, **label})
File without changes
File without changes
File without changes
File without changes