gitcode-api 1.2.17__py3-none-any.whl → 1.2.18__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/__init__.py CHANGED
@@ -1,7 +1,7 @@
1
1
  """Public package exports for the GitCode SDK."""
2
2
 
3
3
  import re
4
- from importlib.metadata import metadata
4
+ from importlib.metadata import PackageNotFoundError, metadata, version
5
5
  from typing import cast
6
6
 
7
7
  from . import constants
@@ -14,11 +14,32 @@ from ._exceptions import (
14
14
  )
15
15
  from .utils import as_dict
16
16
 
17
- package_meta = metadata("gitcode_api")
18
- package_desc = cast(str, package_meta.get("Description"))
19
- readme_uuids = re.findall(r"\&uuid=(\w+)", package_desc, flags=re.ASCII)
20
- __build_hash__ = readme_uuids[0] if readme_uuids else "unknown"
21
- __version__ = cast(str, package_meta.get("Version")).strip()
17
+ _README_UUIDS = []
18
+ _VERSION_STR = "unknown"
19
+
20
+ try:
21
+ package_meta = metadata("gitcode_api")
22
+ package_desc = cast(str, package_meta.get("Description"))
23
+ _README_UUIDS = re.findall(r"\&uuid=(\w+)", package_desc, flags=re.ASCII)
24
+ _VERSION_STR = version("gitcode_api")
25
+ except PackageNotFoundError:
26
+ from pathlib import Path
27
+
28
+ import tomllib
29
+
30
+ pyproject_toml = Path(__file__).parent.parent / "pyproject.toml"
31
+ if pyproject_toml.exists():
32
+ _VERSION_STR = tomllib.loads(pyproject_toml.read_text(encoding="utf-8")).get("project", {}).get("version", "")
33
+ else:
34
+ version_file = Path(__file__).with_name("version.txt")
35
+ if version_file.exists():
36
+ _VERSION_STR = version_file.read_text(encoding="utf-8").strip()
37
+ read_me_file = pyproject_toml.with_name("README.md")
38
+ if read_me_file.exists():
39
+ _README_UUIDS = re.findall(r"\&uuid=(\w+)", read_me_file.read_text(encoding="utf-8").strip(), flags=re.ASCII)
40
+
41
+ __build_hash__ = _README_UUIDS[0] if _README_UUIDS else "unknown"
42
+ __version__ = _VERSION_STR.strip()
22
43
 
