codeberg-cli 0.3.0__py3-none-any.whl → 0.4.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
codeberg_cli/client.py CHANGED
@@ -17,6 +17,24 @@ class ClientError(RuntimeError):
17
17
  """Raised when the API returns a non-2xx status."""
18
18
 
19
19
 
20
+ def _response_error_message(response: httpx.Response) -> str:
21
+ if not response.text:
22
+ return response.reason_phrase or "unknown error"
23
+
24
+ try:
25
+ payload = response.json()
26
+ except ValueError:
27
+ return response.text.strip() or response.reason_phrase or "unknown error"
28
+
29
+ if isinstance(payload, dict):
30
+ for key in ("message", "error", "detail"):
31
+ message = payload.get(key)
32
+ if message:
33
+ return str(message)
34
+
35
+ return response.text.strip() or response.reason_phrase or "unknown error"
36
+
37
+
20
38
  class Client:
21
39
  """HTTP client for the Codeberg API."""
22
40
 
@@ -80,11 +98,7 @@ class Client:
80
98
  with Status(f"{label}..."):
81
99
  response = self._client.request(method, path, **kwargs)
82
100
  if not response.is_success:
83
- msg = (
84
- response.json().get("message", "unknown error")
85
- if response.text
86
- else "unknown error"
87
- )
101
+ msg = _response_error_message(response)
88
102
  raise ClientError(f"{response.status_code} {msg}")
89
103
  if response.status_code == 204:
90
104
  return None
@@ -0,0 +1,36 @@
1
+ from typing import Any
2
+
3
+
4
+ def _first(run: dict[str, Any], *keys: str, default: str = "") -> Any:
5
+ for key in keys:
6
+ value = run.get(key)
7
+ if value is not None and value != "":
8
+ return value
9
+ return default
10
+
11
+
12
+ def normalize_run(run: dict[str, Any]) -> dict[str, Any]:
13
+ return {
14
+ "id": run.get("id"),
15
+ "index_in_repo": run.get("index_in_repo"),
16
+ "title": _first(run, "title", "display_title", default=""),
17
+ "status": _first(run, "conclusion", "status", default="?"),
18
+ "event": _first(run, "trigger_event", "event", default="?"),
19
+ "workflow_id": run.get("workflow_id"),
20
+ "created": _first(run, "created", "created_at", default=""),
21
+ "updated": _first(run, "updated", "updated_at", default=""),
22
+ "started": run.get("started"),
23
+ "stopped": run.get("stopped"),
24
+ "ref": _first(run, "prettyref", "head_branch", default=""),
25
+ "commit": _first(run, "commit_sha", "head_sha", default=""),
26
+ "html_url": _first(run, "html_url", "url", default=""),
27
+ }
28
+
29
+
30
+ def list_runs(response: dict[str, Any] | list[dict[str, Any]]) -> list[dict[str, Any]]:
31
+ if isinstance(response, dict):
32
+ runs = response.get("workflow_runs", [])
33
+ if isinstance(runs, list):
34
+ return runs
35
+ return []
36
+ return response
@@ -6,6 +6,8 @@ from codeberg_cli.git import infer_repo
6
6
  from codeberg_cli.helpers import is_json_mode, output, require_client
7
7
  from xclif import Arg, Option, command
8
8
 
9
+ from codeberg_cli.routes.actions._format import normalize_run
10
+
9
11
 
10
12
  @command("run")
