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
d15c753b
Commit
d15c753b
authored
1 month ago
by
Adrien Lescourt
Browse files
Options
Downloads
Patches
Plain Diff
Fix repos creation
parent
32487b04
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pwm/pwm.py
+21
-6
21 additions, 6 deletions
pwm/pwm.py
with
21 additions
and
6 deletions
pwm/pwm.py
+
21
−
6
View file @
d15c753b
...
...
@@ -101,6 +101,17 @@ class Gitlab:
else
:
print
(
"
Group
"
+
group_id
+
"
successfully deleted
"
)
def
get_user_id
(
self
,
user
:
User
)
->
str
|
None
:
headers
=
{
"
PRIVATE-TOKEN
"
:
self
.
token
}
res
=
requests
.
get
(
BASE_API_URL
+
"
/users
"
,
params
=
{
"
search
"
:
user
.
id
},
headers
=
headers
)
if
res
.
status_code
!=
200
:
print
(
f
"
Error searching user
{
user
.
id
}
"
)
print
(
res
.
text
)
else
:
return
res
.
json
()[
0
][
"
id
"
]
def
create_repository
(
self
,
group_id
:
str
,
...
...
@@ -119,6 +130,7 @@ class Gitlab:
params
=
{
"
name
"
:
name
,
"
namespace_id
"
:
group_id
,
"
visibility
"
:
"
private
"
}
if
import_url
:
params
[
"
import_url
"
]
=
import_url
project
=
requests
.
post
(
BASE_API_URL
+
"
/projects
"
,
params
=
params
,
headers
=
headers
).
json
()
...
...
@@ -144,18 +156,21 @@ class Gitlab:
# Add each student as maintainer (level 40)
for
user
in
users
:
print
(
user
)
params
=
{
"
user_id
"
:
user
.
id
,
"
access_level
"
:
access_level
}
user_id
=
self
.
get_user_id
(
user
)
if
user_id
is
None
:
print
(
f
"
ERROR: User
{
user
.
id
}
will not be added to project:
{
name
}
"
)
params
=
{
"
user_id
"
:
user_id
,
"
access_level
"
:
access_level
}
if
expires_at
:
params
[
"
expires_at
"
]
=
expires_at
new_user
=
requests
.
post
(
res
=
requests
.
post
(
BASE_API_URL
+
"
/projects/
"
+
str
(
project
[
"
id
"
])
+
"
/members
"
,
params
=
params
,
headers
=
headers
,
)
.
json
()
if
"
message
"
in
new_user
:
print
(
"
Error in adding user: %s
"
%
new_user
)
)
if
res
.
status_code
!=
201
:
print
(
res
.
text
)
else
:
new_user
=
res
.
json
()
out
=
(
"
Adding
'"
+
new_user
[
"
name
"
]
...
...
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