gitcode-api 1.2.11__py3-none-any.whl → 1.2.12__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.
gitcode_api/cli.py CHANGED
@@ -1,6 +1,7 @@
1
1
  """Command-line interface for the GitCode SDK."""
2
2
 
3
3
  import argparse
4
+ import codecs
4
5
  import inspect
5
6
  import json
6
7
  import re
@@ -8,7 +9,7 @@ import sys
8
9
  import textwrap
9
10
  from collections.abc import Mapping, Sequence
10
11
  from pathlib import Path
11
- from typing import Any, List, Optional, Union, get_args, get_origin
12
+ from typing import Any, Dict, List, Optional, Union, get_args, get_origin
12
13
 
13
14
  import httpx
14
15
 
@@ -36,6 +37,40 @@ def _plain_cli_inline(text: str) -> str:
36
37
  return t
37
38
 
38
39
 
40
+ _ESCAPE_PATTERN = re.compile(r"\\\w+")
41
+
42
+
43
+ def _unescape_input(value: str, replacements: Dict[str, str]) -> str:
44
+ """Unescape CLI input with provided escape sequences."""
45
+ for token, decoded in replacements.items():
46
+ value = value.replace(token, decoded)
47
+ return value
48
+
49
+
50
+ def _unescape_namespace(args: argparse.Namespace) -> None:
51
+ mapping = ((token, codecs.decode(token, "unicode-escape")) for token in _ESCAPE_PATTERN.findall(str(args.escape)))
52
+ replacements = {token: decoded for token, decoded in mapping if token and (token != decoded)}
53
+ if not replacements:
54
+ raise argparse.ArgumentTypeError("No valid escape sequence provided!")
55
+ for key, value in vars(args).items():
56
+ if key in {"escape", "base_url", "resource", "method", "api_key"}:
57
+ continue
58
+ if isinstance(value, str):
59
+ setattr(args, key, _unescape_input(value, replacements=replacements))
60
+ continue
61
+ if isinstance(value, list):
62
+ updated = []
63
+ changed = False
64
+ for item in value:
65
+ if isinstance(item, str):
66
+ updated.append(_unescape_input(item, replacements=replacements))
67
+ changed = True
68
+ else:
69
+ updated.append(item)
70
+ if changed:
71
+ setattr(args, key, updated)
72
+
73
+
39
74
  def _unwrap_optional(annotation: Any) -> Any:
40
75
  origin = get_origin(annotation)
41
76
  if origin is Union:
@@ -179,12 +214,17 @@ def _invocation_parent_parser() -> argparse.ArgumentParser:
179
214
  """Parser with flags for real API calls (attached only to leaf METHOD parsers, not top-level usage)."""
180
215
  parser = argparse.ArgumentParser(add_help=False)
181
216
  parser.add_argument("--api-key", help=f"GitCode access token. Defaults to {DEFAULT_TOKEN_ENV}.")
182
- parser.add_argument("--owner", help="Default repository owner.")
183
- parser.add_argument("--repo", help="Default repository name.")
184
217
  parser.add_argument("--base-url", default=DEFAULT_BASE_URL, help="Base URL for the REST API.")
185
218
  parser.add_argument("--timeout", type=float, default=None, help="Request timeout in seconds.")
186
219
  parser.add_argument("--output-file", help="Write the response to a file instead of stdout.")
187
220
  parser.add_argument("--compact", action="store_true", help="Print JSON without indentation.")
221
+ parser.add_argument(
222
+ "-e",
223
+ "--escape",
224
+ default="",
225
+ metavar="SEQUENCES",
226
+ help='Unescape certain escape sequences (e.g. -e "\\n\\t") in arguments.',
227
+ )
188
228
  return parser
189
229
 
190
230
 
@@ -192,6 +232,15 @@ def _root_banner() -> str:
192
232
  return "Connection and defaults are documented on each method's help: %(prog)s RESOURCE METHOD -h."
193
233
 
194
234
 
235
+ def _parse_true_false(raw: str) -> bool:
236
+ value = raw.strip().lower()
237
+ if value == "true":
238
+ return True
239
+ if value == "false":
240
+ return False
241
+ raise argparse.ArgumentTypeError("Expected 'true' or 'false'.")
242
+
243
+
195
244
  def _serve_parser() -> argparse.ArgumentParser:
196
245
  """Parser with options for starting the bundled MCP server."""
197
246
  parser = argparse.ArgumentParser(add_help=False)
@@ -201,10 +250,25 @@ def _serve_parser() -> argparse.ArgumentParser:
201
250
  parser.add_argument("--repo", help="Default repository name.")
202
251
  parser.add_argument("--base-url", default=DEFAULT_BASE_URL, help="Base URL for the REST API.")
