gitcode-api 1.2.16__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 +32 -2
- gitcode_api/_base_client.py +16 -10
- gitcode_api/_cli_banner.py +15 -3
- gitcode_api/cli.py +3 -3
- gitcode_api/constants.py +8 -0
- gitcode_api/py.typed +0 -1
- gitcode_api/version.txt +1 -1
- {gitcode_api-1.2.16.dist-info → gitcode_api-1.2.18.dist-info}/METADATA +9 -9
- {gitcode_api-1.2.16.dist-info → gitcode_api-1.2.18.dist-info}/RECORD +13 -12
- {gitcode_api-1.2.16.dist-info → gitcode_api-1.2.18.dist-info}/WHEEL +0 -0
- {gitcode_api-1.2.16.dist-info → gitcode_api-1.2.18.dist-info}/entry_points.txt +0 -0
- {gitcode_api-1.2.16.dist-info → gitcode_api-1.2.18.dist-info}/licenses/LICENSE +0 -0
- {gitcode_api-1.2.16.dist-info → gitcode_api-1.2.18.dist-info}/top_level.txt +0 -0
gitcode_api/__init__.py
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"""Public package exports for the GitCode SDK."""
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import re
|
|
4
|
+
from importlib.metadata import PackageNotFoundError, metadata, version
|
|
5
|
+
from typing import cast
|
|
4
6
|
|
|
7
|
+
from . import constants
|
|
5
8
|
from ._client import AsyncGitCode, GitCode
|
|
6
9
|
from ._exceptions import (
|
|
7
10
|
GitCodeAPIError,
|
|
@@ -11,10 +14,37 @@ from ._exceptions import (
|
|
|
11
14
|
)
|
|
12
15
|
from .utils import as_dict
|
|
13
16
|
|
|
14
|
-
|
|
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()
|
|
15
43
|
|
|
16
44
|
__all__ = [
|
|
45
|
+
"constants",
|
|
17
46
|
"__version__",
|
|
47
|
+
"__build_hash__",
|
|
18
48
|
"AsyncGitCode",
|
|
19
49
|
"GitCode",
|
|
20
50
|
"GitCodeAPIError",
|
gitcode_api/_base_client.py
CHANGED
|
@@ -12,11 +12,7 @@ import httpx
|
|
|
12
12
|
|
|
13
13
|
from ._base_resource import BaseResource
|
|
14
14
|
from ._exceptions import GitCodeConfigurationError, GitCodeHTTPStatusError
|
|
15
|
-
|
|
16
|
-
DEFAULT_BASE_URL = "https://api.gitcode.com/api/v5"
|
|
17
|
-
DEFAULT_TIMEOUT = 30.0
|
|
18
|
-
DEFAULT_TOKEN_ENV = "GITCODE_ACCESS_TOKEN"
|
|
19
|
-
DEFAULT_CA_ENV = "GITCODE_CA_BUNDLE"
|
|
15
|
+
from .constants import DEFAULT_BASE_URL, DEFAULT_CA_ENV, DEFAULT_TIMEOUT, DEFAULT_TOKEN_ENV
|
|
20
16
|
|
|
21
17
|
|
|
22
18
|
def _drop_none_values(mapping: Dict[str, Any]) -> Dict[str, Any]:
|
|
@@ -24,6 +20,11 @@ def _drop_none_values(mapping: Dict[str, Any]) -> Dict[str, Any]:
|
|
|
24
20
|
return {key: value for key, value in mapping.items() if value is not None}
|
|
25
21
|
|
|
26
22
|
|
|
23
|
+
def _default_decrypt(value: Any) -> str:
|
|
24
|
+
"""Dummy decryption function, basically a no-op."""
|
|
25
|
+
return value
|
|
26
|
+
|
|
27
|
+
|
|
27
28
|
class BaseGitCodeClient:
|
|
28
29
|
"""Base configuration shared by synchronous and asynchronous clients.
|
|
29
30
|
|
|
@@ -46,19 +47,24 @@ class BaseGitCodeClient:
|
|
|
46
47
|
decrypt: Optional[Callable] = None,
|
|
47
48
|
) -> None:
|
|
48
49
|
"""Store client configuration and resolve authentication."""
|
|
49
|
-
self.
|
|
50
|
+
self.decrypt = decrypt or _default_decrypt
|
|
51
|
+
self.api_key = self._resolve_api_key(api_key)
|
|
50
52
|
self.owner = owner
|
|
51
53
|
self.repo = repo
|
|
52
54
|
self.base_url = base_url.rstrip("/")
|
|
53
55
|
self.timeout = timeout if timeout is not None else DEFAULT_TIMEOUT
|
|
54
56
|
|
|
55
|
-
def _resolve_api_key(self, api_key: Optional[str]
|
|
57
|
+
def _resolve_api_key(self, api_key: Optional[str]) -> str:
|
|
56
58
|
"""Resolve the access token from an argument or environment variable."""
|
|
57
59
|
token = api_key or os.getenv(DEFAULT_TOKEN_ENV)
|
|
58
|
-
if callable(decrypt):
|
|
59
|
-
token = decrypt(token)
|
|
60
60
|
if not token:
|
|
61
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
|
|
62
68
|
return str(token)
|
|
63
69
|
|
|
64
70
|
def _resolve_repo_context(
|
|
@@ -79,7 +85,7 @@ class BaseGitCodeClient:
|
|
|
79
85
|
"""Build request headers for authenticated JSON API calls."""
|
|
80
86
|
headers = {
|
|
81
87
|
"Accept": "application/json",
|
|
82
|
-
"Authorization": f"Bearer {self.api_key}",
|
|
88
|
+
"Authorization": f"Bearer {self.decrypt(self.api_key)}",
|
|
83
89
|
}
|
|
84
90
|
if extra_headers:
|
|
85
91
|
headers.update(extra_headers)
|
gitcode_api/_cli_banner.py
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import sys
|
|
4
4
|
from functools import lru_cache
|
|
5
|
+
from importlib.metadata import metadata
|
|
6
|
+
from typing import List, cast
|
|
5
7
|
|
|
6
8
|
# ANSI Colour Codes
|
|
7
9
|
CREDBG = "\033[41m"
|
|
@@ -24,8 +26,18 @@ BANNER = r"""
|
|
|
24
26
|
|
|
25
27
|
|
|
26
28
|
@lru_cache(maxsize=1)
|
|
27
|
-
def format_default_welcome(version: str) -> str:
|
|
29
|
+
def format_default_welcome(version: str, build: str) -> str:
|
|
28
30
|
"""Colored banner and version line for the no-arguments launcher (plain if not a TTY)."""
|
|
31
|
+
homepage = "https://gitcode-api.readthedocs.io"
|
|
32
|
+
docspage = "https://gitcode-api.readthedocs.io"
|
|
33
|
+
banner = BANNER
|
|
34
|
+
version = f"Ver. {version} (build {build})"
|
|
35
|
+
for project_url in cast(List[str], metadata("gitcode_api").get_all("Project-URL")):
|
|
36
|
+
if project_url.casefold().startswith("homepage"):
|
|
37
|
+
homepage = project_url.split(", ")[1]
|
|
29
38
|
if sys.stdout.isatty():
|
|
30
|
-
|
|
31
|
-
|
|
39
|
+
homepage = f"{CBLU}{homepage}{CEND}"
|
|
40
|
+
docspage = f"{CBLU}{docspage}{CEND}"
|
|
41
|
+
banner = f"{CRED}{BANNER}{CEND}"
|
|
42
|
+
version = f"{CREDBG}{version}{CEND}"
|
|
43
|
+
return f"{banner}\n {version}\n Home Page: {homepage}\n Docs Page: {docspage}\n\n"
|
gitcode_api/cli.py
CHANGED
|
@@ -13,7 +13,7 @@ from typing import Any, Dict, List, Optional, Union, get_args, get_origin
|
|
|
13
13
|
|
|
14
14
|
import httpx
|
|
15
15
|
|
|
16
|
-
from . import GitCode, __version__
|
|
16
|
+
from . import GitCode, __build_hash__, __version__
|
|
17
17
|
from ._base_client import DEFAULT_BASE_URL, DEFAULT_TOKEN_ENV
|
|
18
18
|
from ._cli_banner import format_default_welcome
|
|
19
19
|
from ._exceptions import GitCodeError
|
|
@@ -295,7 +295,7 @@ Each method -h opens with resource.method_signature("<name>") from the Python SD
|
|
|
295
295
|
epilog=epilog,
|
|
296
296
|
formatter_class=_CLIHelpFormatter,
|
|
297
297
|
)
|
|
298
|
-
parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
|
|
298
|
+
parser.add_argument("--version", action="version", version=f"%(prog)s {__version__} (build {__build_hash__})")
|
|
299
299
|
|
|
300
300
|
client = _probe_gitcode()
|
|
301
301
|
try:
|
|
@@ -457,7 +457,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
|
|
|
457
457
|
parser = build_parser()
|
|
458
458
|
effective = list(sys.argv[1:] if argv is None else argv)
|
|
459
459
|
if not effective:
|
|
460
|
-
print(format_default_welcome(__version__), end="")
|
|
460
|
+
print(format_default_welcome(__version__, __build_hash__), end="")
|
|
461
461
|
saved_epilog = parser.epilog
|
|
462
462
|
parser.epilog = None
|
|
463
463
|
try:
|
gitcode_api/constants.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""Shared constant values for the GitCode SDK."""
|
|
2
|
+
|
|
3
|
+
DEFAULT_BASE_URL = "https://api.gitcode.com/api/v5"
|
|
4
|
+
DEFAULT_TIMEOUT = 30.0
|
|
5
|
+
DEFAULT_TOKEN_ENV = "GITCODE_ACCESS_TOKEN"
|
|
6
|
+
DEFAULT_CA_ENV = "GITCODE_CA_BUNDLE"
|
|
7
|
+
|
|
8
|
+
__all__ = ["DEFAULT_BASE_URL", "DEFAULT_TIMEOUT", "DEFAULT_TOKEN_ENV", "DEFAULT_CA_ENV"]
|
gitcode_api/py.typed
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
partial
|
gitcode_api/version.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.2.
|
|
1
|
+
1.2.18
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: gitcode-api
|
|
3
|
-
Version: 1.2.
|
|
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:
|
|
8
|
-
Project-URL:
|
|
9
|
-
Project-URL:
|
|
10
|
-
Project-URL:
|
|
11
|
-
Project-URL:
|
|
12
|
-
Project-URL:
|
|
13
|
-
Project-URL:
|
|
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
|
-
[](https://pypi.org/project/gitcode-api) [](https://pepy.tech/projects/gitcode-api) [](https://www.codefactor.io/repository/github/trenza1ore/gitcode-api)
|
|
41
41
|
[](https://cursor.com/en/install-mcp?name=GitCode%20API&config=eyJjb21tYW5kIjoidXZ4IiwiYXJncyI6WyItLWZyb20iLCJnaXRjb2RlLWFwaVttY3BdIiwiZ2l0Y29kZS1hcGkiLCJzZXJ2ZSJdLCJlbnYiOnsiR0lUQ09ERV9BQ0NFU1NfVE9LRU4iOiIke2lucHV0OmdpdGNvZGVfYWNjZXNzX3Rva2VufSJ9LCJpbnB1dHMiOlt7ImlkIjoiZ2l0Y29kZV9hY2Nlc3NfdG9rZW4iLCJ0eXBlIjoicHJvbXB0U3RyaW5nIiwiZGVzY3JpcHRpb24iOiJFbnRlciBHSVRDT0RFX0FDQ0VTU19UT0tFTiIsInBhc3N3b3JkIjp0cnVlfV19) [](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
|
[](https://github.com/Trenza1ore/GitCode-API) [](https://gitcode.com/SushiNinja/GitCode-API)
|
|
43
43
|
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
gitcode_api/__init__.py,sha256=
|
|
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=
|
|
3
|
+
gitcode_api/_base_client.py,sha256=qG-d6wlMwjvbK4bi4m4dwHNZR9wP2tSS9qiWFTIIsFA,13960
|
|
4
4
|
gitcode_api/_base_resource.py,sha256=mlKe1b_1AKcqxhptaCpP-AOjKkLNzCbYG-Pkp1HYWrA,2238
|
|
5
|
-
gitcode_api/_cli_banner.py,sha256=
|
|
5
|
+
gitcode_api/_cli_banner.py,sha256=S6i8dnzCXrxytrboxNh_gz-x95u6w9E-Yz6IkTz2PJk,1576
|
|
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=ip0xgdWao8Z3ATfSaPn3KzG81OXd25RVB1ansOaJaUM,110586
|
|
9
|
-
gitcode_api/cli.py,sha256=
|
|
10
|
-
gitcode_api/py
|
|
9
|
+
gitcode_api/cli.py,sha256=7ZrpWIh5zZdftMhbMjldiuvijig8qKLFiQbof93Cy6k,18792
|
|
10
|
+
gitcode_api/constants.py,sha256=UYfSkmoRc71kIkgFYS5NFUoFhdbcXvnGV-EiJnvbELI,296
|
|
11
|
+
gitcode_api/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
12
|
gitcode_api/run_mcp.py,sha256=3_JOrjg9_yL-0M-H-F8mPgxdVKh7K2ggipu7UHeNCg0,147
|
|
12
13
|
gitcode_api/utils.py,sha256=51QmPTQPeNsPSGf2IzhwmiEO1H2GkJrp2A7vkzhOOag,1351
|
|
13
|
-
gitcode_api/version.txt,sha256=
|
|
14
|
+
gitcode_api/version.txt,sha256=EEaCKUK2jb-KMegeJfWHxBHsQs-nsTSYst95cj6LJIo,7
|
|
14
15
|
gitcode_api/llm/__init__.py,sha256=rU75ZlJvTWNVxBLc3QzdfWmSjqVc9z6hfQ8z6jVVKOk,1693
|
|
15
16
|
gitcode_api/llm/_tool.py,sha256=b65iUiHo1H29uA6mFM3WlD0zZlISsENx1tpEqlkiUoA,16239
|
|
16
17
|
gitcode_api/llm/jiuwen.py,sha256=qca2y4544xoRYFOCMbkjiUZZLpJGMcBkK4w5bqs60-4,4276
|
|
@@ -22,9 +23,9 @@ gitcode_api/resources/account.py,sha256=mnc2p7wI-nBnHFNdWPNiHfmZpT6d3RDQC777gewt
|
|
|
22
23
|
gitcode_api/resources/collaboration.py,sha256=TK0QXG_ymE4vbtHyP3Y-M39oG9zQE44UU5-UnPhF2WM,112388
|
|
23
24
|
gitcode_api/resources/misc.py,sha256=w7bq8rmgKr2ScBKeWZ3EZJmAdylDdPtSPrhi3AQre7w,34747
|
|
24
25
|
gitcode_api/resources/repositories.py,sha256=EAK2znZhEsgVUu-NDEQslSEEYJzvb-kHuh4mW57y6sc,78178
|
|
25
|
-
gitcode_api-1.2.
|
|
26
|
-
gitcode_api-1.2.
|
|
27
|
-
gitcode_api-1.2.
|
|
28
|
-
gitcode_api-1.2.
|
|
29
|
-
gitcode_api-1.2.
|
|
30
|
-
gitcode_api-1.2.
|
|
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,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|