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

Added a jupyter notebook to demonstrate how to use the GitlabClassHelper.

parent 5c6cd85b
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Load required libraries and setup connection to the gitlab instance."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import config\n",
"import pandas as pd\n",
"from gitlab_class_helper import GitlabClassHelper\n",
"class_helper = GitlabClassHelper('https://source.coderefinery.org/api/v4', config.PersonalAcessToken)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Initial setup for a class"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a group for the class, this collects all new repositories in the same location. The id_of_parent_group specifies the location where the new group will be placed in the gitlab server."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class_helper.create_class(\n",
" group_name=\"gitlab-helper-demo-class\",\n",
" id_of_parent_group=715)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating an assignment (day one)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Load list of users and the repositories they should be connected to."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The file containing the repository names and associated students."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with open(\"demo-assignment-group-list.txt\") as fh:\n",
" for line in fh:\n",
" print(line)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"list_of_repo_names = pd.read_csv(\"demo-assignment-group-list.txt\")\n",
"print(list_of_repo_names)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create repositories for the assignment."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class_helper.create_assignment_repositories(\n",
" repositories = list_of_repo_names['repository'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Push local git repository to the new repositories related to the assignment."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class_helper.push_git_repo_to_repositories(\n",
" local_path = \"hw1\",\n",
" repositories = list_of_repo_names['repository'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Unprotect the master branch, so the students can actually push stuff to the master branch."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class_helper.unprotect_master_branch(\n",
" repositories = list_of_repo_names['repository'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Grading an assignment (day two)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Initialize the GitlabClassHelper."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import config\n",
"import pandas as pd\n",
"from gitlab_class_helper import GitlabClassHelper\n",
"class_helper = GitlabClassHelper('https://source.coderefinery.org/api/v4', config.PersonalAcessToken)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class_helper.enter_class(\n",
" group_name = \"gitlab-helper-demo-class\", \n",
" id_of_parent_group = 715)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Download all student responses for the assignment."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"list_of_repo_names = pd.read_csv(\"demo-assignment-group-list.txt\")\n",
"print(list_of_repo_names)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class_helper.clone_repositories(\n",
" repositories = list_of_repo_names['repository'],\n",
" local_path_to_fetch_to = \"assignment1/studentresponses/\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
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