23
44
  __all__ = [
24
45
  "constants",
@@ -20,6 +20,11 @@ def _drop_none_values(mapping: Dict[str, Any]) -> Dict[str, Any]:
20
20
  return {key: value for key, value in mapping.items() if value is not None}
21
21
 
22
22
 
23
+ def _default_decrypt(value: Any) -> str:
24
+ """Dummy decryption function, basically a no-op."""
25
+ return value
26
+
27
+
23
28
  class BaseGitCodeClient:
24
29
  """Base configuration shared by synchronous and asynchronous clients.
25
30
 
@@ -42,19 +47,24 @@ class BaseGitCodeClient:
42
47
  decrypt: Optional[Callable] = None,
43
48
  ) -> None:
44
49
  """Store client configuration and resolve authentication."""
45
- self.api_key = self._resolve_api_key(api_key, decrypt)
50
+ self.decrypt = decrypt or _default_decrypt
51
+ self.api_key = self._resolve_api_key(api_key)
46
52
  self.owner = owner
47
53
  self.repo = repo
48
54
  self.base_url = base_url.rstrip("/")
49
55
  self.timeout = timeout if timeout is not None else DEFAULT_TIMEOUT
50
56
 
51
- def _resolve_api_key(self, api_key: Optional[str], decrypt: Optional[Callable] = None) -> str:
57
+ def _resolve_api_key(self, api_key: Optional[str]) -> str:
52
58
  """Resolve the access token from an argument or environment variable."""
53
59
  token = api_key or os.getenv(DEFAULT_TOKEN_ENV)
54
- if callable(decrypt):
55
- token = decrypt(token)
56
60
  if not token:
57
61
  raise GitCodeConfigurationError("No API key provided. Pass api_key=... or set GITCODE_ACCESS_TOKEN.")
62
+ try:
63
+ token_decrypt = self.decrypt(str(token))
64
+ if not isinstance(token_decrypt, str):
65
+ raise TypeError(f"Decrypted token has type={type(token_decrypt)} instead of str: {token_decrypt}")
66
+ except Exception as e:
67
+ raise GitCodeConfigurationError("Invalid decrypt function, check its correctness.") from e
58
68
  return str(token)
59
69
 
60
70
  def _resolve_repo_context(
@@ -75,7 +85,7 @@ class BaseGitCodeClient:
75
85
  """Build request headers for authenticated JSON API calls."""
76
86
  headers = {
77
87
  "Accept": "application/json",
78
- "Authorization": f"Bearer {self.api_key}",
88
+ "Authorization": f"Bearer {self.decrypt(self.api_key)}",
79
89
  }
80
90
  if extra_headers:
81
91
  headers.update(extra_headers)
gitcode_api/py.typed CHANGED
@@ -1 +0,0 @@
1
- partial
gitcode_api/version.txt CHANGED
@@ -1 +1 @@
1
- 1.2.17
1
+ 1.2.18
@@ -1,16 +1,16 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gitcode-api
3
- Version: 1.2.17
3
+ Version: 1.2.18
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
7
- Project-URL: changelog, https://gitcode-api.readthedocs.io/en/latest/changelog.html
8
- Project-URL: issues, https://github.com/Trenza1ore/GitCode-API/issues
9
- Project-URL: documentation, https://gitcode-api.readthedocs.io
10
- Project-URL: gitcode, https://gitcode.com/SushiNinja/GitCode-API
11
- Project-URL: github, https://github.com/Trenza1ore/GitCode-API
12
- Project-URL: homepage, https://hugohuang.com/gitcode-api
13
- Project-URL: author, https://hugohuang.com
7
+ Project-URL: Changelog, https://gitcode-api.readthedocs.io/en/latest/changelog.html
8
+ Project-URL: Issues, https://github.com/Trenza1ore/GitCode-API/issues
9
+ Project-URL: Documentation, https://gitcode-api.readthedocs.io
10
+ Project-URL: Gitcode, https://gitcode.com/SushiNinja/GitCode-API
11
+ Project-URL: Github, https://github.com/Trenza1ore/GitCode-API
12
+ Project-URL: Homepage, https://hugohuang.com/gitcode-api
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
16
16
  Classifier: Programming Language :: Python
@@ -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&uuid=0c863acb12c7438c96f44568f4d808ce)](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=161cdcabfd404203848318e830b96b41)](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=f049bfb2e9a847dfb667888d9e54d163)](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=3d4c578403ac4d8aab1c59a48425e14b)](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
 
@@ -1,6 +1,6 @@
1
- gitcode_api/__init__.py,sha256=c3FpiH2ISh_5FIUEHVALVBsv9rrUl501V0pbmu44z-g,872
1
+ gitcode_api/__init__.py,sha256=94gg5E1bAWozIR6PBYIPdZMfj-VyBFJp_rQQda2Qagk,1672
2
2
  gitcode_api/__main__.py,sha256=Yd8P4MSNcWFqUTKnUaNibbWX4Vd-MVVNmhPFaohzqcA,137
3
- gitcode_api/_base_client.py,sha256=zc2WMxgMA4KdxrhS5Ptmlmf3UIsl09pUoXaOVOGpUms,13523
3
+ gitcode_api/_base_client.py,sha256=qG-d6wlMwjvbK4bi4m4dwHNZR9wP2tSS9qiWFTIIsFA,13960
4
4
  gitcode_api/_base_resource.py,sha256=mlKe1b_1AKcqxhptaCpP-AOjKkLNzCbYG-Pkp1HYWrA,2238
5
5
  gitcode_api/_cli_banner.py,sha256=S6i8dnzCXrxytrboxNh_gz-x95u6w9E-Yz6IkTz2PJk,1576
6
6
  gitcode_api/_client.py,sha256=bmZxBHdfshM5Kv_EurHUVu8rsEj0k3Up3ATSIPaFrvc,8258
@@ -8,10 +8,10 @@ gitcode_api/_exceptions.py,sha256=T5N8gBGmPSktDkLP5P_hxbzOHw3W378TzxN1xja40pA,11
8
8
  gitcode_api/_models.py,sha256=ip0xgdWao8Z3ATfSaPn3KzG81OXd25RVB1ansOaJaUM,110586
9
9
  gitcode_api/cli.py,sha256=7ZrpWIh5zZdftMhbMjldiuvijig8qKLFiQbof93Cy6k,18792
10
10
  gitcode_api/constants.py,sha256=UYfSkmoRc71kIkgFYS5NFUoFhdbcXvnGV-EiJnvbELI,296
11
- gitcode_api/py.typed,sha256=mDShSrm8qg9qjacQc2F-rI8ATllqP6EdgHuEYxuCXZ0,7
11
+ gitcode_api/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  gitcode_api/run_mcp.py,sha256=3_JOrjg9_yL-0M-H-F8mPgxdVKh7K2ggipu7UHeNCg0,147
13
13
  gitcode_api/utils.py,sha256=51QmPTQPeNsPSGf2IzhwmiEO1H2GkJrp2A7vkzhOOag,1351
14
- gitcode_api/version.txt,sha256=3vZfbhJrgomRbGajbYUy_iaIl-F0UxtE4rP7GwAihls,7
14
+ gitcode_api/version.txt,sha256=EEaCKUK2jb-KMegeJfWHxBHsQs-nsTSYst95cj6LJIo,7
15
15
  gitcode_api/llm/__init__.py,sha256=rU75ZlJvTWNVxBLc3QzdfWmSjqVc9z6hfQ8z6jVVKOk,1693
16
16
  gitcode_api/llm/_tool.py,sha256=b65iUiHo1H29uA6mFM3WlD0zZlISsENx1tpEqlkiUoA,16239
17
17
  gitcode_api/llm/jiuwen.py,sha256=qca2y4544xoRYFOCMbkjiUZZLpJGMcBkK4w5bqs60-4,4276
@@ -23,9 +23,9 @@ gitcode_api/resources/account.py,sha256=mnc2p7wI-nBnHFNdWPNiHfmZpT6d3RDQC777gewt
23
23
  gitcode_api/resources/collaboration.py,sha256=TK0QXG_ymE4vbtHyP3Y-M39oG9zQE44UU5-UnPhF2WM,112388
24
24
  gitcode_api/resources/misc.py,sha256=w7bq8rmgKr2ScBKeWZ3EZJmAdylDdPtSPrhi3AQre7w,34747
25
25
  gitcode_api/resources/repositories.py,sha256=EAK2znZhEsgVUu-NDEQslSEEYJzvb-kHuh4mW57y6sc,78178
26
- gitcode_api-1.2.17.dist-info/licenses/LICENSE,sha256=gOACXuWhMu6PJKVLr9RQbxX3HULnZIGNXCaMFJIXhoA,1067
27
- gitcode_api-1.2.17.dist-info/METADATA,sha256=x3U0ebx62mxesdGHb3QFkXgVZMBTVP2DP75lLptx3IA,23592
28
- gitcode_api-1.2.17.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
29
- gitcode_api-1.2.17.dist-info/entry_points.txt,sha256=dIPylJcgohIE2RRIlt3In2WzcwDK8TOdkL_ReKuij4o,53
30
- gitcode_api-1.2.17.dist-info/top_level.txt,sha256=gIlg0ptyOUHJT64ajOjWIhRPYgIQnMIvnhhnesw9fxU,12
31
- gitcode_api-1.2.17.dist-info/RECORD,,
26
+ gitcode_api-1.2.18.dist-info/licenses/LICENSE,sha256=gOACXuWhMu6PJKVLr9RQbxX3HULnZIGNXCaMFJIXhoA,1067
27
+ gitcode_api-1.2.18.dist-info/METADATA,sha256=QsYuYvwW_j8YWO2FV6YnK6HBOCu9BDLjfIjUaYL_8SI,23592
28
+ gitcode_api-1.2.18.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
29
+ gitcode_api-1.2.18.dist-info/entry_points.txt,sha256=dIPylJcgohIE2RRIlt3In2WzcwDK8TOdkL_ReKuij4o,53
30
+ gitcode_api-1.2.18.dist-info/top_level.txt,sha256=gIlg0ptyOUHJT64ajOjWIhRPYgIQnMIvnhhnesw9fxU,12
31
+ gitcode_api-1.2.18.dist-info/RECORD,,