gitlab-projects-settings 1.0.0__py3-none-any.whl
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.
- gitlab_projects_settings/__init__.py +5 -0
- gitlab_projects_settings/__main__.py +5 -0
- gitlab_projects_settings/cli/__init__.py +0 -0
- gitlab_projects_settings/cli/main.py +198 -0
- gitlab_projects_settings/features/__init__.py +0 -0
- gitlab_projects_settings/features/gitlab.py +314 -0
- gitlab_projects_settings/features/settings.py +213 -0
- gitlab_projects_settings/package/__init__.py +0 -0
- gitlab_projects_settings/package/bundle.py +16 -0
- gitlab_projects_settings/package/version.py +57 -0
- gitlab_projects_settings/prints/__init__.py +0 -0
- gitlab_projects_settings/prints/colors.py +85 -0
- gitlab_projects_settings/system/__init__.py +0 -0
- gitlab_projects_settings/system/platform.py +27 -0
- gitlab_projects_settings-1.0.0.dist-info/LICENSE +201 -0
- gitlab_projects_settings-1.0.0.dist-info/METADATA +118 -0
- gitlab_projects_settings-1.0.0.dist-info/RECORD +20 -0
- gitlab_projects_settings-1.0.0.dist-info/WHEEL +5 -0
- gitlab_projects_settings-1.0.0.dist-info/entry_points.txt +2 -0
- gitlab_projects_settings-1.0.0.dist-info/top_level.txt +1 -0
|
File without changes
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Standard libraries
|
|
4
|
+
from argparse import (_ArgumentGroup, ArgumentParser, Namespace, RawTextHelpFormatter)
|
|
5
|
+
from os import environ
|
|
6
|
+
from sys import exit as sys_exit
|
|
7
|
+
|
|
8
|
+
# Components
|
|
9
|
+
from ..features.settings import SettingsFeature
|
|
10
|
+
from ..package.bundle import Bundle
|
|
11
|
+
from ..package.version import Version
|
|
12
|
+
from ..prints.colors import Colors
|
|
13
|
+
from ..system.platform import Platform
|
|
14
|
+
|
|
15
|
+
# Main, pylint: disable=too-many-statements
|
|
16
|
+
def main() -> None:
|
|
17
|
+
|
|
18
|
+
# Variables
|
|
19
|
+
group: _ArgumentGroup
|
|
20
|
+
result: bool = False
|
|
21
|
+
|
|
22
|
+
# Arguments creation
|
|
23
|
+
parser: ArgumentParser = ArgumentParser(
|
|
24
|
+
prog=Bundle.NAME,
|
|
25
|
+
description=f'{Bundle.NAME}: {Bundle.DESCRIPTION}',
|
|
26
|
+
add_help=False,
|
|
27
|
+
formatter_class=RawTextHelpFormatter,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
# Arguments internal definitions
|
|
31
|
+
group = parser.add_argument_group('internal arguments')
|
|
32
|
+
group.add_argument(
|
|
33
|
+
'-h',
|
|
34
|
+
'--help',
|
|
35
|
+
dest='help',
|
|
36
|
+
action='store_true',
|
|
37
|
+
help='Show this help message',
|
|
38
|
+
)
|
|
39
|
+
group.add_argument(
|
|
40
|
+
'--version',
|
|
41
|
+
dest='version',
|
|
42
|
+
action='store_true',
|
|
43
|
+
help='Show the current version',
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
# Arguments credentials definitions
|
|
47
|
+
group = parser.add_argument_group('credentials arguments')
|
|
48
|
+
group.add_argument(
|
|
49
|
+
'-t',
|
|
50
|
+
dest='token',
|
|
51
|
+
default=environ.get(Bundle.ENV_GITLAB_TOKEN, ''), #
|
|
52
|
+
help=f'GitLab API token (default: {Bundle.ENV_GITLAB_TOKEN} environment)',
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
# Arguments common settings definitions
|
|
56
|
+
group = parser.add_argument_group('common settings arguments')
|
|
57
|
+
group.add_argument(
|
|
58
|
+
'--dry-run',
|
|
59
|
+
dest='dry_run',
|
|
60
|
+
action='store_true',
|
|
61
|
+
help='Enable dry run mode to check without saving',
|
|
62
|
+
)
|
|
63
|
+
group.add_argument(
|
|
64
|
+
'--avoid-group',
|
|
65
|
+
dest='avoid_group',
|
|
66
|
+
action='store_true',
|
|
67
|
+
help='Avoid affecting parent group settings',
|
|
68
|
+
)
|
|
69
|
+
group.add_argument(
|
|
70
|
+
'--avoid-subgroups',
|
|
71
|
+
dest='avoid_subgroups',
|
|
72
|
+
action='store_true',
|
|
73
|
+
help='Avoid affecting children subgroups settings',
|
|
74
|
+
)
|
|
75
|
+
group.add_argument(
|
|
76
|
+
'--avoid-projects',
|
|
77
|
+
dest='avoid_projects',
|
|
78
|
+
action='store_true',
|
|
79
|
+
help='Avoid affecting children projects settings',
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
# Arguments general settings definitions
|
|
83
|
+
group = parser.add_argument_group('general settings arguments')
|
|
84
|
+
group.add_argument(
|
|
85
|
+
'--reset-features',
|
|
86
|
+
dest='reset_features',
|
|
87
|
+
action='store_true',
|
|
88
|
+
help='Reset features of GitLab projects based on usage',
|
|
89
|
+
)
|
|
90
|
+
group.add_argument(
|
|
91
|
+
'--reset-members',
|
|
92
|
+
dest='reset_members',
|
|
93
|
+
action='store_true',
|
|
94
|
+
help='Reset members of GitLab projects and groups',
|
|
95
|
+
)
|
|
96
|
+
group.add_argument(
|
|
97
|
+
'--set-avatar',
|
|
98
|
+
dest='set_avatar',
|
|
99
|
+
action='store',
|
|
100
|
+
metavar='FILE',
|
|
101
|
+
help='Set avatar of GitLab projects and groups',
|
|
102
|
+
)
|
|
103
|
+
group.add_argument(
|
|
104
|
+
'--set-description',
|
|
105
|
+
dest='set_description',
|
|
106
|
+
action='store',
|
|
107
|
+
metavar='DESCRIPTION',
|
|
108
|
+
help='Set description of GitLab projects and groups',
|
|
109
|
+
)
|
|
110
|
+
group.add_argument(
|
|
111
|
+
'--update-description',
|
|
112
|
+
dest='update_description',
|
|
113
|
+
action='store_true',
|
|
114
|
+
help='Update description of GitLab projects and groups automatically',
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
# Arguments repository settings definitions
|
|
118
|
+
group = parser.add_argument_group('repository settings arguments')
|
|
119
|
+
group.add_argument(
|
|
120
|
+
'--protect-branches',
|
|
121
|
+
dest='protect_branches',
|
|
122
|
+
action='store_true',
|
|
123
|
+
help='Protect branches with default master/main, develop and staging',
|
|
124
|
+
)
|
|
125
|
+
group.add_argument(
|
|
126
|
+
'--protect-tags',
|
|
127
|
+
dest='protect_tags',
|
|
128
|
+
action='store',
|
|
129
|
+
metavar='LEVEL',
|
|
130
|
+
help='Protect tags at level [no-one,admins,maintainers,developers]',
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
# Arguments positional definitions
|
|
134
|
+
group = parser.add_argument_group('positional arguments')
|
|
135
|
+
group.add_argument(
|
|
136
|
+
dest='gitlab',
|
|
137
|
+
action='store',
|
|
138
|
+
nargs='?',
|
|
139
|
+
default='https://gitlab.com',
|
|
140
|
+
help='GitLab URL (default: https://gitlab.com)',
|
|
141
|
+
)
|
|
142
|
+
group.add_argument(
|
|
143
|
+
dest='path',
|
|
144
|
+
action='store',
|
|
145
|
+
nargs='?',
|
|
146
|
+
help='GitLab group or project path',
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
# Arguments parser
|
|
150
|
+
options: Namespace = parser.parse_args()
|
|
151
|
+
|
|
152
|
+
# Help informations
|
|
153
|
+
if options.help:
|
|
154
|
+
print(' ')
|
|
155
|
+
parser.print_help()
|
|
156
|
+
print(' ')
|
|
157
|
+
Platform.flush()
|
|
158
|
+
sys_exit(0)
|
|
159
|
+
|
|
160
|
+
# Prepare colors
|
|
161
|
+
Colors.prepare()
|
|
162
|
+
|
|
163
|
+
# Version informations
|
|
164
|
+
if options.version:
|
|
165
|
+
print(
|
|
166
|
+
f'{Bundle.NAME} {Version.get()} from {Version.path()} (python {Version.python()})'
|
|
167
|
+
)
|
|
168
|
+
Platform.flush()
|
|
169
|
+
sys_exit(0)
|
|
170
|
+
|
|
171
|
+
# Arguments validation
|
|
172
|
+
if not options.token or not options.gitlab or not options.path:
|
|
173
|
+
print(' ')
|
|
174
|
+
parser.print_help()
|
|
175
|
+
print(' ')
|
|
176
|
+
Platform.flush()
|
|
177
|
+
sys_exit(1)
|
|
178
|
+
|
|
179
|
+
# Header
|
|
180
|
+
print(' ')
|
|
181
|
+
Platform.flush()
|
|
182
|
+
|
|
183
|
+
# Configure GitLab projects
|
|
184
|
+
result = SettingsFeature.entrypoint(options)
|
|
185
|
+
|
|
186
|
+
# Footer
|
|
187
|
+
print(' ')
|
|
188
|
+
Platform.flush()
|
|
189
|
+
|
|
190
|
+
# Result
|
|
191
|
+
if result:
|
|
192
|
+
sys_exit(0)
|
|
193
|
+
else:
|
|
194
|
+
sys_exit(1)
|
|
195
|
+
|
|
196
|
+
# Entrypoint
|
|
197
|
+
if __name__ == '__main__': # pragma: no cover
|
|
198
|
+
main()
|
|
File without changes
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Standard libraries
|
|
4
|
+
from typing import List
|
|
5
|
+
|
|
6
|
+
# Modules libraries
|
|
7
|
+
from gitlab import Gitlab
|
|
8
|
+
from gitlab.exceptions import GitlabListError
|
|
9
|
+
from gitlab.v4.objects import Group, Project
|
|
10
|
+
|
|
11
|
+
# GitLabFeature class
|
|
12
|
+
class GitLabFeature:
|
|
13
|
+
|
|
14
|
+
# Members
|
|
15
|
+
__dry_run: bool = False
|
|
16
|
+
__gitlab: Gitlab
|
|
17
|
+
|
|
18
|
+
# Constructor
|
|
19
|
+
def __init__(self, url: str, token: str, dry_run: bool = False) -> None:
|
|
20
|
+
self.__dry_run = dry_run
|
|
21
|
+
self.__gitlab = Gitlab(url, private_token=token)
|
|
22
|
+
self.__gitlab.auth()
|
|
23
|
+
|
|
24
|
+
# Group
|
|
25
|
+
def group(self, criteria: str) -> Group:
|
|
26
|
+
return self.__gitlab.groups.get(criteria)
|
|
27
|
+
|
|
28
|
+
# Group reset members
|
|
29
|
+
def group_reset_members(self, criteria: str) -> None:
|
|
30
|
+
|
|
31
|
+
# Remove group members
|
|
32
|
+
group = self.group(criteria)
|
|
33
|
+
for member in group.members.list():
|
|
34
|
+
if not self.__dry_run:
|
|
35
|
+
group.members.delete(member.id)
|
|
36
|
+
|
|
37
|
+
# Save group
|
|
38
|
+
if not self.__dry_run:
|
|
39
|
+
group.save()
|
|
40
|
+
|
|
41
|
+
# Group set avatar
|
|
42
|
+
def group_set_avatar(self, criteria: str, file: str) -> None:
|
|
43
|
+
|
|
44
|
+
# Set group avatar
|
|
45
|
+
group = self.group(criteria)
|
|
46
|
+
with open(file, 'rb') as avatar:
|
|
47
|
+
group.avatar = avatar
|
|
48
|
+
|
|
49
|
+
# Save group
|
|
50
|
+
if not self.__dry_run:
|
|
51
|
+
group.save()
|
|
52
|
+
|
|
53
|
+
# Group set description
|
|
54
|
+
def group_set_description(self, criteria: str, description: str) -> None:
|
|
55
|
+
|
|
56
|
+
# Set group description
|
|
57
|
+
group = self.group(criteria)
|
|
58
|
+
group.description = description
|
|
59
|
+
|
|
60
|
+
# Save group
|
|
61
|
+
if not self.__dry_run:
|
|
62
|
+
group.save()
|
|
63
|
+
|
|
64
|
+
# Project
|
|
65
|
+
def project(self, criteria: str) -> Project:
|
|
66
|
+
return self.__gitlab.projects.get(criteria)
|
|
67
|
+
|
|
68
|
+
# Project protect branches
|
|
69
|
+
def project_protect_branches(self, criteria: str) -> List[str]:
|
|
70
|
+
|
|
71
|
+
# Validate project feature
|
|
72
|
+
result: List[str] = []
|
|
73
|
+
project = self.project(criteria)
|
|
74
|
+
try:
|
|
75
|
+
assert project.branches.list()
|
|
76
|
+
except (AssertionError, GitlabListError):
|
|
77
|
+
return result
|
|
78
|
+
|
|
79
|
+
# Acquire project, branches and protected branches
|
|
80
|
+
branches = [branch.name for branch in project.branches.list()]
|
|
81
|
+
protectedbranches = [
|
|
82
|
+
protectedbranch.name for protectedbranch in project.protectedbranches.list()
|
|
83
|
+
]
|
|
84
|
+
|
|
85
|
+
# Protect main/master
|
|
86
|
+
for branch in ['main', 'master']:
|
|
87
|
+
if branch in branches and branch not in protectedbranches:
|
|
88
|
+
if not self.__dry_run:
|
|
89
|
+
project.protectedbranches.create({
|
|
90
|
+
'name': branch,
|
|
91
|
+
'merge_access_level': 40,
|
|
92
|
+
'push_access_level': 40,
|
|
93
|
+
'allow_force_push': False
|
|
94
|
+
})
|
|
95
|
+
result += [branch]
|
|
96
|
+
|
|
97
|
+
# Protect develop
|
|
98
|
+
for branch in ['develop']:
|
|
99
|
+
if branch in branches and branch not in protectedbranches:
|
|
100
|
+
if not self.__dry_run:
|
|
101
|
+
project.protectedbranches.create({
|
|
102
|
+
'name': branch,
|
|
103
|
+
'merge_access_level': 40,
|
|
104
|
+
'push_access_level': 40,
|
|
105
|
+
'allow_force_push': True
|
|
106
|
+
})
|
|
107
|
+
result += [branch]
|
|
108
|
+
|
|
109
|
+
# Protect staging
|
|
110
|
+
for branch in ['staging']:
|
|
111
|
+
if branch in branches and branch not in protectedbranches:
|
|
112
|
+
if not self.__dry_run:
|
|
113
|
+
project.protectedbranches.create({
|
|
114
|
+
'name': branch,
|
|
115
|
+
'merge_access_level': 30,
|
|
116
|
+
'push_access_level': 30,
|
|
117
|
+
'allow_force_push': True
|
|
118
|
+
})
|
|
119
|
+
result += [branch]
|
|
120
|
+
|
|
121
|
+
# Save project
|
|
122
|
+
if not self.__dry_run:
|
|
123
|
+
project.save()
|
|
124
|
+
|
|
125
|
+
# Result
|
|
126
|
+
return result
|
|
127
|
+
|
|
128
|
+
# Project protect tags, pylint: disable=too-many-branches
|
|
129
|
+
def project_protect_tags(self, criteria: str, protect_level: str) -> List[str]:
|
|
130
|
+
|
|
131
|
+
# Validate project feature
|
|
132
|
+
result: List[str] = []
|
|
133
|
+
project = self.project(criteria)
|
|
134
|
+
try:
|
|
135
|
+
assert project.tags.list()
|
|
136
|
+
except (AssertionError, GitlabListError):
|
|
137
|
+
return result
|
|
138
|
+
|
|
139
|
+
# Prepare access level
|
|
140
|
+
access_level: int
|
|
141
|
+
if protect_level == 'no-one':
|
|
142
|
+
access_level = 0
|
|
143
|
+
elif protect_level == 'admins':
|
|
144
|
+
access_level = 60
|
|
145
|
+
elif protect_level == 'maintainers':
|
|
146
|
+
access_level = 40
|
|
147
|
+
elif protect_level == 'developers':
|
|
148
|
+
access_level = 30
|
|
149
|
+
else:
|
|
150
|
+
raise SyntaxError(f'Unknown protection level: {access_level}')
|
|
151
|
+
|
|
152
|
+
# Acquire protected tags
|
|
153
|
+
protectedtags = [
|
|
154
|
+
protectedtag.name for protectedtag in project.protectedtags.list()
|
|
155
|
+
]
|
|
156
|
+
|
|
157
|
+
# Update protected tags
|
|
158
|
+
for protectedtag in project.protectedtags.list():
|
|
159
|
+
protectedtag_level = protectedtag.create_access_levels[0]['access_level']
|
|
160
|
+
if protectedtag_level != 0 and (access_level == 0
|
|
161
|
+
or protectedtag_level < access_level):
|
|
162
|
+
name = protectedtag.name
|
|
163
|
+
if not self.__dry_run:
|
|
164
|
+
protectedtag.delete()
|
|
165
|
+
project.protectedtags.create({
|
|
166
|
+
'name': name,
|
|
167
|
+
'create_access_level': access_level
|
|
168
|
+
})
|
|
169
|
+
result += [name]
|
|
170
|
+
|
|
171
|
+
# Protect unprotected tags
|
|
172
|
+
for tag in project.tags.list():
|
|
173
|
+
if tag.name not in protectedtags:
|
|
174
|
+
if not self.__dry_run:
|
|
175
|
+
project.protectedtags.create({
|
|
176
|
+
'name': tag.name,
|
|
177
|
+
'create_access_level': access_level
|
|
178
|
+
})
|
|
179
|
+
result += [tag.name]
|
|
180
|
+
|
|
181
|
+
# Save project
|
|
182
|
+
if not self.__dry_run:
|
|
183
|
+
project.save()
|
|
184
|
+
|
|
185
|
+
# Result
|
|
186
|
+
result.sort()
|
|
187
|
+
return result
|
|
188
|
+
|
|
189
|
+
# Project reset features, pylint: disable=too-many-branches,too-many-statements
|
|
190
|
+
def project_reset_features(self, criteria: str) -> List[str]:
|
|
191
|
+
|
|
192
|
+
# Variables
|
|
193
|
+
result: List[str] = []
|
|
194
|
+
project = self.__gitlab.projects.get(criteria, statistics=True)
|
|
195
|
+
|
|
196
|
+
# Disable unused features
|
|
197
|
+
if project.issues_enabled and not project.issues.list(get_all=False):
|
|
198
|
+
project.issues_enabled = False
|
|
199
|
+
result += ['Issues']
|
|
200
|
+
try:
|
|
201
|
+
assert project.commits.list(get_all=False)
|
|
202
|
+
except (AssertionError, GitlabListError):
|
|
203
|
+
if project.repository_access_level != 'disabled':
|
|
204
|
+
project.repository_access_level = 'disabled'
|
|
205
|
+
result += ['Repository']
|
|
206
|
+
if project.merge_requests_enabled and not project.mergerequests.list(
|
|
207
|
+
get_all=False):
|
|
208
|
+
project.merge_requests_enabled = False
|
|
209
|
+
result += ['Merge requests']
|
|
210
|
+
if project.forking_access_level != 'disabled' and not project.forks.list(
|
|
211
|
+
get_all=False):
|
|
212
|
+
project.forking_access_level = 'disabled'
|
|
213
|
+
result += ['Forks']
|
|
214
|
+
if project.lfs_enabled and project.statistics['lfs_objects_size'] == 0:
|
|
215
|
+
project.lfs_enabled = False
|
|
216
|
+
result += ['Git LFS']
|
|
217
|
+
if project.jobs_enabled and not project.jobs.list(get_all=False):
|
|
218
|
+
project.jobs_enabled = False
|
|
219
|
+
result += ['CI/CD']
|
|
220
|
+
if project.container_registry_enabled and not project.repositories.list(
|
|
221
|
+
get_all=False):
|
|
222
|
+
project.container_registry_enabled = False
|
|
223
|
+
result += ['Container registry']
|
|
224
|
+
if project.analytics_access_level != 'disabled':
|
|
225
|
+
project.analytics_access_level = 'disabled'
|
|
226
|
+
result += ['Analytics']
|
|
227
|
+
if project.security_and_compliance_access_level != 'disabled':
|
|
228
|
+
project.security_and_compliance_access_level = 'disabled'
|
|
229
|
+
result += ['Security and Compliance']
|
|
230
|
+
if project.wiki_enabled and not project.wikis.list(get_all=False):
|
|
231
|
+
project.wiki_enabled = False
|
|
232
|
+
result += ['Wiki']
|
|
233
|
+
if project.snippets_enabled and not project.snippets.list(get_all=False):
|
|
234
|
+
project.snippets_enabled = False
|
|
235
|
+
result += ['Snippets']
|
|
236
|
+
if project.packages_enabled and not project.packages.list(get_all=False):
|
|
237
|
+
project.packages_enabled = False
|
|
238
|
+
result += ['Package registry']
|
|
239
|
+
if project.model_experiments_access_level != 'disabled':
|
|
240
|
+
project.model_experiments_access_level = 'disabled'
|
|
241
|
+
result += ['Model experiments']
|
|
242
|
+
if project.model_registry_access_level != 'disabled':
|
|
243
|
+
project.model_registry_access_level = 'disabled'
|
|
244
|
+
result += ['Model registry']
|
|
245
|
+
if project.pages_access_level != 'disabled':
|
|
246
|
+
project.pages_access_level = 'disabled'
|
|
247
|
+
result += ['Pages']
|
|
248
|
+
if project.monitor_access_level != 'disabled':
|
|
249
|
+
project.monitor_access_level = 'disabled'
|
|
250
|
+
result += ['Monitor']
|
|
251
|
+
try:
|
|
252
|
+
assert project.environments.list(get_all=False)
|
|
253
|
+
except (AssertionError, GitlabListError):
|
|
254
|
+
if project.environments_access_level != 'disabled':
|
|
255
|
+
project.environments_access_level = 'disabled'
|
|
256
|
+
result += ['Environments']
|
|
257
|
+
if project.feature_flags_access_level != 'disabled':
|
|
258
|
+
project.feature_flags_access_level = 'disabled'
|
|
259
|
+
result += ['Feature flags']
|
|
260
|
+
if project.infrastructure_access_level != 'disabled':
|
|
261
|
+
project.infrastructure_access_level = 'disabled'
|
|
262
|
+
result += ['Infrastructure']
|
|
263
|
+
if project.releases_access_level != 'disabled' and not project.releases.list(
|
|
264
|
+
get_all=False):
|
|
265
|
+
project.releases_access_level = 'disabled'
|
|
266
|
+
result += ['Releases']
|
|
267
|
+
if project.service_desk_enabled:
|
|
268
|
+
project.service_desk_enabled = False
|
|
269
|
+
result += ['Service Desk']
|
|
270
|
+
if project.auto_devops_enabled:
|
|
271
|
+
project.auto_devops_enabled = False
|
|
272
|
+
result += ['Auto DevOps']
|
|
273
|
+
|
|
274
|
+
# Save project
|
|
275
|
+
if not self.__dry_run:
|
|
276
|
+
project.save()
|
|
277
|
+
|
|
278
|
+
# Result
|
|
279
|
+
return result
|
|
280
|
+
|
|
281
|
+
# Project reset members
|
|
282
|
+
def project_reset_members(self, criteria: str) -> None:
|
|
283
|
+
|
|
284
|
+
# Remove project members
|
|
285
|
+
project = self.project(criteria)
|
|
286
|
+
for member in project.members.list():
|
|
287
|
+
if not self.__dry_run:
|
|
288
|
+
project.members.delete(member.id)
|
|
289
|
+
|
|
290
|
+
# Save project
|
|
291
|
+
if not self.__dry_run:
|
|
292
|
+
project.save()
|
|
293
|
+
|
|
294
|
+
# Project set avatar
|
|
295
|
+
def project_set_avatar(self, criteria: str, file: str) -> None:
|
|
296
|
+
|
|
297
|
+
# Set project avatar
|
|
298
|
+
project = self.project(criteria)
|
|
299
|
+
with open(file, 'rb') as avatar:
|
|
300
|
+
project.avatar = avatar
|
|
301
|
+
if not self.__dry_run:
|
|
302
|
+
project.save()
|
|
303
|
+
|
|
304
|
+
# Project set description
|
|
305
|
+
def project_set_description(self, criteria: str, description: str) -> None:
|
|
306
|
+
project = self.project(criteria)
|
|
307
|
+
project.description = description
|
|
308
|
+
if not self.__dry_run:
|
|
309
|
+
project.save()
|
|
310
|
+
|
|
311
|
+
# URL
|
|
312
|
+
@property
|
|
313
|
+
def url(self) -> str:
|
|
314
|
+
return str(self.__gitlab.api_url)
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Standard libraries
|
|
4
|
+
from argparse import Namespace
|
|
5
|
+
|
|
6
|
+
# Modules libraries
|
|
7
|
+
from gitlab.exceptions import GitlabGetError
|
|
8
|
+
from gitlab.v4.objects import Group, Project
|
|
9
|
+
|
|
10
|
+
# Components
|
|
11
|
+
from ..features.gitlab import GitLabFeature
|
|
12
|
+
from ..prints.colors import Colors
|
|
13
|
+
from ..system.platform import Platform
|
|
14
|
+
|
|
15
|
+
# SettingsFeature class, pylint: disable=too-few-public-methods
|
|
16
|
+
class SettingsFeature:
|
|
17
|
+
|
|
18
|
+
# Entrypoint
|
|
19
|
+
@staticmethod
|
|
20
|
+
def entrypoint(options: Namespace) -> bool:
|
|
21
|
+
|
|
22
|
+
# Variables
|
|
23
|
+
group: Group = None
|
|
24
|
+
project: Project = None
|
|
25
|
+
|
|
26
|
+
# Header
|
|
27
|
+
print(' ')
|
|
28
|
+
|
|
29
|
+
# GitLab client
|
|
30
|
+
gitlab = GitLabFeature(options.gitlab, options.token, options.dry_run)
|
|
31
|
+
print(f'{Colors.BOLD} - GitLab host: '
|
|
32
|
+
f'{Colors.GREEN}{gitlab.url}'
|
|
33
|
+
f'{Colors.RESET}')
|
|
34
|
+
Platform.flush()
|
|
35
|
+
|
|
36
|
+
# GitLab path
|
|
37
|
+
try:
|
|
38
|
+
group = gitlab.group(options.path)
|
|
39
|
+
print(f'{Colors.BOLD} - GitLab group: '
|
|
40
|
+
f'{Colors.GREEN}{group.full_path} ({group.description})'
|
|
41
|
+
f'{Colors.RESET}')
|
|
42
|
+
print(' ')
|
|
43
|
+
Platform.flush()
|
|
44
|
+
except GitlabGetError:
|
|
45
|
+
project = gitlab.project(options.path)
|
|
46
|
+
print(f'{Colors.BOLD} - GitLab project: '
|
|
47
|
+
f'{Colors.GREEN}{project.path_with_namespace} ({project.description})'
|
|
48
|
+
f'{Colors.RESET}')
|
|
49
|
+
print(' ')
|
|
50
|
+
Platform.flush()
|
|
51
|
+
|
|
52
|
+
# Handle single project
|
|
53
|
+
if project:
|
|
54
|
+
SettingsFeature.project(options, gitlab, project.id)
|
|
55
|
+
|
|
56
|
+
# Handle group recursively
|
|
57
|
+
elif group:
|
|
58
|
+
|
|
59
|
+
# Handle group
|
|
60
|
+
if not options.avoid_group:
|
|
61
|
+
SettingsFeature.group(options, gitlab, group.id)
|
|
62
|
+
|
|
63
|
+
# Iterate through subgroups
|
|
64
|
+
if not options.avoid_subgroups:
|
|
65
|
+
for group_subgroup in group.descendant_groups.list(
|
|
66
|
+
get_all=True,
|
|
67
|
+
include_subgroups=True,
|
|
68
|
+
order_by='path',
|
|
69
|
+
sort='asc',
|
|
70
|
+
):
|
|
71
|
+
SettingsFeature.group(options, gitlab, group_subgroup.id)
|
|
72
|
+
|
|
73
|
+
# Iterate through projects
|
|
74
|
+
if not options.avoid_projects:
|
|
75
|
+
for group_project in group.projects.list(
|
|
76
|
+
get_all=True,
|
|
77
|
+
include_subgroups=not options.avoid_subgroups,
|
|
78
|
+
order_by='path',
|
|
79
|
+
sort='asc',
|
|
80
|
+
):
|
|
81
|
+
SettingsFeature.project(options, gitlab, group_project.id)
|
|
82
|
+
|
|
83
|
+
# Result
|
|
84
|
+
return True
|
|
85
|
+
|
|
86
|
+
# GitLab projects settings project, pylint: disable=too-many-branches
|
|
87
|
+
@staticmethod
|
|
88
|
+
def project(options: Namespace, gitlab: GitLabFeature, criteria: str) -> None:
|
|
89
|
+
|
|
90
|
+
# Show project details
|
|
91
|
+
project = gitlab.project(criteria)
|
|
92
|
+
print(f'{Colors.BOLD} - GitLab project: '
|
|
93
|
+
f'{Colors.YELLOW_LIGHT}{project.path_with_namespace} '
|
|
94
|
+
f'{Colors.CYAN}({project.description})'
|
|
95
|
+
f'{Colors.RESET}')
|
|
96
|
+
|
|
97
|
+
# Set project description
|
|
98
|
+
if options.set_description:
|
|
99
|
+
gitlab.project_set_description(criteria, options.set_description)
|
|
100
|
+
print(f'{Colors.BOLD} - Set description: '
|
|
101
|
+
f'{Colors.CYAN}{options.set_description}'
|
|
102
|
+
f'{Colors.RESET}')
|
|
103
|
+
|
|
104
|
+
# Update project description
|
|
105
|
+
elif options.update_description:
|
|
106
|
+
description = f'{project.name[:1].capitalize()}{project.name[1:]}' \
|
|
107
|
+
f' - description'
|
|
108
|
+
gitlab.project_set_description(criteria, description)
|
|
109
|
+
print(f'{Colors.BOLD} - Updated description: '
|
|
110
|
+
f'{Colors.CYAN}{description}'
|
|
111
|
+
f'{Colors.RESET}')
|
|
112
|
+
|
|
113
|
+
# Reset project features
|
|
114
|
+
if options.reset_features:
|
|
115
|
+
features = ', '.join(gitlab.project_reset_features(criteria))
|
|
116
|
+
if features:
|
|
117
|
+
print(f'{Colors.BOLD} - Reset features: '
|
|
118
|
+
f'{Colors.CYAN}{features}'
|
|
119
|
+
f'{Colors.RESET}')
|
|
120
|
+
else:
|
|
121
|
+
print(f'{Colors.BOLD} - Reset features: '
|
|
122
|
+
f'{Colors.GREEN}Already done'
|
|
123
|
+
f'{Colors.RESET}')
|
|
124
|
+
|
|
125
|
+
# Reset project members
|
|
126
|
+
if options.reset_members:
|
|
127
|
+
gitlab.project_reset_members(criteria)
|
|
128
|
+
print(f'{Colors.BOLD} - Reset members: '
|
|
129
|
+
f'{Colors.GREEN}Success'
|
|
130
|
+
f'{Colors.RESET}')
|
|
131
|
+
|
|
132
|
+
# Set project avatar
|
|
133
|
+
if options.set_avatar:
|
|
134
|
+
gitlab.project_set_avatar(criteria, options.set_avatar)
|
|
135
|
+
print(f'{Colors.BOLD} - Set avatar: '
|
|
136
|
+
f'{Colors.CYAN}{options.set_avatar}'
|
|
137
|
+
f'{Colors.RESET}')
|
|
138
|
+
|
|
139
|
+
# Protect project branches
|
|
140
|
+
if options.protect_branches:
|
|
141
|
+
branches = ', '.join(gitlab.project_protect_branches(criteria))
|
|
142
|
+
if branches:
|
|
143
|
+
print(f'{Colors.BOLD} - Protecting branches: '
|
|
144
|
+
f'{Colors.CYAN}{branches}'
|
|
145
|
+
f'{Colors.RESET}')
|
|
146
|
+
else:
|
|
147
|
+
print(f'{Colors.BOLD} - Protecting branches: '
|
|
148
|
+
f'{Colors.GREEN}Already done'
|
|
149
|
+
f'{Colors.RESET}')
|
|
150
|
+
|
|
151
|
+
# Protect project tags
|
|
152
|
+
if options.protect_tags:
|
|
153
|
+
tags = ', '.join(gitlab.project_protect_tags(criteria, options.protect_tags))
|
|
154
|
+
if tags:
|
|
155
|
+
print(f'{Colors.BOLD} - Protecting tags: '
|
|
156
|
+
f'{Colors.CYAN}{tags}'
|
|
157
|
+
f'{Colors.GREEN} (level: {options.protect_tags})'
|
|
158
|
+
f'{Colors.RESET}')
|
|
159
|
+
else:
|
|
160
|
+
print(f'{Colors.BOLD} - Protecting tags: '
|
|
161
|
+
f'{Colors.GREEN}Already done'
|
|
162
|
+
f'{Colors.RESET}')
|
|
163
|
+
|
|
164
|
+
# Footer
|
|
165
|
+
print(' ')
|
|
166
|
+
Platform.flush()
|
|
167
|
+
|
|
168
|
+
# GitLab projects settings group
|
|
169
|
+
@staticmethod
|
|
170
|
+
def group(options: Namespace, gitlab: GitLabFeature, criteria: str,
|
|
171
|
+
subgroup: bool = False) -> None:
|
|
172
|
+
|
|
173
|
+
# Show group details
|
|
174
|
+
group = gitlab.group(criteria)
|
|
175
|
+
group_type = 'subgroup' if subgroup else 'group'
|
|
176
|
+
print(f'{Colors.BOLD} - GitLab {group_type}: '
|
|
177
|
+
f'{Colors.YELLOW_LIGHT}{group.full_path} '
|
|
178
|
+
f'{Colors.CYAN}({group.description})'
|
|
179
|
+
f'{Colors.RESET}')
|
|
180
|
+
|
|
181
|
+
# Set group description
|
|
182
|
+
if options.set_description:
|
|
183
|
+
gitlab.group_set_description(criteria, options.set_description)
|
|
184
|
+
print(f'{Colors.BOLD} - Set description: '
|
|
185
|
+
f'{Colors.CYAN}{options.set_description}'
|
|
186
|
+
f'{Colors.RESET}')
|
|
187
|
+
|
|
188
|
+
# Update group description
|
|
189
|
+
elif options.update_description:
|
|
190
|
+
description = f'{group.name[:1].capitalize()}{group.name[1:]}' \
|
|
191
|
+
f' - description'
|
|
192
|
+
gitlab.group_set_description(criteria, description)
|
|
193
|
+
print(f'{Colors.BOLD} - Updated description: '
|
|
194
|
+
f'{Colors.CYAN}{description}'
|
|
195
|
+
f'{Colors.RESET}')
|
|
196
|
+
|
|
197
|
+
# Reset group members
|
|
198
|
+
if options.reset_members:
|
|
199
|
+
gitlab.group_reset_members(criteria)
|
|
200
|
+
print(f'{Colors.BOLD} - Reset members: '
|
|
201
|
+
f'{Colors.GREEN}Success'
|
|
202
|
+
f'{Colors.RESET}')
|
|
203
|
+
|
|
204
|
+
# Set group avatar
|
|
205
|
+
if options.set_avatar:
|
|
206
|
+
gitlab.group_set_avatar(criteria, options.set_avatar)
|
|
207
|
+
print(f'{Colors.BOLD} - Set avatar: '
|
|
208
|
+
f'{Colors.CYAN}{options.set_avatar}'
|
|
209
|
+
f'{Colors.RESET}')
|
|
210
|
+
|
|
211
|
+
# Footer
|
|
212
|
+
print(' ')
|
|
213
|
+
Platform.flush()
|
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Bundle class, pylint: disable=too-few-public-methods
|
|
4
|
+
class Bundle:
|
|
5
|
+
|
|
6
|
+
# Names
|
|
7
|
+
NAME: str = 'gitlab-projects-settings'
|
|
8
|
+
|
|
9
|
+
# Details
|
|
10
|
+
DESCRIPTION: str = 'Configure GitLab groups and projects settings automatically'
|
|
11
|
+
|
|
12
|
+
# Sources
|
|
13
|
+
REPOSITORY: str = 'https://gitlab.com/AdrianDC/gitlab-projects-settings'
|
|
14
|
+
|
|
15
|
+
# Environment
|
|
16
|
+
ENV_GITLAB_TOKEN: str = 'GITLAB_TOKEN'
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Standard libraries
|
|
4
|
+
from sys import version_info
|
|
5
|
+
|
|
6
|
+
# Components
|
|
7
|
+
from ..system.platform import Platform
|
|
8
|
+
from .bundle import Bundle
|
|
9
|
+
|
|
10
|
+
# Version class
|
|
11
|
+
class Version:
|
|
12
|
+
|
|
13
|
+
# Getter
|
|
14
|
+
@staticmethod
|
|
15
|
+
def get() -> str:
|
|
16
|
+
|
|
17
|
+
# Acquire version from metadata
|
|
18
|
+
try:
|
|
19
|
+
from importlib import metadata # pylint: disable=import-outside-toplevel
|
|
20
|
+
return metadata.version(Bundle.NAME)
|
|
21
|
+
except Exception: # pylint: disable=broad-exception-caught # pragma: no cover
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
# Acquire version from resources
|
|
25
|
+
try: # pragma: no cover
|
|
26
|
+
from pkg_resources import require # pylint: disable=import-outside-toplevel
|
|
27
|
+
name = __name__.split('.', maxsplit=1)[0]
|
|
28
|
+
return str(require(name)[0].version)
|
|
29
|
+
|
|
30
|
+
# Default fallback
|
|
31
|
+
except Exception: # pylint: disable=broad-exception-caught # pragma: no cover
|
|
32
|
+
return '0.0.0'
|
|
33
|
+
|
|
34
|
+
# Path
|
|
35
|
+
@staticmethod
|
|
36
|
+
def path() -> str:
|
|
37
|
+
|
|
38
|
+
# Acquire path
|
|
39
|
+
path = __file__
|
|
40
|
+
|
|
41
|
+
# Strip package path
|
|
42
|
+
index = path.rfind(Platform.PATH_SEPARATOR)
|
|
43
|
+
index = path.rfind(Platform.PATH_SEPARATOR, 0, index)
|
|
44
|
+
path = path[0:index]
|
|
45
|
+
|
|
46
|
+
# Result
|
|
47
|
+
return path
|
|
48
|
+
|
|
49
|
+
# Python
|
|
50
|
+
@staticmethod
|
|
51
|
+
def python() -> str:
|
|
52
|
+
|
|
53
|
+
# Acquire Python version
|
|
54
|
+
version = f'{version_info.major}.{version_info.minor}'
|
|
55
|
+
|
|
56
|
+
# Result
|
|
57
|
+
return version
|
|
File without changes
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Standard libraries
|
|
4
|
+
from typing import List
|
|
5
|
+
|
|
6
|
+
# Modules libraries
|
|
7
|
+
try:
|
|
8
|
+
try: # colored>=2.0.0
|
|
9
|
+
from colored import Colored
|
|
10
|
+
except ImportError: # colored<2.0.0, pragma: no cover
|
|
11
|
+
from colored import colored as Colored
|
|
12
|
+
except ModuleNotFoundError: # pragma: no cover
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
# Colors class, pylint: disable=too-few-public-methods
|
|
16
|
+
class Colors:
|
|
17
|
+
|
|
18
|
+
# Attributes
|
|
19
|
+
ALL: List[str] = []
|
|
20
|
+
BOLD = ''
|
|
21
|
+
CYAN = ''
|
|
22
|
+
GREEN = ''
|
|
23
|
+
GREY = ''
|
|
24
|
+
RED = ''
|
|
25
|
+
RESET = ''
|
|
26
|
+
YELLOW = ''
|
|
27
|
+
YELLOW_LIGHT = ''
|
|
28
|
+
|
|
29
|
+
# Enabled
|
|
30
|
+
@staticmethod
|
|
31
|
+
def enabled() -> bool:
|
|
32
|
+
|
|
33
|
+
# Result
|
|
34
|
+
try:
|
|
35
|
+
return bool(Colored('').enabled())
|
|
36
|
+
except (NameError, TypeError): # pragma: no cover
|
|
37
|
+
return False
|
|
38
|
+
|
|
39
|
+
# Prepare
|
|
40
|
+
@staticmethod
|
|
41
|
+
def prepare() -> None:
|
|
42
|
+
|
|
43
|
+
# Colors enabled
|
|
44
|
+
if Colors.enabled():
|
|
45
|
+
Colors.RESET = Colored('reset').attribute()
|
|
46
|
+
Colors.BOLD = Colors.RESET + Colored('bold').attribute()
|
|
47
|
+
Colors.CYAN = Colors.BOLD + Colored('cyan').foreground()
|
|
48
|
+
Colors.GREEN = Colors.BOLD + Colored('green').foreground()
|
|
49
|
+
Colors.GREY = Colors.BOLD + Colored('light_gray').foreground()
|
|
50
|
+
Colors.RED = Colors.BOLD + Colored('red').foreground()
|
|
51
|
+
Colors.YELLOW = Colors.BOLD + Colored('yellow').foreground()
|
|
52
|
+
Colors.YELLOW_LIGHT = Colors.BOLD + Colored('light_yellow').foreground()
|
|
53
|
+
Colors.ALL = [
|
|
54
|
+
Colors.CYAN,
|
|
55
|
+
Colors.GREEN,
|
|
56
|
+
Colors.GREY,
|
|
57
|
+
Colors.RED,
|
|
58
|
+
Colors.YELLOW,
|
|
59
|
+
Colors.YELLOW_LIGHT,
|
|
60
|
+
Colors.BOLD,
|
|
61
|
+
Colors.RESET,
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
# Colors disabled
|
|
65
|
+
else:
|
|
66
|
+
Colors.BOLD = ''
|
|
67
|
+
Colors.CYAN = ''
|
|
68
|
+
Colors.GREEN = ''
|
|
69
|
+
Colors.GREY = ''
|
|
70
|
+
Colors.RED = ''
|
|
71
|
+
Colors.RESET = ''
|
|
72
|
+
Colors.YELLOW = ''
|
|
73
|
+
Colors.YELLOW_LIGHT = ''
|
|
74
|
+
Colors.ALL = []
|
|
75
|
+
|
|
76
|
+
# Strip
|
|
77
|
+
@staticmethod
|
|
78
|
+
def strip(string: str) -> str:
|
|
79
|
+
|
|
80
|
+
# Strip all colors
|
|
81
|
+
for item in Colors.ALL:
|
|
82
|
+
string = string.replace(item, '')
|
|
83
|
+
|
|
84
|
+
# Result
|
|
85
|
+
return string
|
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
# Standard libraries
|
|
4
|
+
from os import sep
|
|
5
|
+
from sys import platform, stdin, stdout
|
|
6
|
+
|
|
7
|
+
# Platform, pylint: disable=too-few-public-methods
|
|
8
|
+
class Platform:
|
|
9
|
+
|
|
10
|
+
# Constants
|
|
11
|
+
IS_LINUX: bool = platform in ['linux', 'linux2']
|
|
12
|
+
IS_WINDOWS: bool = platform in ['win32', 'win64']
|
|
13
|
+
|
|
14
|
+
# Separators
|
|
15
|
+
PATH_SEPARATOR: str = sep
|
|
16
|
+
|
|
17
|
+
# TTYs
|
|
18
|
+
IS_TTY_STDIN: bool = stdin.isatty() and stdin.encoding != 'cp1252'
|
|
19
|
+
IS_TTY_STDOUT: bool = stdout.isatty()
|
|
20
|
+
IS_TTY_UTF8: bool = str(stdout.encoding).lower() == 'utf-8'
|
|
21
|
+
|
|
22
|
+
# Flush
|
|
23
|
+
@staticmethod
|
|
24
|
+
def flush() -> None:
|
|
25
|
+
|
|
26
|
+
# Flush output
|
|
27
|
+
print('', end='', flush=Platform.IS_TTY_STDOUT)
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: gitlab-projects-settings
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Migrate GitLab projects from a GitLab group to another GitLab's group
|
|
5
|
+
Home-page: https://gitlab.com/AdrianDC/gitlab-projects-settings
|
|
6
|
+
Author: Adrian DC
|
|
7
|
+
Author-email: radian.dc@gmail.com
|
|
8
|
+
License: Apache License 2.0
|
|
9
|
+
Project-URL: Bug Reports, https://gitlab.com/AdrianDC/gitlab-projects-settings/-/issues
|
|
10
|
+
Project-URL: Changelog, https://gitlab.com/AdrianDC/gitlab-projects-settings/blob/main/CHANGELOG.md
|
|
11
|
+
Project-URL: Documentation, https://gitlab.com/AdrianDC/gitlab-projects-settings#gitlab-projects-settings
|
|
12
|
+
Project-URL: Source, https://gitlab.com/AdrianDC/gitlab-projects-settings
|
|
13
|
+
Project-URL: Statistics, https://pypistats.org/packages/gitlab-projects-settings
|
|
14
|
+
Keywords: gitlab issues sync
|
|
15
|
+
Classifier: Environment :: Console
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
26
|
+
Classifier: Topic :: Software Development
|
|
27
|
+
Classifier: Topic :: Utilities
|
|
28
|
+
Requires-Python: >=3, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Requires-Dist: colored >=1.4.2
|
|
32
|
+
Requires-Dist: python-gitlab >=4.4.0
|
|
33
|
+
Requires-Dist: setuptools >=45.1.0
|
|
34
|
+
|
|
35
|
+
# gitlab-projects-settings
|
|
36
|
+
|
|
37
|
+
<!-- markdownlint-disable no-inline-html -->
|
|
38
|
+
|
|
39
|
+
[](https://gitlab.com/AdrianDC/gitlab-projects-settings/-/commits/main/)
|
|
40
|
+
|
|
41
|
+
Configure GitLab groups and projects settings automatically
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Purpose
|
|
46
|
+
|
|
47
|
+
This tool can automatically configure and update the GitLab settings
|
|
48
|
+
of groups, subgroups and projects, using multiple available options.
|
|
49
|
+
|
|
50
|
+
Repetitive tasks can be performed accross multiple projects at once,
|
|
51
|
+
for example protecting tags and branches, or setting a new avatar recursively.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Usage
|
|
56
|
+
|
|
57
|
+
<!-- prettier-ignore-start -->
|
|
58
|
+
|
|
59
|
+
```yaml
|
|
60
|
+
usage: gitlab-projects-settings [-h] [--version] [-t TOKEN] [--dry-run] [--avoid-group]
|
|
61
|
+
[--avoid-subgroups] [--avoid-projects] [--reset-features]
|
|
62
|
+
[--reset-members] [--set-avatar FILE] [--set-description TEXT]
|
|
63
|
+
[--update-description] [--protect-branches]
|
|
64
|
+
[--protect-tags LEVEL]
|
|
65
|
+
[gitlab] [path]
|
|
66
|
+
|
|
67
|
+
gitlab-projects-settings: Configure GitLab groups and projects settings automatically
|
|
68
|
+
|
|
69
|
+
internal arguments:
|
|
70
|
+
-h, --help # Show this help message
|
|
71
|
+
--version # Show the current version
|
|
72
|
+
|
|
73
|
+
credentials arguments:
|
|
74
|
+
-t TOKEN # GitLab API token (default: GITLAB_TOKEN environment)
|
|
75
|
+
|
|
76
|
+
common settings arguments:
|
|
77
|
+
--dry-run # Enable dry run mode to check without saving
|
|
78
|
+
--avoid-group # Avoid affecting parent group settings
|
|
79
|
+
--avoid-subgroups # Avoid affecting children subgroups settings
|
|
80
|
+
--avoid-projects # Avoid affecting children projects settings
|
|
81
|
+
|
|
82
|
+
general settings arguments:
|
|
83
|
+
--reset-features # Reset features of GitLab projects based on usage
|
|
84
|
+
--reset-members # Reset members of GitLab projects and groups
|
|
85
|
+
--set-avatar FILE # Set avatar of GitLab projects and groups
|
|
86
|
+
--set-description TEXT
|
|
87
|
+
# Set description of GitLab projects and groups
|
|
88
|
+
--update-description # Update description of GitLab projects and groups automatically
|
|
89
|
+
|
|
90
|
+
repository settings arguments:
|
|
91
|
+
--protect-branches # Protect branches with default master/main, develop and staging
|
|
92
|
+
--protect-tags LEVEL # Protect tags at level [no-one,admins,maintainers,developers]
|
|
93
|
+
|
|
94
|
+
positional arguments:
|
|
95
|
+
gitlab # GitLab URL (default: https://gitlab.com)
|
|
96
|
+
path # GitLab group or project path
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
<!-- prettier-ignore-end -->
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Dependencies
|
|
104
|
+
|
|
105
|
+
- [colored](https://pypi.org/project/colored/): Terminal colors and styles
|
|
106
|
+
- [python-gitlab](https://pypi.org/project/python-gitlab/): A python wrapper for the GitLab API
|
|
107
|
+
- [setuptools](https://pypi.org/project/setuptools/): Build and manage Python packages
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## References
|
|
112
|
+
|
|
113
|
+
- [git-chglog](https://github.com/git-chglog/git-chglog): CHANGELOG generator
|
|
114
|
+
- [gitlab-release](https://pypi.org/project/gitlab-release/): Utility for publishing on GitLab
|
|
115
|
+
- [gitlabci-local](https://pypi.org/project/gitlabci-local/): Launch .gitlab-ci.yml jobs locally
|
|
116
|
+
- [mypy](https://pypi.org/project/mypy/): Optional static typing for Python
|
|
117
|
+
- [PyPI](https://pypi.org/): The Python Package Index
|
|
118
|
+
- [twine](https://pypi.org/project/twine/): Utility for publishing on PyPI
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
gitlab_projects_settings/__init__.py,sha256=n41iWlNc1-bRIbDPAH1L0o4nIzC-qIWpynop78EeUKA,113
|
|
2
|
+
gitlab_projects_settings/__main__.py,sha256=hkYZJBCbOdKzzF558kfDUJKA_xx2TyKoOczHlTJX3ck,85
|
|
3
|
+
gitlab_projects_settings/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
gitlab_projects_settings/cli/main.py,sha256=1cPMxkVFNKcAXoj6fTvIJGiZPFzQF1Up3FwgkhZB0JI,5331
|
|
5
|
+
gitlab_projects_settings/features/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
gitlab_projects_settings/features/gitlab.py,sha256=o7wqQ8tCZkIZczJp3INHgq8isviNjFOcn_-VPeb-sGs,11344
|
|
7
|
+
gitlab_projects_settings/features/settings.py,sha256=Cx4aoT4UaE-ejedPmaEpu1Q5143mc4dYnEXsTqa5FcE,7772
|
|
8
|
+
gitlab_projects_settings/package/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
gitlab_projects_settings/package/bundle.py,sha256=NUdqd_YPBbXbMsxXxSBrmKtKZ0SUuwajpkZ8qaog2ng,403
|
|
10
|
+
gitlab_projects_settings/package/version.py,sha256=FIPxVt1Lq9v33_McMGq6knJIPJmDhGqKY0xwJBmfnEo,1444
|
|
11
|
+
gitlab_projects_settings/prints/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
|
+
gitlab_projects_settings/prints/colors.py,sha256=vjenJ5BeGq5OSfB65mzkZpTDa7lSvVcw7AmiWnCJgFI,2262
|
|
13
|
+
gitlab_projects_settings/system/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
|
+
gitlab_projects_settings/system/platform.py,sha256=Ktf8jGZYUCuQnRUO8s1UM8-MdTap7jEN1nI_m7tsFjE,669
|
|
15
|
+
gitlab_projects_settings-1.0.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
16
|
+
gitlab_projects_settings-1.0.0.dist-info/METADATA,sha256=qHFW9AEiRl5Grzv517dwyU8OhAv6WD6Ot_FQ2N-nwHg,4937
|
|
17
|
+
gitlab_projects_settings-1.0.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
18
|
+
gitlab_projects_settings-1.0.0.dist-info/entry_points.txt,sha256=4u2pTghP2WldeK1wcwp3JUEDZFmkx5tx6h1yFP5QrVI,84
|
|
19
|
+
gitlab_projects_settings-1.0.0.dist-info/top_level.txt,sha256=Vsj_AyqKoDdIcs8aZ-xDmOYGD3O3aS-y-mGeuUSX9k0,25
|
|
20
|
+
gitlab_projects_settings-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
gitlab_projects_settings
|