From 5873f77afd93c8aa0937f1d54b235b86fabd72e9 Mon Sep 17 00:00:00 2001 From: Robert Haase Date: Sun, 20 Oct 2024 10:33:12 +0200 Subject: [PATCH] add test-notebook for github/lab API --- playground/git_api_test.ipynb | 1047 +++++++++++++++++++++++++++++++++ 1 file changed, 1047 insertions(+) create mode 100644 playground/git_api_test.ipynb diff --git a/playground/git_api_test.ipynb b/playground/git_api_test.ipynb new file mode 100644 index 0000000..0666d34 --- /dev/null +++ b/playground/git_api_test.ipynb @@ -0,0 +1,1047 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "5b32e79f-6b2a-400c-8858-add19aa920a5", + "metadata": {}, + "source": [ + "# Git API test\n", + "This notebook serves testing if the gitlab and github APIs are compatible." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "e429bc05-fb8b-4e02-83da-571d8520d746", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "os.chdir(\"../\")" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "96ad607d-2d96-4d13-b15a-c82440036a75", + "metadata": {}, + "outputs": [], + "source": [ + "import git_bob._gitlab_utilities as gu1\n", + "import git_bob._github_utilities as gu2" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "0e5a8835-57bb-4058-bade-67a8e24d5bd7", + "metadata": {}, + "outputs": [], + "source": [ + "repository = \"haesleinhuepf/git-bob\"" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "33069017-7031-4acd-aa4c-1b4e22d3f391", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " \n", + "\n", + "\n", + " \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu in [gu1, gu2]:\n", + " print(gu, \"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "f4582ea8-6b9c-4953-9705-e967ae625c6b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "main \n", + "\n", + "\n", + "main \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu in [gu1, gu2]:\n", + " print(gu.get_default_branch_name(repository), \"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "b86d90cf-e19a-4fb0-8ea4-1e2c2b921851", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> add_reaction_to_last_comment_in_issue(haesleinhuepf/git-bob, 1, +1)\n", + "None \n", + "\n", + "\n", + "-> add_reaction_to_last_comment_in_issue(haesleinhuepf/git-bob, 1, +1)\n", + "None \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu in [gu1, gu2]:\n", + " print(gu.add_reaction_to_last_comment_in_issue(repository, 1, \"+1\"), \"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "8e1cdbcf-3f6c-4232-9fc5-10b00688c9d3", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> create_issue(haesleinhuepf/git-bob, test4fun, ...)\n", + "13\n", + "-> add_reaction_to_last_comment_in_issue(haesleinhuepf/git-bob, 13, +1)\n", + "None \n", + "\n", + "\n", + "-> add_comment_to_issue(haesleinhuepf/git-bob, 13, ...)\n", + "Comment added to issue #13 in repository haesleinhuepf/git-bob.\n", + "None \n", + "\n", + "\n", + "-> add_reaction_to_last_comment_in_issue(haesleinhuepf/git-bob, 13, +1)\n", + "None \n", + "\n", + "\n", + "-> create_issue(haesleinhuepf/git-bob, test4fun)\n", + "Issue created: #395\n", + "395\n", + "-> add_reaction_to_last_comment_in_issue(haesleinhuepf/git-bob, 395, +1)\n", + "None \n", + "\n", + "\n", + "-> add_comment_to_issue(haesleinhuepf/git-bob, 395, ...)\n", + "Comment added to issue #395 in repository haesleinhuepf/git-bob.\n", + "None \n", + "\n", + "\n", + "-> add_reaction_to_last_comment_in_issue(haesleinhuepf/git-bob, 395, +1)\n", + "None \n", + "\n", + "\n" + ] + } + ], + "source": [ + "from datetime import datetime\n", + "\n", + "current_datetime = datetime.now().strftime(\"%Y-%m-%d %H:%M:%S\")\n", + "\n", + "for gu in [gu1, gu2]:\n", + " issue = gu.create_issue(repository, \"test4fun\", \"hello world again\")\n", + " print(issue)\n", + " print(gu.add_reaction_to_last_comment_in_issue(repository, issue, \"+1\"), \"\\n\\n\")\n", + " print(gu.add_comment_to_issue(repository, issue, \"hello world \" + current_datetime), \"\\n\\n\")\n", + " print(gu.add_reaction_to_last_comment_in_issue(repository, issue, \"+1\"), \"\\n\\n\")\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "f10f007f-a52e-4132-a801-41550cd1d45e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> get_diff_of_pull_request(haesleinhuepf/git-bob, 2)\n", + "File: playground/test.txt -> playground/test.txt\n", + "@@ -0,0 +1 @@\n", + "+hello-world\n", + "\\ No newline at end of file\n", + "\n", + "\n", + "\n", + "-> get_diff_of_pull_request(haesleinhuepf/git-bob, 387)\n", + "https://github.com/haesleinhuepf/git-bob/pull/387.diff\n", + "diff --git a/playground/test.txt b/playground/test.txt\n", + "new file mode 100644\n", + "index 0000000..bdd51cc\n", + "--- /dev/null\n", + "+++ b/playground/test.txt\n", + "@@ -0,0 +1 @@\n", + "+hello-world\n", + "\\ No newline at end of file\n", + "\n" + ] + } + ], + "source": [ + "for gu, pr in zip([gu1, gu2], [2, 387]):\n", + " print(gu.get_diff_of_pull_request(repository, pr))" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "4a77f950-580b-4246-a201-0327f8b80517", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> create_branch(haesleinhuepf/git-bob, main)\n", + "-> create_branch(haesleinhuepf/git-bob, main)\n", + "git-bob-mod-9AsJU2OJ7D\n", + "git-bob-mod-88AwAVptDT\n" + ] + } + ], + "source": [ + "gu1_branch = gu1.create_branch(repository)\n", + "gu2_branch = gu2.create_branch(repository)\n", + "\n", + "print(gu1_branch)\n", + "print(gu2_branch)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "1dc52b1b-71c6-44e3-aa5c-a6fe9a755608", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> write_file_in_branch(haesleinhuepf/git-bob, git-bob-mod-9AsJU2OJ7D, playground/test.txt)\n", + "File playground/test.txt successfully created in repository haesleinhuepf/git-bob branch git-bob-mod-9AsJU2OJ7D. \n", + "\n", + "\n", + "-> write_file_in_new_branch(haesleinhuepf/git-bob, git-bob-mod-88AwAVptDT, playground/test.txt, ...)\n", + "-> check_if_file_exists(haesleinhuepf/git-bob, playground/test.txt)\n", + "-> get_file_in_repository(haesleinhuepf/git-bob, git-bob-mod-88AwAVptDT, playground/test.txt)\n", + "loading file content... playground/test.txt\n", + "File playground/test.txt successfully created in repository haesleinhuepf/git-bob branch git-bob-mod-88AwAVptDT. \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu, branch in zip([gu1, gu2], [gu1_branch, gu2_branch]):\n", + " print(gu.write_file_in_branch(repository, branch, \"playground/test.txt\", \"hello-world\"), \"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "feb42d6c-1652-4b0e-b6b7-88dc1708411a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> get_diff_of_branches(haesleinhuepf/git-bob, git-bob-mod-9AsJU2OJ7D, main)\n", + "File:playground/test.txt -> playground/test.txt\n", + "----------------------------------------\n", + "@@ -0,0 +1 @@\n", + "+hello-world\n", + "\\ No newline at end of file\n", + " \n", + "\n", + "\n", + "\n", + "File: playground/test.txt\n", + "Status: added\n", + "----------------------------------------\n", + "@@ -0,0 +1 @@\n", + "+hello-world\n", + "\\ No newline at end of file \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu, branch in zip([gu1, gu2], [gu1_branch, gu2_branch]):\n", + " print(gu.get_diff_of_branches(repository, branch, \"main\"), \"\\n\\n\")\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "717c69e7-efcf-45ab-8513-1f2f25408723", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> check_if_file_exists(haesleinhuepf/git-bob, git-bob-mod-9AsJU2OJ7D, playground/test.txt)\n", + "True \n", + "\n", + "\n", + "-> check_if_file_exists(haesleinhuepf/git-bob, playground/test.txt)\n", + "-> get_file_in_repository(haesleinhuepf/git-bob, git-bob-mod-88AwAVptDT, playground/test.txt)\n", + "loading file content... playground/test.txt\n", + "True \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu, branch in zip([gu1, gu2], [gu1_branch, gu2_branch]):\n", + " print(gu.check_if_file_exists(repository, branch, \"playground/test.txt\"), \"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "e24f7926-b96a-4fa5-a9ae-8b660f95ca9a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> check_if_file_exists(haesleinhuepf/git-bob, git-bob-mod-9AsJU2OJ7D, playground/blub.txt)\n", + "False \n", + "\n", + "\n", + "-> check_if_file_exists(haesleinhuepf/git-bob, playground/blub.txt)\n", + "-> get_file_in_repository(haesleinhuepf/git-bob, git-bob-mod-88AwAVptDT, playground/blub.txt)\n", + "loading file content... playground/blub.txt\n", + "False \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu, branch in zip([gu1, gu2], [gu1_branch, gu2_branch]):\n", + " print(gu.check_if_file_exists(repository, branch, \"playground/blub.txt\"), \"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "ffa99d44-aa29-49d2-8254-121d81f25f9d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> copy_file_in_repository(haesleinhuepf/git-bob, playground/test.txt, playground/blub2.txt, git-bob-mod-9AsJU2OJ7D)\n", + "-> get_file_in_repository(haesleinhuepf/git-bob, git-bob-mod-9AsJU2OJ7D, playground/test.txt)\n", + "-> write_file_in_branch(haesleinhuepf/git-bob, git-bob-mod-9AsJU2OJ7D, playground/blub2.txt)\n", + "None \n", + "\n", + "\n", + "-> copy_file_in_repository(haesleinhuepf/git-bob, playground/test.txt, playground/blub3.txt, git-bob-mod-9AsJU2OJ7D)\n", + "-> write_file_in_branch(haesleinhuepf/git-bob, git-bob-mod-9AsJU2OJ7D, playground/blub3.txt)\n", + "None \n", + "\n", + "\n", + "-> copy_file_in_repository(haesleinhuepf/git-bob, git-bob-mod-88AwAVptDT, playground/test.txt, playground/blub2.txt)\n", + "None \n", + "\n", + "\n", + "-> copy_file_in_repository(haesleinhuepf/git-bob, git-bob-mod-88AwAVptDT, playground/test.txt, playground/blub3.txt)\n", + "None \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu, branch in zip([gu1, gu2], [gu1_branch, gu2_branch]):\n", + " print(gu.copy_file_in_repository(repository, branch, \"playground/test.txt\", \"playground/blub2.txt\"), \"\\n\\n\")\n", + " print(gu.copy_file_in_repository(repository, branch, \"playground/test.txt\", \"playground/blub3.txt\"), \"\\n\\n\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "79cd1650-28fc-461b-921e-ec4e6a5dfdca", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> rename_file_in_repository(haesleinhuepf/git-bob, playground/test.txt, playground/blub.txt, git-bob-mod-9AsJU2OJ7D)\n", + "None \n", + "\n", + "\n", + "-> rename_file_in_repository(haesleinhuepf/git-bob, git-bob-mod-88AwAVptDT, playground/test.txt, playground/blub.txt)\n", + "None \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu, branch in zip([gu1, gu2], [gu1_branch, gu2_branch]):\n", + " print(gu.rename_file_in_repository(repository, branch, \"playground/test.txt\", \"playground/blub.txt\"), \"\\n\\n\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "b94bd5b1-1fdd-427d-9307-94d951ef0ed1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> check_if_file_exists(haesleinhuepf/git-bob, git-bob-mod-9AsJU2OJ7D, playground/blub.txt)\n", + "False \n", + "\n", + "\n", + "-> check_if_file_exists(haesleinhuepf/git-bob, playground/blub.txt)\n", + "-> get_file_in_repository(haesleinhuepf/git-bob, git-bob-mod-88AwAVptDT, playground/blub.txt)\n", + "loading file content... playground/blub.txt\n", + "True \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu, branch in zip([gu1, gu2], [gu1_branch, gu2_branch]):\n", + " print(gu.check_if_file_exists(repository, branch, \"playground/blub.txt\"), \"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "4d78779a-df02-428f-9f98-0e5be2c89263", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> download_to_repository(haesleinhuepf/git-bob, playground/image.png, https://github.com/user-attachments/assets/da6456bb-7bdf-4ad8-8f0d-95e38fa110e9, git-bob-mod-9AsJU2OJ7D)\n", + "-> write_file_in_branch(haesleinhuepf/git-bob, git-bob-mod-9AsJU2OJ7D, playground/image.png)\n", + "None \n", + "\n", + "\n", + "-> download_to_repository(haesleinhuepf/git-bob, git-bob-mod-88AwAVptDT, https://github.com/user-attachments/assets/da6456bb-7bdf-4ad8-8f0d-95e38fa110e9, playground/image.png)\n", + "File 'playground/image.png' successfully uploaded.\n", + "None \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu, branch in zip([gu1, gu2], [gu1_branch, gu2_branch]):\n", + " print(gu.download_to_repository(repository, branch, \"https://github.com/user-attachments/assets/da6456bb-7bdf-4ad8-8f0d-95e38fa110e9\", \"playground/image.png\"), \"\\n\\n\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "4c3f6d60-0b88-410e-9a13-0352634cfb6b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> check_if_file_exists(haesleinhuepf/git-bob, git-bob-mod-9AsJU2OJ7D, playground/image.png)\n", + "True \n", + "\n", + "\n", + "-> check_if_file_exists(haesleinhuepf/git-bob, playground/image.png)\n", + "-> get_file_in_repository(haesleinhuepf/git-bob, git-bob-mod-88AwAVptDT, playground/image.png)\n", + "loading file content... playground/image.png\n", + "True \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu, branch in zip([gu1, gu2], [gu1_branch, gu2_branch]):\n", + " print(gu.check_if_file_exists(repository, branch, \"playground/image.png\"), \"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "4905226a-e114-4161-ac9d-140f019e2c55", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> check_if_file_exists(haesleinhuepf/git-bob, git-bob-mod-9AsJU2OJ7D, playground/blub.txt)\n", + "False \n", + "\n", + "\n", + "-> check_if_file_exists(haesleinhuepf/git-bob, playground/blub.txt)\n", + "-> get_file_in_repository(haesleinhuepf/git-bob, git-bob-mod-88AwAVptDT, playground/blub.txt)\n", + "loading file content... playground/blub.txt\n", + "True \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu, branch in zip([gu1, gu2], [gu1_branch, gu2_branch]):\n", + " print(gu.check_if_file_exists(repository, branch, \"playground/blub.txt\"), \"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "31ec2874-ac04-4b36-9a1a-d6997c8e937e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> delete_file_from_repository(haesleinhuepf/git-bob, playground/blub2.txt, git-bob-mod-9AsJU2OJ7D)\n", + "None \n", + "\n", + "\n", + "-> delete_file_in_repository(haesleinhuepf/git-bob, git-bob-mod-88AwAVptDT, playground/blub2.txt)\n", + "-> get_file_in_repository(haesleinhuepf/git-bob, git-bob-mod-88AwAVptDT, playground/blub2.txt)\n", + "loading file content... playground/blub2.txt\n", + "None \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu, branch in zip([gu1, gu2], [gu1_branch, gu2_branch]):\n", + " print(gu.delete_file_from_repository(repository, branch, \"playground/blub2.txt\"), \"\\n\\n\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "7d641aca-57d0-41ee-bb65-53fd5eab36ca", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> check_if_file_exists(haesleinhuepf/git-bob, git-bob-mod-9AsJU2OJ7D, playground/blub.txt)\n", + "False \n", + "\n", + "\n", + "-> check_if_file_exists(haesleinhuepf/git-bob, playground/blub.txt)\n", + "-> get_file_in_repository(haesleinhuepf/git-bob, git-bob-mod-88AwAVptDT, playground/blub.txt)\n", + "loading file content... playground/blub.txt\n", + "True \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu, branch in zip([gu1, gu2], [gu1_branch, gu2_branch]):\n", + " print(gu.check_if_file_exists(repository, branch, \"playground/blub.txt\"), \"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "6a39c9c7-63a9-4dc3-9a13-6c89f2306a3a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> get_file_in_repository(haesleinhuepf/git-bob, git-bob-mod-9AsJU2OJ7D, playground/blub3.txt)\n", + "hello-world \n", + "\n", + "\n", + "-> get_file_in_repository(haesleinhuepf/git-bob, git-bob-mod-88AwAVptDT, playground/blub3.txt)\n", + "loading file content... playground/blub3.txt\n", + "hello-world \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu, branch in zip([gu1, gu2], [gu1_branch, gu2_branch]):\n", + " print(gu.decode_file(gu.get_file_in_repository(repository, branch, \"playground/blub3.txt\")), \"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "c7b0c3b7-33c7-41a1-b41b-7092eba53ac7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> send_pull_request(haesleinhuepf/git-bob, git-bob-mod-9AsJU2OJ7D, main)\n", + "Pull request created: https://gitlab.com/haesleinhuepf/git-bob/-/merge_requests/5 \n", + "\n", + "\n", + "-> send_pull_request(haesleinhuepf/git-bob, git-bob-mod-88AwAVptDT, main, ...)\n", + "Pull request created: https://github.com/haesleinhuepf/git-bob/pull/396 \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu, branch in zip([gu1, gu2], [gu1_branch, gu2_branch]):\n", + " print(gu.send_pull_request(repository, branch, \"main\", \"test-pr\", \"hello world pr\"), \"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fbf3868d-fcea-4376-bdcb-36f81a8ceb02", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "33dffa0d-32ca-4b2b-a4e9-b231a14c7783", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> check_access_and_ask_for_approval(haesleinhuepf, haesleinhuepf/git-bob, 1)\n", + "True \n", + "\n", + "\n", + "-> check_access_and_ask_for_approval(haesleinhuepf, haesleinhuepf/git-bob, 1)\n", + "True \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu in [gu1, gu2]:\n", + " print(gu.check_access_and_ask_for_approval(\"haesleinhuepf\", repository, 1), \"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "fe337023-e7bf-4ca5-885c-8d5095c5a5cb", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> check_access_and_ask_for_approval(ddd, haesleinhuepf/git-bob, 1)\n", + "User does not have access rights.\n", + "-> add_comment_to_issue(haesleinhuepf/git-bob, 1, ...)\n", + "Comment added to issue #1 in repository haesleinhuepf/git-bob.\n", + "False \n", + "\n", + "\n", + "-> check_access_and_ask_for_approval(ddd, haesleinhuepf/git-bob, 1)\n", + "User does not have access rights.\n", + "-> add_comment_to_issue(haesleinhuepf/git-bob, 1, ...)\n", + "Comment added to issue #1 in repository haesleinhuepf/git-bob.\n", + "False \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu in [gu1, gu2]:\n", + " print(gu.check_access_and_ask_for_approval(\"ddd\", repository, 1), \"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "7a7a81bd-85ba-4c40-a324-852e8d2ebf7b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> get_contributors(haesleinhuepf/git-bob)\n", + "['github-actions[bot]', 'Robert Haase'] \n", + "\n", + "\n", + "-> get_contributors(haesleinhuepf/git-bob)\n", + "['haesleinhuepf', 'github-actions[bot]'] \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu in [gu1, gu2]:\n", + " print(gu.get_contributors(repository), \"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "d8cb48ac-5f1a-4e70-b13c-516427c0cf63", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> get_repository_file_contents(haesleinhuepf/git-bob, ['playground/test.py'], main)\n", + "{'playground/test.py': 'def faculty(number):\\n if number == 0:\\n return 1\\n else:\\n \n", + "\n", + "\n", + "-> get_repository_file_contents(haesleinhuepf/git-bob, ['playground/test.py'])\n", + "-> get_file_in_repository(haesleinhuepf/git-bob, main, playground/test.py)\n", + "loading file content... playground/test.py\n", + "{'playground/test.py': 'def faculty(number):\\n if number == 0:\\n return 1\\n else:\\n \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu in [gu1, gu2]:\n", + " print(str(gu.get_repository_file_contents(repository, \"main\", [\"playground/test.py\"]))[:100], \"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "a5c1f71d-25f5-4c14-a64c-09fe27018b93", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> list_repository_files(haesleinhuepf/git-bob)\n", + "['.gitattributes', '.gitignore', 'LICENSE', 'README.md', 'pyproject.toml', 'requirements.txt', 'setup.cfg', 'setup.py', 'tests/test_github_utilities.py', 'tests/test_logger.py', 'tests/test_utilities.py', 'src/git_bob/__init__.py', 'src/git_bob/_ai_github_utilities.py', 'src/git_bob/_endpoints.py', 'src/git_bob/_github_utilities.py', 'src/git_bob/_logger.py', 'src/git_bob/_terminal.py', 'src/git_bob/_utilities.py', 'playground/blobs.tif', 'playground/long_file.java', 'playground/python_basics.ipynb', 'playground/readme.md', 'playground/test.py', 'playground/test3.py', 'docs/installation-tutorial.md', 'docs/images/banner.png', 'docs/images/demo_comment_code.png', 'docs/images/demo_fix_typos.png', 'docs/images/demo_question.png', 'docs/images/demo_review_pull_request.png', 'docs/images/install/img.png', 'docs/images/install/img4a.png', 'docs/images/install/img_1.png', 'docs/images/install/img_10.png', 'docs/images/install/img_2.png', 'docs/images/install/img_3.png', 'docs/images/install/img_4.png', 'docs/images/install/img_5.png', 'docs/images/install/img_6.png', 'docs/images/install/img_7.png', 'docs/images/install/img_8.png', 'docs/images/install/img_9.png', '.github/workflows/git-bob.yml', '.github/workflows/pytest.yml'] \n", + "\n", + "\n", + "-> list_repository_files(haesleinhuepf/git-bob)\n", + "['.gitattributes', '.gitignore', 'LICENSE', 'README.md', 'pyproject.toml', 'requirements.txt', 'setup.cfg', 'setup.py', 'docs/installation-tutorial.md', 'playground/blobs.tif', 'playground/long_file.java', 'playground/python_basics.ipynb', 'playground/readme.md', 'playground/test.py', 'playground/test3.py', 'tests/test_github_utilities.py', 'tests/test_logger.py', 'tests/test_utilities.py', '.github/workflows/git-bob.yml', '.github/workflows/pytest.yml', 'docs/images/banner.png', 'docs/images/demo_comment_code.png', 'docs/images/demo_fix_typos.png', 'docs/images/demo_question.png', 'docs/images/demo_review_pull_request.png', 'src/git_bob/__init__.py', 'src/git_bob/_ai_github_utilities.py', 'src/git_bob/_endpoints.py', 'src/git_bob/_github_utilities.py', 'src/git_bob/_logger.py', 'src/git_bob/_terminal.py', 'src/git_bob/_utilities.py', 'docs/images/install/img.png', 'docs/images/install/img4a.png', 'docs/images/install/img_1.png', 'docs/images/install/img_10.png', 'docs/images/install/img_2.png', 'docs/images/install/img_3.png', 'docs/images/install/img_4.png', 'docs/images/install/img_5.png', 'docs/images/install/img_6.png', 'docs/images/install/img_7.png', 'docs/images/install/img_8.png', 'docs/images/install/img_9.png'] \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu in [gu1, gu2]:\n", + " print(gu.list_repository_files(repository), \"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "328bbb94-4059-4d00-befc-66b4f9455bb3", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> get_gitlab_issue_details(haesleinhuepf/git-bob, 1)\n", + "\n", + "Issue #1: this is a test\n", + "State: opened\n", + "Created at: 2024-10-19T16:57:49.005Z\n", + "Updated at: 2024-10-20T08:31:43.504Z\n", + "Closed at: None\n", + "Author: haesleinhuepf\n", + "Assignees: \n", + "Labels: \n", + "Comments: 7\n", + "Description:\n", + "he \n", + "\n", + "\n", + "-> get_github_issue_details(haesleinhuepf/git-bob, 1)\n", + "\n", + "Issue #1: Testing conversational workflows\n", + "State: closed\n", + "Created at: 2024-08-01 13:09:09+00:00\n", + "Updated at: 2024-10-20 08:31:45+00:00\n", + "Closed at: 2024-08-01 14:47:48+00:00\n", + "Author: haesleinhuepf\n", + "Assigne \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu in [gu1, gu2]:\n", + " print(str(gu.get_issue_details(repository, 1))[:200], \"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "c76d9fba-4516-4a99-b09b-a0661369ee19", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> list_issues(haesleinhuepf/git-bob, opened)\n", + "{13: 'test4fun', 12: 'Questions', 11: 'test4fun', 10: 'test4fun', 9: 'test4fun', 8: 'test4fun', 7: 'test4fun', 6: 'test4fun', 5: 'test4fun', 2: 'test2', 1: 'this is a test'} \n", + "\n", + "\n", + "-> list_issues(haesleinhuepf/git-bob, open)\n", + "{396: 'test-pr', 395: 'test4fun', 385: 'get_most_recently_commented_issue is super slow', 384: 'Bug: get_repository_file_contents does not have a branch parameter', 383: 'Add GitLab support with API-compatible utility functions.', 382: 'Gitlab support', 378: 'Also support Gitlab / Gitlab CI', 377: 'Integrate aider to solve complex issues', 362: 'plotting', 337: 'LLM-based task decision', 71: 'Halucinations in reviews'} \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu in [gu1, gu2]:\n", + " print(gu.list_issues(repository), \"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "f0adf7d9-f58f-4061-a5d8-d9722b8c0949", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> get_most_recent_comment_on_issue(haesleinhuepf/git-bob, 1)\n", + "('haesleinhuepf', \"\\nThis message was generated by [git-bob](https://github.com/haesleinhuepf/git-bob) (version: 0.10.0, model: None), an experimental AI-based assistant. It can make mistakes and has [limitations](https://github.com/haesleinhuepf/git-bob?tab=readme-ov-file#limitations). Check its messages carefully.\\n\\nHi @ddd, \\n\\nthanks for reaching out! Unfortunately, I'm not allowed to respond to you directly. \\nI need approval from a person who has access.\\n\\nBest,\\ngit-bob\") \n", + "\n", + "\n", + "-> get_most_recent_comment_on_issue(haesleinhuepf/git-bob, 1)\n", + "('haesleinhuepf', \"\\nThis message was generated by [git-bob](https://github.com/haesleinhuepf/git-bob) (version: 0.10.0, model: None), an experimental AI-based assistant. It can make mistakes and has [limitations](https://github.com/haesleinhuepf/git-bob?tab=readme-ov-file#limitations). Check its messages carefully.\\n\\nHi @ddd, \\n\\nthanks for reaching out! Unfortunately, I'm not allowed to respond to you directly. \\nI need approval from a person who has access.\\n\\nBest,\\ngit-bob\\n\") \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu in [gu1, gu2]:\n", + " print(gu.get_most_recent_comment_on_issue(repository, 1), \"\\n\\n\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "98c59d84-f549-4750-a657-0e89027298a1", + "metadata": {}, + "outputs": [], + "source": [ + "## super slow, see https://github.com/haesleinhuepf/git-bob/issues/385\n", + "# for gu in [gu1, gu2]:\n", + "# print(gu.get_most_recently_commented_issue(repository), \"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "132c7c85-32bd-46c5-b91d-d66237af7439", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> get_conversation_on_issue(haesleinhuepf/git-bob, 1)\n", + "Issue Title: this is a test\n", + "\n", + "Issue Body:\n", + "hello world\n", + "\n", + "Comment by haesleinhuepf:\n", + "\n", + "This message w \n", + "\n", + "\n", + "-> get_conversation_on_issue(haesleinhuepf/git-bob, 1)\n", + "Issue Title: Testing conversational workflows\n", + "\n", + "Issue Body:\n", + "Hi, this is a test!\n", + "\n", + "Comment by haesleinh \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu in [gu1, gu2]:\n", + " print(gu.get_conversation_on_issue(repository, 1)[:100], \"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "e6cbb2d0-efed-494e-bff9-2e4df3732bf9", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "-> add_comment_to_issue(haesleinhuepf/git-bob, 1, ...)\n", + "Comment added to issue #1 in repository haesleinhuepf/git-bob.\n", + "None \n", + "\n", + "\n", + "-> add_comment_to_issue(haesleinhuepf/git-bob, 1, ...)\n", + "Comment added to issue #1 in repository haesleinhuepf/git-bob.\n", + "None \n", + "\n", + "\n" + ] + } + ], + "source": [ + "from datetime import datetime\n", + "\n", + "current_datetime = datetime.now().strftime(\"%Y-%m-%d %H:%M:%S\")\n", + "\n", + "for gu in [gu1, gu2]:\n", + " print(gu.add_comment_to_issue(repository, 1, \"hello world \" + current_datetime), \"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "58c0e9ed-f9c4-494d-808a-b56948a2a394", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " => {' \n", + "\n", + "\n", + "Repository(full_name=\"haesleinhuepf/git-bob\") \n", + "\n", + "\n" + ] + } + ], + "source": [ + "for gu in [gu1, gu2]:\n", + " print(str(gu.get_repository_handle(repository))[:50], \"\\n\\n\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "783b2898-bb3c-4e62-847e-9fdf95a565e9", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7360a055-639c-438f-b542-191a87430e57", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "53f8a081-49d9-454b-8bce-ec151caccf13", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "856d036e-790d-4862-91da-6ce78130721c", + "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.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}