203
252
  parser.add_argument("--timeout", type=float, default=None, help="Request timeout in seconds.")
204
- parser.add_argument("--transport", default="stdio", help="FastMCP transport to run, such as stdio or http.")
253
+ parser.add_argument(
254
+ "--transport",
255
+ default="stdio",
256
+ choices=("stdio", "http", "sse"),
257
+ metavar="{stdio,http,sse}",
258
+ help="FastMCP transport to run, such as stdio or http.",
259
+ )
205
260
  parser.add_argument("--host", default=None, help="Host for HTTP-based transports.")
206
261
  parser.add_argument("--port", type=int, default=None, help="Port for HTTP-based transports.")
207
262
  parser.add_argument("--path", default=None, help="Path for HTTP-based transports.")
263
+ parser.add_argument(
264
+ "-b",
265
+ "--show-banner",
266
+ type=_parse_true_false,
267
+ choices=(True, False),
268
+ default=None,
269
+ metavar="{true,false}",
270
+ help="Show the FastMCP startup banner.",
271
+ )
208
272
  return parser
209
273
 
210
274
 
@@ -356,7 +420,7 @@ def _run_mcp_server(args: argparse.Namespace) -> int:
356
420
  if value is not None:
357
421
  run_kwargs[key] = value
358
422
 
359
- server.run(**run_kwargs)
423
+ server.run(show_banner=args.show_banner, **run_kwargs)
360
424
  return 0
361
425
 
362
426
 
@@ -402,6 +466,9 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
402
466
  parser.epilog = saved_epilog
403
467
  return 0
404
468
  args = parser.parse_args(effective)
469
+ escape_seq = getattr(args, "escape", None)
470
+ if escape_seq and isinstance(escape_seq, str):
471
+ _unescape_namespace(args)
405
472
 
406
473
  try:
407
474
  if getattr(args, "command", None) == "serve":
@@ -409,8 +476,6 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
409
476
 
410
477
  with GitCode(
411
478
  api_key=args.api_key,
412
- owner=args.owner,
413
- repo=args.repo,
414
479
  base_url=args.base_url,
415
480
  timeout=args.timeout,
416
481
  ) as client:
gitcode_api/run_mcp.py CHANGED
@@ -3,4 +3,4 @@
3
3
  from gitcode_api.llm.mcp import GitCodeMCP
4
4
 
5
5
  if __name__ == "__main__":
6
- GitCodeMCP().mcp.run()
6
+ GitCodeMCP().mcp.run(show_banner=False)
gitcode_api/version.txt CHANGED
@@ -1 +1 @@
1
- 1.2.11
1
+ 1.2.12
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gitcode-api
3
- Version: 1.2.11
3
+ Version: 1.2.12
4
4
  Summary: Easy to use Python SDK for the GitCode REST API. Providing builtin CLI tool, and optional LLM integration (MCP, OpenAI tool, and openJiuwen tool) for agents. Community-maintained.
5
5
  Author-email: Hugo Huang <hugo@hugohuang.com>
6
6
  License-Expression: MIT
@@ -9,7 +9,7 @@ Project-URL: issues, https://github.com/Trenza1ore/GitCode-API/issues
9
9
  Project-URL: documentation, https://gitcode-api.readthedocs.io
10
10
  Project-URL: gitcode, https://gitcode.com/SushiNinja/GitCode-API
11
11
  Project-URL: github, https://github.com/Trenza1ore/GitCode-API
12
- Project-URL: homepage, https://linktr.ee/Hugoooo
12
+ Project-URL: homepage, https://hugohuang.com/gitcode-api
13
13
  Project-URL: author, https://hugohuang.com
14
14
  Keywords: gitcode,git,devops,api,sdk,python,httpx,client,mcp,agent,fastmcp,llm,openjiuwen,mcp client,mcp server,model context protocol
15
15
  Classifier: Development Status :: 4 - Beta
@@ -37,7 +37,7 @@ Dynamic: license-file
37
37
 
38
38
  # GitCode-API
39
39
 
