python-cnb 0.1.0__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.
- cnb/__init__.py +7 -0
- cnb/artifactory.py +205 -0
- cnb/assets.py +219 -0
- cnb/build.py +91 -0
- cnb/client.py +79 -0
- cnb/cnb.py +46 -0
- cnb/collaborators.py +320 -0
- cnb/contributors.py +72 -0
- cnb/exceptions.py +21 -0
- cnb/followers.py +50 -0
- cnb/git.py +441 -0
- cnb/gitsettings.py +158 -0
- cnb/issues.py +233 -0
- cnb/missions.py +23 -0
- cnb/models/__init__.py +0 -0
- cnb/models/api.py +393 -0
- cnb/models/chart.py +43 -0
- cnb/models/constant.py +85 -0
- cnb/models/convert.py +13 -0
- cnb/models/die.py +19 -0
- cnb/models/dto.py +1523 -0
- cnb/models/git_woa_com_cnb_monorepo_git_internal_app_git_service_bff_api.py +14 -0
- cnb/models/git_woa_com_cnb_monorepo_git_internal_app_git_service_bff_web.py +14 -0
- cnb/models/git_woa_com_cnb_monorepo_git_internal_app_vcs_service_bff_api.py +13 -0
- cnb/models/git_woa_com_cnb_monorepo_git_internal_dto_web.py +14 -0
- cnb/models/git_woa_com_cnb_monorepo_mission_mission_resource_dto_web.py +13 -0
- cnb/models/handler.py +83 -0
- cnb/models/http.py +20 -0
- cnb/models/identity.py +19 -0
- cnb/models/label.py +15 -0
- cnb/models/map_constant.py +11 -0
- cnb/models/models.py +50 -0
- cnb/models/openapi.py +64 -0
- cnb/models/organization.py +16 -0
- cnb/models/organizations.py +18 -0
- cnb/models/scope.py +28 -0
- cnb/models/v1.py +26 -0
- cnb/models/web.py +1045 -0
- cnb/models/webapi.py +162 -0
- cnb/models/wechat.py +25 -0
- cnb/organizations.py +192 -0
- cnb/pulls.py +242 -0
- cnb/releases.py +170 -0
- cnb/repocontributor.py +31 -0
- cnb/repolabels.py +75 -0
- cnb/repositories.py +243 -0
- cnb/starring.py +58 -0
- cnb/users.py +73 -0
- cnb/workspace.py +66 -0
- python_cnb-0.1.0.dist-info/METADATA +102 -0
- python_cnb-0.1.0.dist-info/RECORD +54 -0
- python_cnb-0.1.0.dist-info/WHEEL +5 -0
- python_cnb-0.1.0.dist-info/licenses/LICENSE +20 -0
- python_cnb-0.1.0.dist-info/top_level.txt +1 -0
cnb/__init__.py
ADDED
cnb/artifactory.py
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# Code generated by cnb.cool/cnb/sdk/cnb-sdk-generator. DO NOT EDIT.
|
|
2
|
+
# versions:
|
|
3
|
+
# cnb-sdk-generator: 1.0.2
|
|
4
|
+
# source: https://api.cnb.cool/swagger.json
|
|
5
|
+
|
|
6
|
+
from typing import Optional
|
|
7
|
+
from .models import dto
|
|
8
|
+
class ArtifactoryService:
|
|
9
|
+
def __init__(self, client):
|
|
10
|
+
self._client = client
|
|
11
|
+
|
|
12
|
+
# 删除制品标签。 Delete the specific tag under specific package
|
|
13
|
+
def delete_package_tag(self,
|
|
14
|
+
slug: str,
|
|
15
|
+
t: str,
|
|
16
|
+
name: str,
|
|
17
|
+
tag: str,
|
|
18
|
+
):
|
|
19
|
+
u = "/%s/-/packages/%s/%s/-/tag/%s" % (slug, t, name, tag, )
|
|
20
|
+
|
|
21
|
+
data = self._client.request(
|
|
22
|
+
method="DELETE",
|
|
23
|
+
endpoint=u,
|
|
24
|
+
)
|
|
25
|
+
return
|
|
26
|
+
|
|
27
|
+
# 删除制品仓库。Delete the artifact repository.
|
|
28
|
+
def delete_registry(self,
|
|
29
|
+
registry: str,
|
|
30
|
+
):
|
|
31
|
+
u = "/%s" % (registry, )
|
|
32
|
+
|
|
33
|
+
data = self._client.request(
|
|
34
|
+
method="DELETE",
|
|
35
|
+
endpoint=u,
|
|
36
|
+
)
|
|
37
|
+
return
|
|
38
|
+
|
|
39
|
+
# 下载制品配额信息。 Download registry quota details.
|
|
40
|
+
def download_quotas_by_project_name(self,
|
|
41
|
+
slug: str,
|
|
42
|
+
t: str,
|
|
43
|
+
page: Optional[int] = None,
|
|
44
|
+
page_size: Optional[int] = None,
|
|
45
|
+
ordering: Optional[str] = None,
|
|
46
|
+
) -> list[dto.QuotaRsp]:
|
|
47
|
+
u = "/%s/-/packages/%s/-/quotas/download" % (slug, t, )
|
|
48
|
+
|
|
49
|
+
query_params = {
|
|
50
|
+
"page": page,
|
|
51
|
+
"page_size": page_size,
|
|
52
|
+
"ordering": ordering,
|
|
53
|
+
}
|
|
54
|
+
data = self._client.request(
|
|
55
|
+
method="GET",
|
|
56
|
+
endpoint=u,
|
|
57
|
+
params=query_params,
|
|
58
|
+
)
|
|
59
|
+
return [dto.QuotaRsp.safe_parse(item) for item in data]
|
|
60
|
+
|
|
61
|
+
# 获取某一制品的详细信息。 Get the package detail.
|
|
62
|
+
def get_package(self,
|
|
63
|
+
slug: str,
|
|
64
|
+
t: str,
|
|
65
|
+
name: str,
|
|
66
|
+
) -> dto.PackageDetail:
|
|
67
|
+
u = "/%s/-/packages/%s/%s" % (slug, t, name, )
|
|
68
|
+
|
|
69
|
+
data = self._client.request(
|
|
70
|
+
method="GET",
|
|
71
|
+
endpoint=u,
|
|
72
|
+
)
|
|
73
|
+
return dto.PackageDetail.safe_parse(data)
|
|
74
|
+
|
|
75
|
+
# 获取制品标签详情。 Get the specific tag under specific package.
|
|
76
|
+
def get_package_tag_detail(self,
|
|
77
|
+
slug: str,
|
|
78
|
+
t: str,
|
|
79
|
+
name: str,
|
|
80
|
+
tag: str,
|
|
81
|
+
sha256: Optional[str] = None,
|
|
82
|
+
) -> dto.TagDetail:
|
|
83
|
+
u = "/%s/-/packages/%s/%s/-/tag/%s" % (slug, t, name, tag, )
|
|
84
|
+
|
|
85
|
+
query_params = {
|
|
86
|
+
"sha256": sha256,
|
|
87
|
+
}
|
|
88
|
+
data = self._client.request(
|
|
89
|
+
method="GET",
|
|
90
|
+
endpoint=u,
|
|
91
|
+
params=query_params,
|
|
92
|
+
)
|
|
93
|
+
return dto.TagDetail.safe_parse(data)
|
|
94
|
+
|
|
95
|
+
# 查询制品配额。 Get quota of specific registry.
|
|
96
|
+
def get_quota_by_project_name(self,
|
|
97
|
+
slug: str,
|
|
98
|
+
t: str,
|
|
99
|
+
) -> dto.QuotaRsp:
|
|
100
|
+
u = "/%s/-/packages/%s/-/quota" % (slug, t, )
|
|
101
|
+
|
|
102
|
+
data = self._client.request(
|
|
103
|
+
method="GET",
|
|
104
|
+
endpoint=u,
|
|
105
|
+
)
|
|
106
|
+
return dto.QuotaRsp.safe_parse(data)
|
|
107
|
+
|
|
108
|
+
# 查询全部制品配额。 Get quotas of packages under one registry.
|
|
109
|
+
def get_quotas_by_project_name(self,
|
|
110
|
+
slug: str,
|
|
111
|
+
t: str,
|
|
112
|
+
page: Optional[int] = None,
|
|
113
|
+
page_size: Optional[int] = None,
|
|
114
|
+
ordering: Optional[str] = None,
|
|
115
|
+
) -> list[dto.QuotaRsp]:
|
|
116
|
+
u = "/%s/-/packages/%s/-/quotas" % (slug, t, )
|
|
117
|
+
|
|
118
|
+
query_params = {
|
|
119
|
+
"page": page,
|
|
120
|
+
"page_size": page_size,
|
|
121
|
+
"ordering": ordering,
|
|
122
|
+
}
|
|
123
|
+
data = self._client.request(
|
|
124
|
+
method="GET",
|
|
125
|
+
endpoint=u,
|
|
126
|
+
params=query_params,
|
|
127
|
+
)
|
|
128
|
+
return [dto.QuotaRsp.safe_parse(item) for item in data]
|
|
129
|
+
|
|
130
|
+
# 查询制品数量。 Head all packages.
|
|
131
|
+
def head_packages(self,
|
|
132
|
+
slug: str,
|
|
133
|
+
type: Optional[str] = None,
|
|
134
|
+
page: Optional[int] = None,
|
|
135
|
+
page_size: Optional[int] = None,
|
|
136
|
+
ordering: Optional[str] = None,
|
|
137
|
+
name: Optional[str] = None,
|
|
138
|
+
):
|
|
139
|
+
u = "/%s/-/packages" % (slug, )
|
|
140
|
+
|
|
141
|
+
query_params = {
|
|
142
|
+
"type": type,
|
|
143
|
+
"page": page,
|
|
144
|
+
"page_size": page_size,
|
|
145
|
+
"ordering": ordering,
|
|
146
|
+
"name": name,
|
|
147
|
+
}
|
|
148
|
+
data = self._client.request(
|
|
149
|
+
method="HEAD",
|
|
150
|
+
endpoint=u,
|
|
151
|
+
params=query_params,
|
|
152
|
+
)
|
|
153
|
+
return
|
|
154
|
+
|
|
155
|
+
# 查询制品标签列表。 List all tags under specific package.
|
|
156
|
+
def list_package_tags(self,
|
|
157
|
+
slug: str,
|
|
158
|
+
t: str,
|
|
159
|
+
pkgname: str,
|
|
160
|
+
page: Optional[int] = None,
|
|
161
|
+
page_size: Optional[int] = None,
|
|
162
|
+
ordering: Optional[str] = None,
|
|
163
|
+
name: Optional[str] = None,
|
|
164
|
+
) -> dto.Tag:
|
|
165
|
+
u = "/%s/-/packages/%s/%s/-/tags" % (slug, t, pkgname, )
|
|
166
|
+
|
|
167
|
+
query_params = {
|
|
168
|
+
"page": page,
|
|
169
|
+
"page_size": page_size,
|
|
170
|
+
"ordering": ordering,
|
|
171
|
+
"name": name,
|
|
172
|
+
}
|
|
173
|
+
data = self._client.request(
|
|
174
|
+
method="GET",
|
|
175
|
+
endpoint=u,
|
|
176
|
+
params=query_params,
|
|
177
|
+
)
|
|
178
|
+
return dto.Tag.safe_parse(data)
|
|
179
|
+
|
|
180
|
+
# 查询制品列表。 List all packages.
|
|
181
|
+
def list_packages(self,
|
|
182
|
+
slug: str,
|
|
183
|
+
type: Optional[str] = None,
|
|
184
|
+
page: Optional[int] = None,
|
|
185
|
+
page_size: Optional[int] = None,
|
|
186
|
+
ordering: Optional[str] = None,
|
|
187
|
+
name: Optional[str] = None,
|
|
188
|
+
) -> list[dto.Package]:
|
|
189
|
+
u = "/%s/-/packages" % (slug, )
|
|
190
|
+
|
|
191
|
+
query_params = {
|
|
192
|
+
"type": type,
|
|
193
|
+
"page": page,
|
|
194
|
+
"page_size": page_size,
|
|
195
|
+
"ordering": ordering,
|
|
196
|
+
"name": name,
|
|
197
|
+
}
|
|
198
|
+
data = self._client.request(
|
|
199
|
+
method="GET",
|
|
200
|
+
endpoint=u,
|
|
201
|
+
params=query_params,
|
|
202
|
+
)
|
|
203
|
+
return [dto.Package.safe_parse(item) for item in data]
|
|
204
|
+
|
|
205
|
+
|
cnb/assets.py
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# Code generated by cnb.cool/cnb/sdk/cnb-sdk-generator. DO NOT EDIT.
|
|
2
|
+
# versions:
|
|
3
|
+
# cnb-sdk-generator: 1.0.2
|
|
4
|
+
# source: https://api.cnb.cool/swagger.json
|
|
5
|
+
|
|
6
|
+
from typing import Optional
|
|
7
|
+
from .models import dto
|
|
8
|
+
class AssetsService:
|
|
9
|
+
def __init__(self, client):
|
|
10
|
+
self._client = client
|
|
11
|
+
|
|
12
|
+
# 发起一个获取 commits 附件的请求,返回内容或者 302 到某个地址。Get a request to fetch a commit assets and returns the content directly or a 302 redirect to the assets URL.
|
|
13
|
+
def get_commit_assets(self,
|
|
14
|
+
repo: str,
|
|
15
|
+
fileName: str,
|
|
16
|
+
):
|
|
17
|
+
u = "/%s/-/commit-assets/download/%s" % (repo, fileName, )
|
|
18
|
+
|
|
19
|
+
data = self._client.request(
|
|
20
|
+
method="GET",
|
|
21
|
+
endpoint=u,
|
|
22
|
+
)
|
|
23
|
+
return
|
|
24
|
+
|
|
25
|
+
# 发起一个获取 files 的请求,返回内容或者 302 到某个地址。Initiate a request to retrieve files, returns content or 302 redirect.
|
|
26
|
+
def get_files(self,
|
|
27
|
+
repo: str,
|
|
28
|
+
userIdKey: str,
|
|
29
|
+
randomUUID: str,
|
|
30
|
+
fileName: str,
|
|
31
|
+
):
|
|
32
|
+
u = "/%s/-/files/%s/%s/%s" % (repo, userIdKey, randomUUID, fileName, )
|
|
33
|
+
|
|
34
|
+
data = self._client.request(
|
|
35
|
+
method="GET",
|
|
36
|
+
endpoint=u,
|
|
37
|
+
)
|
|
38
|
+
return
|
|
39
|
+
|
|
40
|
+
# 发起一个获取 imgs 的请求,返回内容或者 302 到某个地址。Initiate a request to get images, returns content or 302 redirect.
|
|
41
|
+
def get_imgs(self,
|
|
42
|
+
repo: str,
|
|
43
|
+
userIdKey: str,
|
|
44
|
+
fileName: str,
|
|
45
|
+
):
|
|
46
|
+
u = "/%s/-/imgs/%s/%s" % (repo, userIdKey, fileName, )
|
|
47
|
+
|
|
48
|
+
data = self._client.request(
|
|
49
|
+
method="GET",
|
|
50
|
+
endpoint=u,
|
|
51
|
+
)
|
|
52
|
+
return
|
|
53
|
+
|
|
54
|
+
# 发起一个获取 latest release 附件的请求,返回内容或者 302 到某个地址。Initiate a request to get latest release attachments, returns content or 302 redirect.
|
|
55
|
+
def get_latest_releases_asset(self,
|
|
56
|
+
repo: str,
|
|
57
|
+
fileName: str,
|
|
58
|
+
):
|
|
59
|
+
u = "/%s/-/releases/latest/download/%s" % (repo, fileName, )
|
|
60
|
+
|
|
61
|
+
data = self._client.request(
|
|
62
|
+
method="GET",
|
|
63
|
+
endpoint=u,
|
|
64
|
+
)
|
|
65
|
+
return
|
|
66
|
+
|
|
67
|
+
# 发起一个获取 logo 的请求,返回内容或者 302 到某个地址。Post a request to fetch a logo and returns the content directly or a 302 redirect to the logo URL.
|
|
68
|
+
def get_logos(self,
|
|
69
|
+
group: str,
|
|
70
|
+
size: str,
|
|
71
|
+
):
|
|
72
|
+
u = "/%s/-/logos/%s" % (group, size, )
|
|
73
|
+
|
|
74
|
+
data = self._client.request(
|
|
75
|
+
method="GET",
|
|
76
|
+
endpoint=u,
|
|
77
|
+
)
|
|
78
|
+
return
|
|
79
|
+
|
|
80
|
+
# 发起一个获取 release 附件的请求,返回内容或者 302 到某个地址。Initiate a request to get release attachments, returns content or 302 redirect.
|
|
81
|
+
def get_releases_asset(self,
|
|
82
|
+
repo: str,
|
|
83
|
+
fileName: str,
|
|
84
|
+
):
|
|
85
|
+
u = "/%s/-/releases/download/%s" % (repo, fileName, )
|
|
86
|
+
|
|
87
|
+
data = self._client.request(
|
|
88
|
+
method="GET",
|
|
89
|
+
endpoint=u,
|
|
90
|
+
)
|
|
91
|
+
return
|
|
92
|
+
|
|
93
|
+
# 获取指定用户的用户头像。Get the user's avatar.
|
|
94
|
+
def get_user_avatar(self,
|
|
95
|
+
username: str,
|
|
96
|
+
size: str,
|
|
97
|
+
):
|
|
98
|
+
u = "/users/%s/avatar/%s" % (username, size, )
|
|
99
|
+
|
|
100
|
+
data = self._client.request(
|
|
101
|
+
method="GET",
|
|
102
|
+
endpoint=u,
|
|
103
|
+
)
|
|
104
|
+
return
|
|
105
|
+
|
|
106
|
+
# 发起一个确认 files 的请求,上传的图片要调用此接口才能生效。Initiate a request to confirm files, uploaded images need to call this API to take effect.
|
|
107
|
+
def put_files(self,
|
|
108
|
+
repo: str,
|
|
109
|
+
userIdKey: str,
|
|
110
|
+
randomUUID: str,
|
|
111
|
+
fileName: str,
|
|
112
|
+
token: Optional[str] = None,
|
|
113
|
+
):
|
|
114
|
+
u = "/%s/-/files/%s/%s/%s" % (repo, userIdKey, randomUUID, fileName, )
|
|
115
|
+
|
|
116
|
+
query_params = {
|
|
117
|
+
"token": token,
|
|
118
|
+
}
|
|
119
|
+
data = self._client.request(
|
|
120
|
+
method="PUT",
|
|
121
|
+
endpoint=u,
|
|
122
|
+
params=query_params,
|
|
123
|
+
)
|
|
124
|
+
return
|
|
125
|
+
|
|
126
|
+
# 发起一个确认 imgs 的请求,上传的图片要调用此接口才能生效。Initiate a request to confirm images, uploaded images need to call this API to take effect.
|
|
127
|
+
def put_imgs(self,
|
|
128
|
+
repo: str,
|
|
129
|
+
userIdKey: str,
|
|
130
|
+
fileName: str,
|
|
131
|
+
token: Optional[str] = None,
|
|
132
|
+
):
|
|
133
|
+
u = "/%s/-/imgs/%s/%s" % (repo, userIdKey, fileName, )
|
|
134
|
+
|
|
135
|
+
query_params = {
|
|
136
|
+
"token": token,
|
|
137
|
+
}
|
|
138
|
+
data = self._client.request(
|
|
139
|
+
method="PUT",
|
|
140
|
+
endpoint=u,
|
|
141
|
+
params=query_params,
|
|
142
|
+
)
|
|
143
|
+
return
|
|
144
|
+
|
|
145
|
+
# 确认上传的logo。Confirms the uploaded logo.
|
|
146
|
+
def put_logos(self,
|
|
147
|
+
group: str,
|
|
148
|
+
token: Optional[str] = None,
|
|
149
|
+
):
|
|
150
|
+
u = "/%s/-/logos" % (group, )
|
|
151
|
+
|
|
152
|
+
query_params = {
|
|
153
|
+
"token": token,
|
|
154
|
+
}
|
|
155
|
+
data = self._client.request(
|
|
156
|
+
method="PUT",
|
|
157
|
+
endpoint=u,
|
|
158
|
+
params=query_params,
|
|
159
|
+
)
|
|
160
|
+
return
|
|
161
|
+
|
|
162
|
+
# 发起一个上传 files 的请求,返回上传 cos 的 url 和 form 内容。Initiate a request to upload files,returns COS upload URL and form data.
|
|
163
|
+
def upload_files(self,
|
|
164
|
+
repo: str,
|
|
165
|
+
body_params: dto.UploadRequestParams,
|
|
166
|
+
) -> dto.UploadAssetsResponse:
|
|
167
|
+
u = "/%s/-/upload/files" % (repo, )
|
|
168
|
+
|
|
169
|
+
data = self._client.request(
|
|
170
|
+
method="POST",
|
|
171
|
+
endpoint=u,
|
|
172
|
+
json=body_params.to_dict(),
|
|
173
|
+
)
|
|
174
|
+
return dto.UploadAssetsResponse.safe_parse(data)
|
|
175
|
+
|
|
176
|
+
# 发起一个上传 imgs 的请求,返回上传 cos 的 url 和 form 内容。发起一个上传 imgs 的请求,返回上传 cos 的 url 和 form 内容.
|
|
177
|
+
def upload_imgs(self,
|
|
178
|
+
repo: str,
|
|
179
|
+
body_params: dto.UploadRequestParams,
|
|
180
|
+
) -> dto.UploadAssetsResponse:
|
|
181
|
+
u = "/%s/-/upload/imgs" % (repo, )
|
|
182
|
+
|
|
183
|
+
data = self._client.request(
|
|
184
|
+
method="POST",
|
|
185
|
+
endpoint=u,
|
|
186
|
+
json=body_params.to_dict(),
|
|
187
|
+
)
|
|
188
|
+
return dto.UploadAssetsResponse.safe_parse(data)
|
|
189
|
+
|
|
190
|
+
# 发起一个上传 logo 的请求,返回上传 cos 的 url 和 form 内容。Post a request to upload a logo.
|
|
191
|
+
def upload_logos(self,
|
|
192
|
+
group: str,
|
|
193
|
+
body_params: dto.UploadRequestParams,
|
|
194
|
+
) -> dto.UploadAssetsResponse:
|
|
195
|
+
u = "/%s/-/upload/logos" % (group, )
|
|
196
|
+
|
|
197
|
+
data = self._client.request(
|
|
198
|
+
method="POST",
|
|
199
|
+
endpoint=u,
|
|
200
|
+
json=body_params.to_dict(),
|
|
201
|
+
)
|
|
202
|
+
return dto.UploadAssetsResponse.safe_parse(data)
|
|
203
|
+
|
|
204
|
+
# 发起一个上传 release 附件的请求,返回上传 cos 的 url 和 form 内容。Initiate a request to upload release attachments, returns COS upload URL and form data.
|
|
205
|
+
def upload_releases(self,
|
|
206
|
+
repo: str,
|
|
207
|
+
tagName: str,
|
|
208
|
+
body_params: dto.UploadRequestParams,
|
|
209
|
+
) -> dto.UploadAssetsResponse:
|
|
210
|
+
u = "/%s/-/upload/releases/%s" % (repo, tagName, )
|
|
211
|
+
|
|
212
|
+
data = self._client.request(
|
|
213
|
+
method="POST",
|
|
214
|
+
endpoint=u,
|
|
215
|
+
json=body_params.to_dict(),
|
|
216
|
+
)
|
|
217
|
+
return dto.UploadAssetsResponse.safe_parse(data)
|
|
218
|
+
|
|
219
|
+
|
cnb/build.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Code generated by cnb.cool/cnb/sdk/cnb-sdk-generator. DO NOT EDIT.
|
|
2
|
+
# versions:
|
|
3
|
+
# cnb-sdk-generator: 1.0.2
|
|
4
|
+
# source: https://api.cnb.cool/swagger.json
|
|
5
|
+
|
|
6
|
+
from typing import Optional
|
|
7
|
+
from .models import dto
|
|
8
|
+
class BuildService:
|
|
9
|
+
def __init__(self, client):
|
|
10
|
+
self._client = client
|
|
11
|
+
|
|
12
|
+
# 查询流水线构建列表。List pipeline builds.
|
|
13
|
+
def get_build_logs(self,
|
|
14
|
+
repo: str,
|
|
15
|
+
createTime: Optional[str] = None,
|
|
16
|
+
endTime: Optional[str] = None,
|
|
17
|
+
event: Optional[str] = None,
|
|
18
|
+
page: Optional[int] = None,
|
|
19
|
+
pagesize: Optional[int] = None,
|
|
20
|
+
sha: Optional[str] = None,
|
|
21
|
+
sn: Optional[str] = None,
|
|
22
|
+
sourceRef: Optional[str] = None,
|
|
23
|
+
status: Optional[str] = None,
|
|
24
|
+
targetRef: Optional[str] = None,
|
|
25
|
+
userId: Optional[str] = None,
|
|
26
|
+
userName: Optional[str] = None,
|
|
27
|
+
) -> dto.BuildLogsResult:
|
|
28
|
+
u = "/%s/-/build/logs" % (repo, )
|
|
29
|
+
|
|
30
|
+
query_params = {
|
|
31
|
+
"createTime": createTime,
|
|
32
|
+
"endTime": endTime,
|
|
33
|
+
"event": event,
|
|
34
|
+
"page": page,
|
|
35
|
+
"pagesize": pagesize,
|
|
36
|
+
"sha": sha,
|
|
37
|
+
"sn": sn,
|
|
38
|
+
"sourceRef": sourceRef,
|
|
39
|
+
"status": status,
|
|
40
|
+
"targetRef": targetRef,
|
|
41
|
+
"userId": userId,
|
|
42
|
+
"userName": userName,
|
|
43
|
+
}
|
|
44
|
+
data = self._client.request(
|
|
45
|
+
method="GET",
|
|
46
|
+
endpoint=u,
|
|
47
|
+
params=query_params,
|
|
48
|
+
)
|
|
49
|
+
return dto.BuildLogsResult.safe_parse(data)
|
|
50
|
+
|
|
51
|
+
# 查询流水线构建状态。Get pipeline build status.
|
|
52
|
+
def get_build_status(self,
|
|
53
|
+
repo: str,
|
|
54
|
+
sn: str,
|
|
55
|
+
) -> dto.BuildStatusResult:
|
|
56
|
+
u = "/%s/-/build/status/%s" % (repo, sn, )
|
|
57
|
+
|
|
58
|
+
data = self._client.request(
|
|
59
|
+
method="GET",
|
|
60
|
+
endpoint=u,
|
|
61
|
+
)
|
|
62
|
+
return dto.BuildStatusResult.safe_parse(data)
|
|
63
|
+
|
|
64
|
+
# 开始一个构建。Start a build.
|
|
65
|
+
def start_build(self,
|
|
66
|
+
repo: str,
|
|
67
|
+
body_params: dto.StartBuildReq,
|
|
68
|
+
) -> list[dto.BuildResult]:
|
|
69
|
+
u = "/%s/-/build/start" % (repo, )
|
|
70
|
+
|
|
71
|
+
data = self._client.request(
|
|
72
|
+
method="POST",
|
|
73
|
+
endpoint=u,
|
|
74
|
+
json=body_params.to_dict(),
|
|
75
|
+
)
|
|
76
|
+
return [dto.BuildResult.safe_parse(item) for item in data]
|
|
77
|
+
|
|
78
|
+
# 停止一个构建。 Stop a build.
|
|
79
|
+
def stop_build(self,
|
|
80
|
+
repo: str,
|
|
81
|
+
sn: str,
|
|
82
|
+
) -> list[dto.BuildResult]:
|
|
83
|
+
u = "/%s/-/build/stop/%s" % (repo, sn, )
|
|
84
|
+
|
|
85
|
+
data = self._client.request(
|
|
86
|
+
method="POST",
|
|
87
|
+
endpoint=u,
|
|
88
|
+
)
|
|
89
|
+
return [dto.BuildResult.safe_parse(item) for item in data]
|
|
90
|
+
|
|
91
|
+
|
cnb/client.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
from typing import Any, Dict, Optional
|
|
3
|
+
from .exceptions import CNBAPIError
|
|
4
|
+
from .cnb import CNBServices
|
|
5
|
+
|
|
6
|
+
class CNBClient():
|
|
7
|
+
"""CNB OpenAPI 客户端"""
|
|
8
|
+
|
|
9
|
+
def __init__(
|
|
10
|
+
self,
|
|
11
|
+
base_url: str = "https://api.cnb.cool",
|
|
12
|
+
api_key: Optional[str] = None,
|
|
13
|
+
timeout: int = 30,
|
|
14
|
+
max_retries: int = 3,
|
|
15
|
+
):
|
|
16
|
+
"""
|
|
17
|
+
初始化客户端
|
|
18
|
+
|
|
19
|
+
:param base_url: API基础URL
|
|
20
|
+
:param api_key: API密钥
|
|
21
|
+
:param timeout: 请求超时时间(秒)
|
|
22
|
+
:param max_retries: 最大重试次数
|
|
23
|
+
"""
|
|
24
|
+
self.base_url = base_url.rstrip('/')
|
|
25
|
+
self.api_key = api_key
|
|
26
|
+
self.timeout = timeout
|
|
27
|
+
self.max_retries = max_retries
|
|
28
|
+
self.session = requests.Session()
|
|
29
|
+
|
|
30
|
+
# 配置默认请求头
|
|
31
|
+
self.session.headers.update({
|
|
32
|
+
"Accept": "application/vnd.cnb.api+json",
|
|
33
|
+
"Content-Type": "application/json",
|
|
34
|
+
"User-Agent": "python-cnb/1.0"
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
if api_key:
|
|
38
|
+
self.session.headers["Authorization"] = f"Bearer {api_key}"
|
|
39
|
+
|
|
40
|
+
self.cnb = CNBServices(self)
|
|
41
|
+
|
|
42
|
+
def request(
|
|
43
|
+
self,
|
|
44
|
+
method: str,
|
|
45
|
+
endpoint: str,
|
|
46
|
+
**kwargs
|
|
47
|
+
) -> Dict[str, Any]:
|
|
48
|
+
"""
|
|
49
|
+
发送API请求
|
|
50
|
+
|
|
51
|
+
:param method: HTTP方法(GET, POST等)
|
|
52
|
+
:param endpoint: API端点路径
|
|
53
|
+
:param kwargs: 其他请求参数
|
|
54
|
+
:return: 响应数据
|
|
55
|
+
:raises: CNBAPIError 当API请求失败时
|
|
56
|
+
"""
|
|
57
|
+
url = f"{self.base_url}/{endpoint.lstrip('/')}"
|
|
58
|
+
|
|
59
|
+
# 设置默认超时
|
|
60
|
+
if 'timeout' not in kwargs:
|
|
61
|
+
kwargs['timeout'] = self.timeout
|
|
62
|
+
|
|
63
|
+
try:
|
|
64
|
+
response = self.session.request(
|
|
65
|
+
method,
|
|
66
|
+
url,
|
|
67
|
+
**kwargs
|
|
68
|
+
)
|
|
69
|
+
response.raise_for_status()
|
|
70
|
+
return response.json()
|
|
71
|
+
|
|
72
|
+
except requests.exceptions.HTTPError as e:
|
|
73
|
+
status_code = e.response.status_code
|
|
74
|
+
raise CNBAPIError(
|
|
75
|
+
detail=e.response.text,
|
|
76
|
+
status_code=status_code
|
|
77
|
+
) from e
|
|
78
|
+
except requests.exceptions.RequestException as e:
|
|
79
|
+
raise CNBAPIError(f"Request failed: {str(e)}") from e
|
cnb/cnb.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Code generated by cnb.cool/cnb/sdk/cnb-sdk-generator. DO NOT EDIT.
|
|
2
|
+
# versions:
|
|
3
|
+
# cnb-sdk-generator: 1.0.2
|
|
4
|
+
# source: https://api.cnb.cool/swagger.json
|
|
5
|
+
from .artifactory import ArtifactoryService
|
|
6
|
+
from .assets import AssetsService
|
|
7
|
+
from .build import BuildService
|
|
8
|
+
from .collaborators import CollaboratorsService
|
|
9
|
+
from .contributors import ContributorsService
|
|
10
|
+
from .followers import FollowersService
|
|
11
|
+
from .git import GitService
|
|
12
|
+
from .gitsettings import GitsettingsService
|
|
13
|
+
from .issues import IssuesService
|
|
14
|
+
from .missions import MissionsService
|
|
15
|
+
from .organizations import OrganizationsService
|
|
16
|
+
from .pulls import PullsService
|
|
17
|
+
from .releases import ReleasesService
|
|
18
|
+
from .repocontributor import RepocontributorService
|
|
19
|
+
from .repolabels import RepolabelsService
|
|
20
|
+
from .repositories import RepositoriesService
|
|
21
|
+
from .starring import StarringService
|
|
22
|
+
from .users import UsersService
|
|
23
|
+
from .workspace import WorkspaceService
|
|
24
|
+
|
|
25
|
+
class CNBServices:
|
|
26
|
+
def __init__(self, client):
|
|
27
|
+
self.client = client
|
|
28
|
+
self.artifactory = ArtifactoryService(client)
|
|
29
|
+
self.assets = AssetsService(client)
|
|
30
|
+
self.build = BuildService(client)
|
|
31
|
+
self.collaborators = CollaboratorsService(client)
|
|
32
|
+
self.contributors = ContributorsService(client)
|
|
33
|
+
self.followers = FollowersService(client)
|
|
34
|
+
self.git = GitService(client)
|
|
35
|
+
self.gitsettings = GitsettingsService(client)
|
|
36
|
+
self.issues = IssuesService(client)
|
|
37
|
+
self.missions = MissionsService(client)
|
|
38
|
+
self.organizations = OrganizationsService(client)
|
|
39
|
+
self.pulls = PullsService(client)
|
|
40
|
+
self.releases = ReleasesService(client)
|
|
41
|
+
self.repocontributor = RepocontributorService(client)
|
|
42
|
+
self.repolabels = RepolabelsService(client)
|
|
43
|
+
self.repositories = RepositoriesService(client)
|
|
44
|
+
self.starring = StarringService(client)
|
|
45
|
+
self.users = UsersService(client)
|
|
46
|
+
self.workspace = WorkspaceService(client)
|