Commit eaa2342e authored by Henrik Skov Midtiby's avatar Henrik Skov Midtiby

Added desriptions of the functions.

parent 53697ee1
Pipeline #6420 canceled with stages
......@@ -8,31 +8,51 @@ def gitlab_url_api4(path):
return '' + 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'/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'/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".
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():
# Fetch commits from repository 692 -
# camera-calibration-using-extended-chessboard
# Fetch and show commits from repository 692 -
resp = get_commits(692)
for item in resp.json():
......@@ -77,6 +97,13 @@ def create_assignment_project(
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.
resp = create_a_new_repository_in_group(project_name, group_id)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment