diff --git a/examples/README.md b/examples/README.md index 1d1929628..119e0b45c 100644 --- a/examples/README.md +++ b/examples/README.md @@ -6,3 +6,4 @@ - [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) +- [Setting commit statuses on Forgejo](set_commit_status.ipynb) diff --git a/examples/set_commit_status.ipynb b/examples/set_commit_status.ipynb new file mode 100644 index 000000000..f14328022 --- /dev/null +++ b/examples/set_commit_status.ipynb @@ -0,0 +1,94 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Setting commit statuses" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from ogr import ForgejoService\n", + "\n", + "TOKEN = \"\"\n", + "instance_url = \"https://codeberg.org\"\n", + "namespace = \"owner\"\n", + "repo = \"repo\"\n", + "\n", + "service = ForgejoService(instance_url=instance_url, token=TOKEN)\n", + "project = service.get_project(namespace=namespace, repo=repo)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Get the hash of the head commit of a specific PR:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "pr_id = 1000\n", + "pr = project.get_pr(pr_id=pr_id)\n", + "head_commit = pr.head_commit" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Set a status flag on this commit:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "from ogr.abstract import CommitStatus\n", + "\n", + "target_url = f\"{instance_url}/{namespace}/{repo}\"\n", + "\n", + "project.set_commit_status(\n", + " commit=head_commit,\n", + " state=CommitStatus.success,\n", + " target_url=target_url,\n", + " description=\"Arbitrary status\",\n", + " context=\"System context\",\n", + ")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3.8.3 64-bit", + "name": "python38364bit3ec8239d0440456baaf370e87148ec69" + }, + "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.8.4-final" + }, + "orig_nbformat": 2 + }, + "nbformat": 4, + "nbformat_minor": 2 +}