diff --git a/examples/README.md b/examples/README.md index 3d2ad9dd..1d192962 100644 --- a/examples/README.md +++ b/examples/README.md @@ -5,3 +5,4 @@ - [Patches to open pull requests on Pagure](list_pr_patches.ipynb) - [Listing all pull requests since specific release on GitHub](list_prs_since_release.ipynb) - [Actions on issues on GitHub](working_with_issues.ipynb) +- [Syncing the labels on GitHub](syncing_labels.ipynb) diff --git a/examples/syncing_labels.ipynb b/examples/syncing_labels.ipynb new file mode 100644 index 00000000..66349d65 --- /dev/null +++ b/examples/syncing_labels.ipynb @@ -0,0 +1,208 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Syncing labels between projects" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "\n", + "from ogr import GithubService\n", + "\n", + "service = GithubService(token=os.getenv(\"GITHUB_TOKEN\"))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now we will fetch the labels from the source project." + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[Label(name=\"area/cli\"),\n", + " Label(name=\"area/config\"),\n", + " Label(name=\"area/copr\"),\n", + " Label(name=\"area/database\"),\n", + " Label(name=\"area/fedora\"),\n", + " Label(name=\"area/general\"),\n", + " Label(name=\"area/github\"),\n", + " Label(name=\"area/gitlab\"),\n", + " Label(name=\"area/image-builder\"),\n", + " Label(name=\"area/other\"),\n", + " Label(name=\"area/rhel-ecosystem\"),\n", + " Label(name=\"area/testing-farm\"),\n", + " Label(name=\"area/user-experience\"),\n", + " Label(name=\"blocked\"),\n", + " Label(name=\"complexity/easy-fix\"),\n", + " Label(name=\"complexity/epic\"),\n", + " Label(name=\"complexity/single-task\"),\n", + " Label(name=\"demo\"),\n", + " Label(name=\"discuss\"),\n", + " Label(name=\"do-not-merge\"),\n", + " Label(name=\"duplicate\"),\n", + " Label(name=\"gain/high\"),\n", + " Label(name=\"gain/low\"),\n", + " Label(name=\"good-first-issue\"),\n", + " Label(name=\"GSOC\"),\n", + " Label(name=\"Hacktoberfest\"),\n", + " Label(name=\"has-release-notes\"),\n", + " Label(name=\"help-wanted\"),\n", + " Label(name=\"impact/high\"),\n", + " Label(name=\"impact/low\"),\n", + " Label(name=\"invalid\"),\n", + " Label(name=\"kind/bug\"),\n", + " Label(name=\"kind/documentation\"),\n", + " Label(name=\"kind/feature\"),\n", + " Label(name=\"kind/internal\"),\n", + " Label(name=\"kind/other\"),\n", + " Label(name=\"kind/refactor\"),\n", + " Label(name=\"mergeit\"),\n", + " Label(name=\"need-info\"),\n", + " Label(name=\"needs-design\"),\n", + " Label(name=\"pinned\"),\n", + " Label(name=\"ready-for-review\"),\n", + " Label(name=\"release\"),\n", + " Label(name=\"RHOSC\"),\n", + " Label(name=\"security\"),\n", + " Label(name=\"source-git\"),\n", + " Label(name=\"stale\"),\n", + " Label(name=\"testing\"),\n", + " Label(name=\"triaged\"),\n", + " Label(name=\"wontfix\"),\n", + " Label(name=\"workaround-exists\"),\n", + " Label(name=\"🌞 friday 🤟\")]" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "project = service.get_project(namespace=\"packit\", repo=\"packit\")\n", + "labels = project.get_labels()\n", + "\n", + "labels" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In this case I only want to sync the labels we use during the refinement of the tickets." + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[Label(name=\"area/cli\"),\n", + " Label(name=\"area/config\"),\n", + " Label(name=\"area/copr\"),\n", + " Label(name=\"area/database\"),\n", + " Label(name=\"area/fedora\"),\n", + " Label(name=\"area/general\"),\n", + " Label(name=\"area/github\"),\n", + " Label(name=\"area/gitlab\"),\n", + " Label(name=\"area/image-builder\"),\n", + " Label(name=\"area/other\"),\n", + " Label(name=\"area/rhel-ecosystem\"),\n", + " Label(name=\"area/testing-farm\"),\n", + " Label(name=\"area/user-experience\"),\n", + " Label(name=\"complexity/easy-fix\"),\n", + " Label(name=\"complexity/epic\"),\n", + " Label(name=\"complexity/single-task\"),\n", + " Label(name=\"gain/high\"),\n", + " Label(name=\"gain/low\"),\n", + " Label(name=\"impact/high\"),\n", + " Label(name=\"impact/low\"),\n", + " Label(name=\"kind/bug\"),\n", + " Label(name=\"kind/documentation\"),\n", + " Label(name=\"kind/feature\"),\n", + " Label(name=\"kind/internal\"),\n", + " Label(name=\"kind/other\"),\n", + " Label(name=\"kind/refactor\")]" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "wanted_labels = list(filter(lambda l: \"/\" in l.name, labels))\n", + "\n", + "wanted_labels" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "And now we can sync them to the other project." + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "26" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "target_project = service.get_project(namespace=\"packit\", repo=\"validation\")\n", + "target_project.update_labels(wanted_labels)" + ] + } + ], + "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.12.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}