{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "e8e57c62-9e6b-45a4-9c2e-f59702bc8a91", "metadata": {}, "outputs": [], "source": [ "import os\n", "from git import Repo" ] }, { "cell_type": "code", "execution_count": 2, "id": "6fcb0699-7800-4fb9-903e-51db762f2805", "metadata": {}, "outputs": [ { "name": "stdin", "output_type": "stream", "text": [ "Gitea Personal Access Token: 9a189bc6133029d4b8b7a331d8f8f8cdbb969e2c\n" ] } ], "source": [ "#Gitea-Token\n", "GITEA_TOKEN = os.getenv('GIT_TOKEN') or input('Gitea Personal Access Token:')" ] }, { "cell_type": "code", "execution_count": 3, "id": "0c040968-c127-42a9-8c56-458ecedc72b5", "metadata": {}, "outputs": [], "source": [ "#Gitea-URL\n", "GITEA_URL = \"gitea.karlkuebelschule.de\"" ] }, { "cell_type": "code", "execution_count": 18, "id": "ed155c5b-d6ed-479e-a827-045c87c6744c", "metadata": {}, "outputs": [], "source": [ "# URL des Gitea-Repositories mit eingebettetem Token\n", "GITEA_REPO=\"10IT_LF05/Test\"" ] }, { "cell_type": "code", "execution_count": 19, "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": 20, "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": 21, "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": 22, "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": 23, "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": 24, "id": "e2401aaa-6f25-4652-8b20-6962045e193c", "metadata": {}, "outputs": [], "source": [ "clone(repo_path)" ] }, { "cell_type": "code", "execution_count": 28, "id": "dfd3e661-5227-43b4-a002-ae55740359d7", "metadata": {}, "outputs": [], "source": [ "commit(repo_path, \"geantwortet\")" ] }, { "cell_type": "code", "execution_count": 29, "id": "ec8d6e2c-516b-4e88-af4e-17592939bbac", "metadata": {}, "outputs": [], "source": [ "push(repo_path)" ] }, { "cell_type": "code", "execution_count": null, "id": "acb4464c-6351-4ea4-a8e6-303b102a6609", "metadata": {}, "outputs": [], "source": [] } ], "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 }