Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
practical-work-manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ISC
projects
practical-work-manager
Commits
45fc6885
Commit
45fc6885
authored
1 year ago
by
Guillaume Chanel
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' into repos_file_generator
parents
c83c7c52
1eaa9f09
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#26461
failed
1 year ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pwm
+14
-4
14 additions, 4 deletions
pwm
with
14 additions
and
4 deletions
pwm
+
14
−
4
View file @
45fc6885
...
...
@@ -62,8 +62,12 @@ def emails_to_ids(emails: List[str], headers: Dict[str, str]) -> List[int]:
for
email
in
emails
:
# Dirty and hackish way that attempts to extract the username from the email.
# It's inefficient, but currently there is no
w
way to reliably obtain
# It's inefficient, but currently there is no way to reliably obtain
# the username from the email.
# new strategy: - stop when we reach the "." or when we get more than 1 result
# Example of tricky users:
# pierre-louis.roden@etu.hesge.ch -> login AAI: pierrelo.roden
# joel.ferreirapinto@etu.hesge.ch -> login AAI: joelfili.ferreira
username
=
email
.
split
(
"
@
"
)[
0
]
#print("Email: ",email)
...
...
@@ -71,11 +75,17 @@ def emails_to_ids(emails: List[str], headers: Dict[str, str]) -> List[int]:
#print("Guessed username: ",username)
user_requested
=
requests
.
get
(
BASE_API_URL
+
'
/users
'
,
params
=
{
'
search
'
:
username
},
headers
=
headers
).
json
()
if
len
(
user_requested
)
==
0
:
nb_users
=
len
(
user_requested
)
if
nb_users
==
0
:
#print('No user %s found, another try...' % email)
lastchar
=
username
[
-
1
]
username
=
username
.
rstrip
(
lastchar
)
if
username
[
-
1
]
==
'
.
'
:
# stop if we reach the . -> probably at least one wrong person match the first name
break
continue
elif
nb_users
>
1
:
print
(
'
Too many users found for email %s, aborting.
'
%
email
)
exit
(
1
)
#print(json.dumps(user_requested, indent=4))
user_ids
.
append
(
user_requested
[
0
][
'
id
'
])
...
...
@@ -104,7 +114,7 @@ def create_repository(token: str, group_id: str, emails: List[str], name: str, i
project
[
'
web_url
'
]
+
"'
created
"
)
# Allow users with developer access level to push and merge on master
access_level
=
3
0
access_level
=
4
0
params
=
{
'
name
'
:
'
master
'
,
'
push_access_level
'
:
str
(
access_level
),
'
merge_access_level
'
:
str
(
access_level
)}
requests
.
post
(
BASE_API_URL
+
'
/projects/
'
+
...
...
@@ -113,7 +123,7 @@ def create_repository(token: str, group_id: str, emails: List[str], name: str, i
# Get students ids from their emails
user_ids
=
emails_to_ids
(
emails
,
headers
)
# Add each student as
project's develop
er (level
3
0)
# Add each student as
maintain
er (level
4
0)
for
user_id
in
user_ids
:
params
=
{
'
user_id
'
:
user_id
,
'
access_level
'
:
access_level
}
if
expires_at
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment