Files
10IT_LF05/.ipynb_checkpoints/gitea-KKS-checkpoint.ipynb
T
2025-04-03 08:07:10 +00:00

178 lines
3.9 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "e8e57c62-9e6b-45a4-9c2e-f59702bc8a91",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from git import Repo"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6fcb0699-7800-4fb9-903e-51db762f2805",
"metadata": {},
"outputs": [],
"source": [
"#Gitea-Token\n",
"GITEA_TOKEN = os.getenv('GIT_TOKEN') or input('Gitea Personal Access Token: ')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0c040968-c127-42a9-8c56-458ecedc72b5",
"metadata": {},
"outputs": [],
"source": [
"#Gitea-URL\n",
"GITEA_URL = \"gitea.karlkuebelschule.de\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ed155c5b-d6ed-479e-a827-045c87c6744c",
"metadata": {},
"outputs": [],
"source": [
"# URL des Gitea-Repositories mit eingebettetem Token\n",
"GITEA_REPO=\"RainerWieland/MINT-01\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3e4a8877-609d-4e3a-8e25-427b020bbcd4",
"metadata": {},
"outputs": [],
"source": [
"# Beachten Sie, dass der Benutzername hier nicht erforderlich ist, da mit einem PAT gearbeitet wird\n",
"repo_url = f'https://{GITEA_TOKEN}@{GITEA_URL}/{GITEA_REPO}.git'"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "714c2c63-aa81-4389-94e9-a7c45e70dddb",
"metadata": {},
"outputs": [],
"source": [
"# Pfad zu Ihrem lokalen Git-Repository\n",
"repo_path = 'MINT-01'"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "aee52656-0a8c-4efd-b92a-c85922488e07",
"metadata": {},
"outputs": [],
"source": [
"def clone(repo_path=None):\n",
" if repo_path==None:\n",
" return\n",
" \n",
" # Repository klonen, falls noch nicht vorhanden\n",
" if not os.path.exists(repo_path):\n",
" Repo.clone_from(repo_url, repo_path)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2bde4f97-55b1-4432-bc45-c305176c8fdc",
"metadata": {},
"outputs": [],
"source": [
"def commit(repo_path=None, commit=\"no comment\"):\n",
" if repo_path==None:\n",
" return \n",
" \n",
" # Repository-Objekt erstellen\n",
" repo = Repo(repo_path)\n",
"\n",
" # Änderungen zu Git hinzufügen\n",
" repo.git.add('--all')\n",
"\n",
" # Änderungen committen\n",
" repo.index.commit(commit)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d044c729-6f29-4c82-9ac6-7c99eb3f493d",
"metadata": {},
"outputs": [],
"source": [
"def push(repo_path=None):\n",
" if repo_path==None:\n",
" return \n",
" \n",
" # Repository-Objekt erstellen\n",
" repo = Repo(repo_path)\n",
" \n",
" # Änderungen pushen\n",
" origin = repo.remote(name='origin')\n",
" origin.push()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e2401aaa-6f25-4652-8b20-6962045e193c",
"metadata": {},
"outputs": [],
"source": [
"clone(repo_path)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dfd3e661-5227-43b4-a002-ae55740359d7",
"metadata": {},
"outputs": [],
"source": [
"commit(repo_path, \"File added\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ec8d6e2c-516b-4e88-af4e-17592939bbac",
"metadata": {},
"outputs": [],
"source": [
"push(repo_path)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.11.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}