Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Henrik Skov Midtiby
gitlab-assignment-handler
Commits
eaa2342e
Commit
eaa2342e
authored
Oct 26, 2019
by
Henrik Skov Midtiby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added desriptions of the functions.
parent
53697ee1
Pipeline
#6420
canceled with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
2 deletions
+29
-2
create_repository.py
create_repository.py
+29
-2
No files found.
create_repository.py
View file @
eaa2342e
...
...
@@ -8,31 +8,51 @@ def gitlab_url_api4(path):
return
'https://source.coderefinery.org/api/v4'
+
path
def
get_commits
(
repository_id
):
"""
Fetch commits from the project with id "project_id".
"""
url
=
gitlab_url_api4
(
"/projects/%d/repository/commits"
%
repository_id
)
return
requests
.
get
(
url
,
headers
=
{
'Authorization'
:
'Bearer {}'
.
format
(
config
.
PersonalAcessToken
)})
def
get_project_details
(
project_id
):
"""
Fetch project details about the project with id "project_id".
"""
url
=
gitlab_url_api4
(
"/projects/%d"
%
project_id
)
return
requests
.
get
(
url
,
headers
=
{
'Authorization'
:
'Bearer {}'
.
format
(
config
.
PersonalAcessToken
)})
def
create_a_new_repository
(
repo_name
):
"""
Create a new repository with the specified name.
"""
return
requests
.
post
(
gitlab_url_api4
(
'/projects?name=%s'
%
repo_name
),
headers
=
{
'Authorization'
:
'Bearer {}'
.
format
(
config
.
PersonalAcessToken
)})
def
create_a_new_repository_in_group
(
repo_name
,
group_id
):
"""
Create a new project with the name "repo_name".
The project is placed in the namespace with id "group_id".
"""
return
requests
.
post
(
gitlab_url_api4
(
'/projects?name=%s&namespace_id=%d'
%
(
repo_name
,
group_id
)),
headers
=
{
'Authorization'
:
'Bearer {}'
.
format
(
config
.
PersonalAcessToken
)})
def
add_user_to_project
(
project_id
,
user_id
):
"""
Add user with id "user_id" to the project with id "project_id".
"""
return
requests
.
post
(
gitlab_url_api4
(
'/projects/%d/members?user_id=%d&access_level=30'
%
(
project_id
,
user_id
)),
headers
=
{
'Authorization'
:
'Bearer {}'
.
format
(
config
.
PersonalAcessToken
)})
def
push_git_repository_content_to_project
(
path_to_git_repository
,
project_id
):
"""
Push the local git repository located at "path_to_git_repository"
to the project with id "project_id".
"""
repo
=
git
.
Repo
(
path_to_git_repository
)
resp
=
get_project_details
(
project_id
)
temp
=
resp
.
json
()
...
...
@@ -41,8 +61,8 @@ def push_git_repository_content_to_project(path_to_git_repository, project_id):
def
fetch_and_show_commits_example
():
print
(
"fetch_and_show_commits_example"
)
# Fetch commits from repository 692 -
# camera-calibration-
using-extended
-chessboard
# Fetch
and show
commits from repository 692 -
#
https://source.coderefinery.org/sdu-uas-center/perception/
camera-calibration-
with-large
-chessboard
s
resp
=
get_commits
(
692
)
print
(
resp
)
for
item
in
resp
.
json
():
...
...
@@ -77,6 +97,13 @@ def create_assignment_project(
student_id
,
group_id
,
path_to_git_repository
):
"""
Create a new project with the name 'project_name' in the namespace
provided by the group with id 'group_id'.
Add the student with id 'student_id' to the project.
Push the current content of the local git repository at the location
'path_to_git_repository' to the project.
"""
print
(
"create_a_new_repository_example"
)
resp
=
create_a_new_repository_in_group
(
project_name
,
group_id
)
print
(
resp
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment