Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
94 changes: 94 additions & 0 deletions examples/set_commit_status.ipynb
Original file line number Diff line number Diff line change
@@ -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 = \"<paste-your-token-here>\"\n",
Comment on lines +16 to +18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better security practice, it's recommended to load tokens from environment variables rather than hardcoding them, even in examples. This helps prevent accidentally committing sensitive credentials. You can use os.environ.get() for this.

import os
from ogr import ForgejoService
TOKEN = os.environ.get("FORGEJO_TOKEN") or "<paste-your-token-here>"

"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
}
Loading