11
13
  def _(
@@ -28,13 +30,16 @@ def _(
28
30
  output(run)
29
31
  return
30
32
 
31
- rich.print(f"[bold]Run #{run['id']}:[/bold] {run['display_title']}")
32
- rich.print(f" Status: {run.get('status', '?')}")
33
- rich.print(f" Conclusion: {run.get('conclusion', 'N/A')}")
34
- rich.print(f" Event: {run.get('event', '?')}")
35
- rich.print(f" Branch: {run.get('head_branch', '?')}")
36
- rich.print(f" Commit: {run.get('head_sha', '?')[:12]}")
37
- rich.print(f" Created: {run.get('created_at', '?')}")
38
- rich.print(f" Updated: {run.get('updated_at', '?')}")
39
- if run.get("url"):
40
- rich.print(f" URL: {run['url']}")
33
+ normalized = normalize_run(run)
34
+ commit = normalized["commit"] or "?"
35
+
36
+ rich.print(f"[bold]Run #{normalized['id']}:[/bold] {normalized['title']}")
37
+ rich.print(f" Status: {normalized['status']}")
38
+ rich.print(f" Event: {normalized['event']}")
39
+ rich.print(f" Workflow: {normalized['workflow_id'] or '?'}")
40
+ rich.print(f" Ref: {normalized['ref'] or '?'}")
41
+ rich.print(f" Commit: {commit[:12]}")
42
+ rich.print(f" Created: {normalized['created'] or '?'}")
43
+ rich.print(f" Updated: {normalized['updated'] or '?'}")
44
+ if normalized["html_url"]:
45
+ rich.print(f" URL: {normalized['html_url']}")
@@ -6,6 +6,8 @@ from codeberg_cli.git import infer_repo
6
6
  from codeberg_cli.helpers import print_table, require_client
7
7
  from xclif import Option, command
8
8
 
9
+ from codeberg_cli.routes.actions._format import list_runs, normalize_run
10
+
9
11
 
10
12
  @command("runs")
11
13
  def _(
@@ -22,7 +24,8 @@ def _(
22
24
  return 1
23
25
  repo = inferred
24
26
 
25
- runs = client.get(f"/repos/{repo}/actions/runs", params={"limit": limit, "page": 1})
27
+ response = client.get(f"/repos/{repo}/actions/runs", params={"limit": limit, "page": 1})
28
+ runs = list_runs(response)
26
29
 
27
30
  if not runs:
28
31
  rich.print(f"[dim]No action runs in {repo}.[/dim]")
@@ -31,19 +34,14 @@ def _(
31
34
  rows = []
32
35
  json_rows = []
33
36
  for run in runs:
34
- status = run.get("status", "?")
35
- conclusion = run.get("conclusion", "")
36
- label = f"{status}" if not conclusion else f"{conclusion}"
37
- rows.append((str(run["id"]), run["display_title"][:72], label, run["event"]))
38
- json_rows.append({
39
- "id": run["id"],
40
- "title": run["display_title"],
41
- "status": status,
42
- "conclusion": conclusion,
43
- "event": run["event"],
44
- "created_at": run.get("created_at", ""),
45
- "head_branch": run.get("head_branch", ""),
46
- })
37
+ normalized = normalize_run(run)
38
+ rows.append((
39
+ str(normalized["id"]),
40
+ normalized["title"][:72],
41
+ normalized["status"],
42
+ normalized["event"],
43
+ ))
44
+ json_rows.append(normalized)
47
45
 
48
46
  print_table(
49
47
  ["ID", "Title", "Status", "Event"],
@@ -2,6 +2,7 @@ from typing import Annotated
2
2
 
3
3
  import rich
4
4
 
5
+ from codeberg_cli.client import ClientError
5
6
  from codeberg_cli.git import infer_repo
6
7
  from codeberg_cli.helpers import print_table, require_client
7
8
  from xclif import Option, command
@@ -10,6 +11,7 @@ from xclif import Option, command
10
11
  @command("workflows")
11
12
  def _(
12
13
  repo: Annotated[str, Option(description="Repository (owner/repo)", name="repo")] = "",
14
+ ref: Annotated[str, Option(description="Branch or ref", name="ref")] = "",
13
15
  ) -> None:
14
16
  """List workflows for a repository."""
15
17
  client = require_client()
@@ -21,26 +23,47 @@ def _(
21
23
  return 1
22
24
  repo = inferred
23
25
 
24
- workflows = client.get(f"/repos/{repo}/actions/workflows")
26
+ params = {}
27
+ if ref:
28
+ params["ref"] = ref
29
+
30
+ try:
31
+ workflows = client.get(
32
+ f"/repos/{repo}/contents/.forgejo/workflows",
33
+ params=params,
34
+ action="Fetching workflow files",
35
+ )
36
+ except ClientError as exc:
37
+ if str(exc).startswith("404 "):
38
+ rich.print(f"[dim]No workflows in {repo}.[/dim]")
39
+ return
40
+ raise
25
41
 
26
42
  if not workflows:
27
43
  rich.print(f"[dim]No workflows in {repo}.[/dim]")
28
44
  return
45
+ if not isinstance(workflows, list):
46
+ rich.print(f"[dim]No workflows in {repo}.[/dim]")
47
+ return
29
48
 
30
49
  rows = []
31
50
  json_rows = []
32
51
  for wf in workflows:
33
- state = wf.get("state", "?")
34
- rows.append((str(wf["id"]), wf["name"], wf.get("filename", ""), state))
52
+ if wf.get("type") != "file":
53
+ continue
54
+ rows.append((wf["name"], wf.get("path", ""), str(wf.get("size", ""))))
35
55
  json_rows.append({
36
- "id": wf["id"],
37
- "name": wf["name"],
38
- "filename": wf.get("filename", ""),
39
- "state": state,
56
+ "filename": wf["name"],
57
+ "path": wf.get("path", ""),
58
+ "size": wf.get("size"),
40
59
  })
41
60
 
61
+ if not rows:
62
+ rich.print(f"[dim]No workflows in {repo}.[/dim]")
63
+ return
64
+
42
65
  print_table(
43
- ["ID", "Name", "Filename", "State"],
66
+ ["Filename", "Path", "Size"],
44
67
  rows,
45
68
  json_data=json_rows,
46
69
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codeberg-cli
3
- Version: 0.3.0
3
+ Version: 0.4.1
4
4
  Summary: A Forgejo CLI — works with Codeberg and any Forgejo instance
5
5
  Project-URL: Homepage, https://codeberg.org/ThatXliner/codeberg-cli
6
6
  Project-URL: Repository, https://codeberg.org/ThatXliner/codeberg-cli
@@ -20,7 +20,7 @@ Requires-Python: >=3.12
20
20
  Requires-Dist: httpx
21
21
  Requires-Dist: platformdirs
22
22
  Requires-Dist: tomlkit
23
- Requires-Dist: xclif>=0.4.3
23
+ Requires-Dist: xclif>=0.5.1
24
24
  Description-Content-Type: text/markdown
25
25
 
26
26
  # cb — A Codeberg CLI
@@ -95,10 +95,11 @@ cb config set base_url "https://git.example.com/api/v1" # Self-hosted Forgejo
95
95
 
96
96
  Here's how `cb` stacks up against other Forgejo CLI tools. *Last updated: May 2026.*
97
97
 
98
+ TL;DR: **`cb` is the most feature-complete Forgejo CLI** — by a wide margin.
99
+
98
100
  | | **cb** (this) | **fj** (forgejo-cli) | **berg** (codeberg-cli) | **tea** (gitea/tea) | **gcli** |
99
101
  |---|---|---|---|---|---|
100
102
  | Language | Python | Rust | Rust | Go | C |
101
- | Version | v0.2.0 | v0.5.0 | v0.5.1 | v0.13.0 | v2.11.0 |
102
103
  | Install | `pip install codeberg-cli` | prebuilt binaries/Cargo | `cargo install codeberg-cli` | `brew install tea` | `brew install gcli` |
103
104
  | Multi-instance | `cb config set base_url` | `-H <instance>` | `BERG_BASE_URL` | `tea login add` | `-t forgejo` |
104
105
 
@@ -108,18 +109,18 @@ Here's how `cb` stacks up against other Forgejo CLI tools. *Last updated: May 20
108
109
  | Create | ✅ | ✅ | ✅ | ✅ | ✅ |
109
110
  | List | ✅ | ✅ | ✅ | ✅ | ✅ |
110
111
  | View | ✅ | ✅ | ✅ | ✅ | ✅ |
111
- | Close | ✅ | ✅ | ✅ | ✅ | |
112
- | Reopen | ✅ | — | ✅ | ✅ | |
112
+ | Close | ✅ | ✅ | ✅ | ✅ | |
113
+ | Reopen | ✅ | — | ✅ | ✅ | |
113
114
  | Comment | ✅ | ✅ | ✅ | ✅ | ✅ |
114
- | Edit | ✅ | | ✅ | ✅ | |
115
+ | Edit | ✅ | | ✅ | ✅ | |
115
116
  | Delete | ✅ | — | — | — | — |
116
117
  | Pin/Unpin | ✅ | — | — | ✅ | — |
117
118
  | Search | ✅ | ✅ | — | ✅ | — |
118
119
  | Attachments | — | — | — | ✅ | — |
119
- | Labels (manage on issue) | ✅ | — | — | ✅ | |
120
+ | Labels (manage on issue) | ✅ | — | — | ✅ | |
120
121
  | Reactions | — | — | — | — | — |
121
122
  | Subscriptions | ✅ | — | — | ✅ | — |
122
- | Tracked times | ✅ | — | — | | ✅ |
123
+ | Tracked times | ✅ | — | — | | ✅ |
123
124
  | Dependencies | — | — | — | — | — |
124
125
  | Deadline | — | — | — | ✅ | — |
125
126
  | Templates | — | ✅ | — | — | — |
@@ -131,16 +132,16 @@ Here's how `cb` stacks up against other Forgejo CLI tools. *Last updated: May 20
131
132
  | List | ✅ | ✅ | ✅ | ✅ | ✅ |
132
133
  | View | ✅ | ✅ | ✅ | ✅ | ✅ |
133
134
  | Merge | ✅ | ✅ | ✅ | ✅ | ✅ |
134
- | Close | ✅ | | ✅ | ✅ | |
135
- | Reopen | ✅ | — | ✅ | ✅ | |
135
+ | Close | ✅ | | ✅ | ✅ | |
136
+ | Reopen | ✅ | — | ✅ | ✅ | |
136
137
  | Comment | ✅ | ✅ | ✅ | ✅ | ✅ |
137
- | Edit | ✅ | | ✅ | ✅ | — |
138
- | Checkout | ✅ | | ✅ | ✅ | ✅ |
139
- | Commits | ✅ | | — | | |
140
- | Files/changed | ✅ | | — | | — |
138
+ | Edit | ✅ | | ✅ | ✅ | — |
139
+ | Checkout | ✅ | | ✅ | ✅ | ✅ |
140
+ | Commits | ✅ | | — | | |
141
+ | Files/changed | ✅ | | — | | — |
141
142
  | Reviews | — | ✅ | — | ✅ | ✅ |
142
- | Diff/Patch | ✅ | | — | | |
143
- | Update branch | ✅ | — | — | | — |
143
+ | Diff/Patch | ✅ | | — | | |
144
+ | Update branch | ✅ | — | — | | — |
144
145
  | AGit (no-fork) | — | ✅ | — | — | — |
145
146
  | CI status | — | ✅ | — | — | — |
146
147
  | Templates | — | ✅ | — | — | — |
@@ -151,7 +152,7 @@ Here's how `cb` stacks up against other Forgejo CLI tools. *Last updated: May 20
151
152
  |---|---|---|---|---|---|
152
153
  | Create | ✅ | ✅ | ✅ | ✅ | ✅ |
153
154
  | List | ✅ | ✅ | ✅ | ✅ | ✅ |
154
- | View | ✅ | ✅ | ✅ | ✅ | |
155
+ | View | ✅ | ✅ | ✅ | ✅ | |
155
156
  | Upload assets | ✅ | — | ✅ | — | ✅ |
156
157
  | Delete | ✅ | — | — | ✅ | ✅ |
157
158
  | Edit | ✅ | — | — | ✅ | — |
@@ -164,12 +165,12 @@ Here's how `cb` stacks up against other Forgejo CLI tools. *Last updated: May 20
164
165
  | Create | ✅ | ✅ | ✅ | ✅ | ✅ |
165
166
  | List | ✅ | ✅ | ✅ | ✅ | ✅ |
166
167
  | View | ✅ | ✅ | ✅ | ✅ | ✅ |
167
- | Clone | ✅ | | ✅ | ✅ | — |
168
+ | Clone | ✅ | | ✅ | ✅ | — |
168
169
  | Fork | ✅ | ✅ | ✅ | ✅ | ✅ |
169
170
  | Delete | ✅ | — | ✅ | ✅ | — |
170
171
  | Star | ✅ | ✅ | ✅ | ✅ | — |
171
- | Unstar | ✅ | | ✅ | ✅ | — |
172
- | Watch/Unwatch | ✅ | | — | ✅ | — |
172
+ | Unstar | ✅ | | ✅ | ✅ | — |
173
+ | Watch/Unwatch | ✅ | | — | ✅ | — |
173
174
  | Edit | ✅ | ✅ | — | ✅ | — |
174
175
  | Migrate/Mirror | ✅ | ✅ | — | ✅ | — |
175
176
  | Branches | ✅ | — | — | ✅ | — |
@@ -207,7 +208,7 @@ Here's how `cb` stacks up against other Forgejo CLI tools. *Last updated: May 20
207
208
  |---|---|---|---|---|---|
208
209
  | List | ✅ | — | ✅ | ✅ | ✅ |
209
210
  | Mark read | — | — | — | ✅ | — |
210
- | Thread details | — | — | — | | — |
211
+ | Thread details | — | — | — | | — |
211
212
  | Per-repo | — | — | — | ✅ | — |
212
213
 
213
214
  ### Extra
@@ -225,7 +226,7 @@ Here's how `cb` stacks up against other Forgejo CLI tools. *Last updated: May 20
225
226
  | Config management | ✅ | — | ✅ | — | — |
226
227
  | Web browser flag | on view commands | — | — | ✅ | — |
227
228
 
228
- **`cb` is the most feature-complete Forgejo CLI** — by a wide margin. It dominates on repo management (branches, topics, languages, tags, commits, contents, collaborators, search, archive, transfer, watch/unwatch, sync-fork, migrate), issues (delete, pin, labels, search, subscribe, tracked times), PRs (diff, commits, files, reopen, update), releases (delete, edit, latest, by-tag), and extras (Actions, org/team management, `--json` on every command, raw API, release uploads). Built in Python with [Xclif](https://xclif.readthedocs.io) for a clean, hackable codebase. If something's missing, open an issue!
229
+ Built in Python with [Xclif](https://xclif.readthedocs.io) for a clean, hackable codebase. If something's missing, open an issue!
229
230
 
230
231
  ## License
231
232
 
@@ -1,5 +1,5 @@
1
1
  codeberg_cli/__main__.py,sha256=35xiBzBbgDy9rcHqCJWHdIVsWhGEtPQNd-s9wt3k7yE,141
2
- codeberg_cli/client.py,sha256=FAtrPdrIpQqJQT3KsRR8cz6yrZytsYK6JVcZ80vtw8s,2923
2
+ codeberg_cli/client.py,sha256=M0nBI7UyTtO4Me13stntaYEDR-yFA5GtfF4I6KIQzFY,3367
3
3
  codeberg_cli/config.py,sha256=bjVHHM1sG3xTIU6EC7sakwR0nnP-ZsCtO4Jn2od6X4A,822
4
4
  codeberg_cli/git.py,sha256=DIzHSaezhWQGl63f8pkYDNd-qDfoMe7SZBZ7TWVlCxc,1899
5
5
  codeberg_cli/helpers.py,sha256=DQe6Be9B7eLPEVRJ4guo644UWKivAADniS7uh42_3Mk,3268
@@ -8,10 +8,11 @@ codeberg_cli/routes/api.py,sha256=o8she7_o32DNuYqr1v9D0hEHjujW1xEZEhHuxIzKO_8,72
8
8
  codeberg_cli/routes/notifications.py,sha256=Jqjy287S0YevaHMy_xwDp3HSZILWL7RBSS7YskQd3WA,1350
9
9
  codeberg_cli/routes/user.py,sha256=uPQowX-VoOs2zumFhbultqeOeFmZ-OODEMEnu5WvMQ0,1099
10
10
  codeberg_cli/routes/actions/__init__.py,sha256=KCjUWUN2rh_GollBkNwoLZtpm9gPC5PPLfQOvd4gCrc,153
11
+ codeberg_cli/routes/actions/_format.py,sha256=J-FE4GQAo97nLPPABtGVBVAYReEG3yAfUalERDn-FWI,1335
11
12
  codeberg_cli/routes/actions/dispatch.py,sha256=Lu3FyE7M8DdSHefist1y97Qp2khho0MRPj-QcnoKaAU,1030
12
- codeberg_cli/routes/actions/run.py,sha256=HkM7lAOD5-w668CX2kzmYg3B6NHOjb2KYFA97oPtlX0,1379
13
- codeberg_cli/routes/actions/runs.py,sha256=oK4JqAqIJV6lJturQQ8_pqBxpbsIdvCG3oy9MIC7UIs,1600
14
- codeberg_cli/routes/actions/workflows.py,sha256=f7ERoPM-VM4d7VcGxZZnZewkU9tQ_8gCHtwo1xVEVvw,1225
13
+ codeberg_cli/routes/actions/run.py,sha256=r-yNjiYtdx-PyV-GE5vuQI-AVK43YQARRXaAR64rLqg,1529
14
+ codeberg_cli/routes/actions/runs.py,sha256=7Bw77hsUMkLN8xwvn0BDD3lkNHNvGlIcD5DrziVAEs8,1398
15
+ codeberg_cli/routes/actions/workflows.py,sha256=cbrcINWbn7n9Cm21BLm16l4guMRyZkT6eLHydMLAD7o,1883
15
16
  codeberg_cli/routes/auth/__init__.py,sha256=eQHz7mep-kGESlmrv4tTAD3EPTqlNC2Dy9MeJkTxUi0,139
16
17
  codeberg_cli/routes/auth/login.py,sha256=6QxaEz5cvSgJbr-dXpudP2VbGxsLx3xPw0cMwWZm1aU,654
17
18
  codeberg_cli/routes/auth/logout.py,sha256=LfsYchVxrr77R5c2WNGbKNCLbkyQtbobkhcpw1DH8HA,351
@@ -115,8 +116,8 @@ codeberg_cli/routes/repo/tag/list.py,sha256=HI9K00-bf50XcimXKzQR-YD4l_y7m8Rfp72U
115
116
  codeberg_cli/routes/repo/topics/__init__.py,sha256=lHx6_CZgeOqtFPasOg0sfM6De61V3mfd-FW-bDOsCqM,117
116
117
  codeberg_cli/routes/repo/topics/list.py,sha256=oV-3wZVQj1RlLeZjBg-EAtv_roB71eTfnB9lWDBg680,931
117
118
  codeberg_cli/routes/repo/topics/set.py,sha256=hhVOMw-3btCgwlQXd34n6A6jEu0f56GcSyJTsyuUiDI,911
118
- codeberg_cli-0.3.0.dist-info/METADATA,sha256=fuF5egD_3yVaXW4nvJRkKLe4Q_ouh6lpMX_wXYwzLSM,8585
119
- codeberg_cli-0.3.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
120
- codeberg_cli-0.3.0.dist-info/entry_points.txt,sha256=7Kg1K5av7D5TzPCqX_qyFCj09JTneIEvW0f2Gp4q1v4,49
121
- codeberg_cli-0.3.0.dist-info/licenses/LICENSE,sha256=o71itnX05JiF5qOrKHEmWIvuf03sgYcwsc3r6AAW_h0,1065
122
- codeberg_cli-0.3.0.dist-info/RECORD,,
119
+ codeberg_cli-0.4.1.dist-info/METADATA,sha256=PElJmoyjTT2ZbJne1chLRJ_WRKgkh7rH0EFhw2DuFr0,8124
120
+ codeberg_cli-0.4.1.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
121
+ codeberg_cli-0.4.1.dist-info/entry_points.txt,sha256=7Kg1K5av7D5TzPCqX_qyFCj09JTneIEvW0f2Gp4q1v4,49
122
+ codeberg_cli-0.4.1.dist-info/licenses/LICENSE,sha256=o71itnX05JiF5qOrKHEmWIvuf03sgYcwsc3r6AAW_h0,1065
123
+ codeberg_cli-0.4.1.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.29.0
2
+ Generator: hatchling 1.30.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any