40
- [![PyPI - Version](https://img.shields.io/pypi/v/gitcode-api?link=https%3A%2F%2Fpypi.org%2Fproject%2Fgitcode-api%2F)](https://pypi.org/project/gitcode-api) [![PyPI Downloads](https://static.pepy.tech/personalized-badge/gitcode-api?period=total&units=INTERNATIONAL_SYSTEM&left_color=GRAY&right_color=RED&left_text=downloads)](https://pepy.tech/projects/gitcode-api) [![CodeFactor](https://www.codefactor.io/repository/github/trenza1ore/gitcode-api/badge)](https://www.codefactor.io/repository/github/trenza1ore/gitcode-api)
40
+ [![PyPI - Version](https://img.shields.io/pypi/v/gitcode-api?link=https%3A%2F%2Fpypi.org%2Fproject%2Fgitcode-api%2F&uuid=d541c73026c34c2a825a2dbefb55ce2c)](https://pypi.org/project/gitcode-api) [![PyPI Downloads](https://static.pepy.tech/personalized-badge/gitcode-api?period=total&units=INTERNATIONAL_SYSTEM&left_color=GRAY&right_color=RED&left_text=downloads&uuid=28b7f87502c04ba39f9cdbcff8d5d25d)](https://pepy.tech/projects/gitcode-api) [![CodeFactor](https://www.codefactor.io/repository/github/trenza1ore/gitcode-api/badge)](https://www.codefactor.io/repository/github/trenza1ore/gitcode-api)
41
41
  [![Install in Cursor](https://img.shields.io/badge/Install_in-Cursor-000000?logoColor=white)](https://cursor.com/en/install-mcp?name=GitCode%20API&config=eyJjb21tYW5kIjoidXZ4IiwiYXJncyI6WyItLWZyb20iLCJnaXRjb2RlLWFwaVttY3BdIiwiZ2l0Y29kZS1hcGkiLCJzZXJ2ZSJdLCJlbnYiOnsiR0lUQ09ERV9BQ0NFU1NfVE9LRU4iOiIke2lucHV0OmdpdGNvZGVfYWNjZXNzX3Rva2VufSJ9LCJpbnB1dHMiOlt7ImlkIjoiZ2l0Y29kZV9hY2Nlc3NfdG9rZW4iLCJ0eXBlIjoicHJvbXB0U3RyaW5nIiwiZGVzY3JpcHRpb24iOiJFbnRlciBHSVRDT0RFX0FDQ0VTU19UT0tFTiIsInBhc3N3b3JkIjp0cnVlfV19) [![Install in VS Code](https://img.shields.io/badge/Install_in-VS_Code-0098FF?logo=visualstudiocode&logoColor=white)](https://vscode.dev/redirect/mcp/install?name=GitCode%20API&config=%7B%22command%22%3A%22uvx%22%2C%22args%22%3A%5B%22--from%22%2C%22gitcode-api%5Bmcp%5D%22%2C%22gitcode-api%22%2C%22serve%22%5D%2C%22env%22%3A%7B%22GITCODE_ACCESS_TOKEN%22%3A%22%24%7Binput%3Agitcode_access_token%7D%22%7D%2C%22inputs%22%3A%5B%7B%22id%22%3A%22gitcode_access_token%22%2C%22type%22%3A%22promptString%22%2C%22description%22%3A%22Enter%20GITCODE_ACCESS_TOKEN%22%2C%22password%22%3Atrue%7D%5D%7D)
42
42
  [![GitHub Badge](https://img.shields.io/badge/github-repo-blue?logo=github&link=https%3A%2F%2Fgithub.com%2FTrenza1ore%2FGitCode-API)](https://github.com/Trenza1ore/GitCode-API) [![GitCode Badge](https://img.shields.io/badge/gitcode-repo-brown?logo=gitcode&link=https%3A%2F%2Fgitcode.com%2FSushiNinja%2FGitCode-API)](https://gitcode.com/SushiNinja/GitCode-API)
43
43
 
@@ -111,12 +111,14 @@ With `gitcode-api[mcp]` installed (Python 3.10+), you can start the bundled Fast
111
111
  gitcode-api serve --api-key "$GITCODE_ACCESS_TOKEN"
112
112
  ```
113
113
 
114
- Use `gitcode-api serve -h` for defaults such as `--owner`, `--repo`, and `--transport`.
114
+ Use `gitcode-api serve -h` for defaults such as `--owner`, `--repo`, `--transport` (`stdio`, `http`, or `sse`), and other options.
115
115
 
116
116
  Commands mirror the synchronous resource methods on `GitCode`, using the pattern
117
117
  `gitcode-api <resource> <method> ...`. For methods that accept extra `**params`
118
118
  or `**payload`, pass repeated `--set key=value` flags or `--set-json '{"key": "value"}'`.
119
119
 
120
+ When using string arguments with escape sequence (such as line break `\n`), pass `-e` / `--escape` with the sequences to un-escape, such as `-e '\n\t'`.
121
+
120
122
  ## Quick Start
121
123
 
122
124
  ### Sync client
@@ -6,10 +6,10 @@ gitcode_api/_cli_banner.py,sha256=3DsoJ2qZ-mWWB4yD-cnxDN_osXzrUKabrA5tbV6752M,97
6
6
  gitcode_api/_client.py,sha256=bmZxBHdfshM5Kv_EurHUVu8rsEj0k3Up3ATSIPaFrvc,8258
7
7
  gitcode_api/_exceptions.py,sha256=T5N8gBGmPSktDkLP5P_hxbzOHw3W378TzxN1xja40pA,1140
8
8
  gitcode_api/_models.py,sha256=v-GZzCGAb3_frY6wFiQww9m271U5MigivpEHDHnoDcI,109030
9
- gitcode_api/cli.py,sha256=7LLDRCKJg7avaLgIwckZZC5LewSpMPWNQFFDRhAQkEs,16616
9
+ gitcode_api/cli.py,sha256=Z-X5gK8iI2wCEXqT-igVKpVzO4ZhaRYaxmTbqMbIUx8,18735
10
10
  gitcode_api/py.typed,sha256=mDShSrm8qg9qjacQc2F-rI8ATllqP6EdgHuEYxuCXZ0,7
11
- gitcode_api/run_mcp.py,sha256=a7zNrcAooGovzokJwTHQGj6iT4g7iltaUoD_E1KLvMg,130
12
- gitcode_api/version.txt,sha256=NzEMfzSBZRIsy59KhUwpSFOVuzrwZZulp3vgZsFRFnk,7
11
+ gitcode_api/run_mcp.py,sha256=3_JOrjg9_yL-0M-H-F8mPgxdVKh7K2ggipu7UHeNCg0,147
12
+ gitcode_api/version.txt,sha256=yAj7rMwM5p-R46aEMo_IcvIhK0Iz-9gcQKB26AMuEjY,7
13
13
  gitcode_api/llm/__init__.py,sha256=rU75ZlJvTWNVxBLc3QzdfWmSjqVc9z6hfQ8z6jVVKOk,1693
14
14
  gitcode_api/llm/_tool.py,sha256=b65iUiHo1H29uA6mFM3WlD0zZlISsENx1tpEqlkiUoA,16239
15
15
  gitcode_api/llm/jiuwen.py,sha256=axwAcoG86XkPkN37PTh47Cdzwh3yACUpe4bTjlaAFDc,4244
@@ -21,9 +21,9 @@ gitcode_api/resources/account.py,sha256=mnc2p7wI-nBnHFNdWPNiHfmZpT6d3RDQC777gewt
21
21
  gitcode_api/resources/collaboration.py,sha256=8lyk78GTjVXddiE9fieutsMGovRjteGfTJcAhwLoR0M,101607
22
22
  gitcode_api/resources/misc.py,sha256=guDwh4cxbTVsSa7EivaYM3bKMJ8_Op4KucGbKEoayKE,22412
23
23
  gitcode_api/resources/repositories.py,sha256=EAK2znZhEsgVUu-NDEQslSEEYJzvb-kHuh4mW57y6sc,78178
24
- gitcode_api-1.2.11.dist-info/licenses/LICENSE,sha256=gOACXuWhMu6PJKVLr9RQbxX3HULnZIGNXCaMFJIXhoA,1067
25
- gitcode_api-1.2.11.dist-info/METADATA,sha256=3VOsMVB8v0K7pMtOetkpLGH4UJjeF9R_QsEmF9GbZrs,22054
26
- gitcode_api-1.2.11.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
27
- gitcode_api-1.2.11.dist-info/entry_points.txt,sha256=dIPylJcgohIE2RRIlt3In2WzcwDK8TOdkL_ReKuij4o,53
28
- gitcode_api-1.2.11.dist-info/top_level.txt,sha256=gIlg0ptyOUHJT64ajOjWIhRPYgIQnMIvnhhnesw9fxU,12
29
- gitcode_api-1.2.11.dist-info/RECORD,,
24
+ gitcode_api-1.2.12.dist-info/licenses/LICENSE,sha256=gOACXuWhMu6PJKVLr9RQbxX3HULnZIGNXCaMFJIXhoA,1067
25
+ gitcode_api-1.2.12.dist-info/METADATA,sha256=7Fnrif5ZdLzUuFrFvSSpSeetslQ7iV-9gUX4QNueFFY,22335
26
+ gitcode_api-1.2.12.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
27
+ gitcode_api-1.2.12.dist-info/entry_points.txt,sha256=dIPylJcgohIE2RRIlt3In2WzcwDK8TOdkL_ReKuij4o,53
28
+ gitcode_api-1.2.12.dist-info/top_level.txt,sha256=gIlg0ptyOUHJT64ajOjWIhRPYgIQnMIvnhhnesw9fxU,12
29
+ gitcode_api-1.2.12.dist-info/RECORD,,