Skip to content

Commit 5b7ed31

Browse files
Add example of setting commit statuses on Forgejo (#976)
Add example of setting commit statuses on Forgejo Reviewed-by: gemini-code-assist[bot] Reviewed-by: Maja Massarini Reviewed-by: Laura Barcziová
2 parents e40745b + a30a4eb commit 5b7ed31

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
- [Listing all pull requests since specific release on GitHub](list_prs_since_release.ipynb)
77
- [Actions on issues on GitHub](working_with_issues.ipynb)
88
- [Syncing the labels on GitHub](syncing_labels.ipynb)
9+
- [Setting commit statuses on Forgejo](set_commit_status.ipynb)

examples/set_commit_status.ipynb

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Setting commit statuses"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": null,
13+
"metadata": {},
14+
"outputs": [],
15+
"source": [
16+
"from ogr import ForgejoService\n",
17+
"\n",
18+
"TOKEN = \"<paste-your-token-here>\"\n",
19+
"instance_url = \"https://codeberg.org\"\n",
20+
"namespace = \"owner\"\n",
21+
"repo = \"repo\"\n",
22+
"\n",
23+
"service = ForgejoService(instance_url=instance_url, token=TOKEN)\n",
24+
"project = service.get_project(namespace=namespace, repo=repo)"
25+
]
26+
},
27+
{
28+
"cell_type": "markdown",
29+
"metadata": {},
30+
"source": [
31+
"Get the hash of the head commit of a specific PR:"
32+
]
33+
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": null,
37+
"metadata": {},
38+
"outputs": [],
39+
"source": [
40+
"pr_id = 1000\n",
41+
"pr = project.get_pr(pr_id=pr_id)\n",
42+
"head_commit = pr.head_commit"
43+
]
44+
},
45+
{
46+
"cell_type": "markdown",
47+
"metadata": {},
48+
"source": [
49+
"Set a status flag on this commit:"
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": null,
55+
"metadata": {},
56+
"outputs": [],
57+
"source": [
58+
"\n",
59+
"from ogr.abstract import CommitStatus\n",
60+
"\n",
61+
"target_url = f\"{instance_url}/{namespace}/{repo}\"\n",
62+
"\n",
63+
"project.set_commit_status(\n",
64+
" commit=head_commit,\n",
65+
" state=CommitStatus.success,\n",
66+
" target_url=target_url,\n",
67+
" description=\"Arbitrary status\",\n",
68+
" context=\"System context\",\n",
69+
")"
70+
]
71+
}
72+
],
73+
"metadata": {
74+
"kernelspec": {
75+
"display_name": "Python 3.8.3 64-bit",
76+
"name": "python38364bit3ec8239d0440456baaf370e87148ec69"
77+
},
78+
"language_info": {
79+
"codemirror_mode": {
80+
"name": "ipython",
81+
"version": 3
82+
},
83+
"file_extension": ".py",
84+
"mimetype": "text/x-python",
85+
"name": "python",
86+
"nbconvert_exporter": "python",
87+
"pygments_lexer": "ipython3",
88+
"version": "3.8.4-final"
89+
},
90+
"orig_nbformat": 2
91+
},
92+
"nbformat": 4,
93+
"nbformat_minor": 2
94+
}

0 commit comments

Comments
 (0)