python-gitea 0.3.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.
gitea/issue/issue.py ADDED
@@ -0,0 +1,277 @@
1
+ """Gitea Issue resource."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from datetime import datetime
6
+ from typing import Any, Literal, cast
7
+
8
+ from requests import Response
9
+
10
+ from gitea.issue.base import BaseIssue
11
+ from gitea.resource.resource import Resource
12
+ from gitea.utils.response import process_response
13
+
14
+
15
+ class Issue(BaseIssue, Resource):
16
+ """Gitea Issue resource."""
17
+
18
+ def _list_issues( # noqa: PLR0913
19
+ self,
20
+ owner: str,
21
+ repository: str,
22
+ state: Literal["closed", "open", "all"] | None = None,
23
+ labels: list[str] | None = None,
24
+ search_string: str | None = None,
25
+ issue_type: Literal["issues", "pulls"] | None = None,
26
+ milestones: list[str] | list[int] | None = None,
27
+ since: datetime | None = None,
28
+ before: datetime | None = None,
29
+ created_by: str | None = None,
30
+ assigned_by: str | None = None,
31
+ mentioned_by: str | None = None,
32
+ page: int | None = None,
33
+ limit: int | None = None,
34
+ **kwargs: Any,
35
+ ) -> Response:
36
+ """List issues in a repository.
37
+
38
+ Args:
39
+ owner: The owner of the repository.
40
+ repository: The name of the repository.
41
+ state: Filter issues by state.
42
+ labels: Filter issues by labels.
43
+ search_string: Filter issues by search string.
44
+ issue_type: Filter by issue type.
45
+ milestones: Filter issues by milestones.
46
+ since: Filter issues updated since this time.
47
+ before: Filter issues updated before this time.
48
+ created_by: Filter issues created by this user.
49
+ assigned_by: Filter issues assigned to this user.
50
+ mentioned_by: Filter issues mentioning this user.
51
+ page: The page number for pagination.
52
+ limit: The number of issues per page.
53
+ **kwargs: Additional arguments for the request.
54
+
55
+ Returns:
56
+ The HTTP response object.
57
+
58
+ """
59
+ endpoint, params = self._list_issues_helper(
60
+ owner=owner,
61
+ repository=repository,
62
+ state=state,
63
+ labels=labels,
64
+ search_string=search_string,
65
+ issue_type=issue_type,
66
+ milestones=milestones,
67
+ since=since,
68
+ before=before,
69
+ created_by=created_by,
70
+ assigned_by=assigned_by,
71
+ mentioned_by=mentioned_by,
72
+ page=page,
73
+ limit=limit,
74
+ )
75
+ return self._get(endpoint=endpoint, params=params, **kwargs)
76
+
77
+ def list_issues( # noqa: PLR0913
78
+ self,
79
+ owner: str,
80
+ repository: str,
81
+ state: Literal["closed", "open", "all"] | None = None,
82
+ labels: list[str] | None = None,
83
+ search_string: str | None = None,
84
+ issue_type: Literal["issues", "pulls"] | None = None,
85
+ milestones: list[str] | list[int] | None = None,
86
+ since: datetime | None = None,
87
+ before: datetime | None = None,
88
+ created_by: str | None = None,
89
+ assigned_by: str | None = None,
90
+ mentioned_by: str | None = None,
91
+ page: int | None = None,
92
+ limit: int | None = None,
93
+ **kwargs: Any,
94
+ ) -> tuple[list[dict[str, Any]], int]:
95
+ """List issues in a repository.
96
+
97
+ Args:
98
+ owner: The owner of the repository.
99
+ repository: The name of the repository.
100
+ state: Filter issues by state.
101
+ labels: Filter issues by labels.
102
+ search_string: Filter issues by search string.
103
+ issue_type: Filter by issue type.
104
+ milestones: Filter issues by milestones.
105
+ since: Filter issues updated since this time.
106
+ before: Filter issues updated before this time.
107
+ created_by: Filter issues created by this user.
108
+ assigned_by: Filter issues assigned to this user.
109
+ mentioned_by: Filter issues mentioning this user.
110
+ page: The page number for pagination.
111
+ limit: The number of issues per page.
112
+ **kwargs: Additional arguments for the request.
113
+
114
+ Returns:
115
+ A tuple containing the list of issues as a list of dictionaries and the status code.
116
+
117
+ """
118
+ response = self._list_issues(
119
+ owner=owner,
120
+ repository=repository,
121
+ state=state,
122
+ labels=labels,
123
+ search_string=search_string,
124
+ issue_type=issue_type,
125
+ milestones=milestones,
126
+ since=since,
127
+ before=before,
128
+ created_by=created_by,
129
+ assigned_by=assigned_by,
130
+ mentioned_by=mentioned_by,
131
+ page=page,
132
+ limit=limit,
133
+ **kwargs,
134
+ )
135
+ data, status_code = process_response(response)
136
+ return cast(list[dict[str, Any]], data), status_code
137
+
138
+ def _get_issue(self, owner: str, repository: str, index: int, **kwargs: Any) -> Response:
139
+ """Get a single issue by its index.
140
+
141
+ Args:
142
+ owner: The owner of the repository.
143
+ repository: The name of the repository.
144
+ index: The index of the issue.
145
+ **kwargs: Additional arguments for the request.
146
+
147
+ Returns:
148
+ The HTTP response object.
149
+
150
+ """
151
+ endpoint = self._get_issue_helper(owner=owner, repository=repository, index=index)
152
+ return self._get(endpoint=endpoint, **kwargs)
153
+
154
+ def get_issue(self, owner: str, repository: str, index: int, **kwargs: Any) -> tuple[dict[str, Any], int]:
155
+ """Get a single issue by its index.
156
+
157
+ Args:
158
+ owner: The owner of the repository.
159
+ repository: The name of the repository.
160
+ index: The index of the issue.
161
+ **kwargs: Additional arguments for the request.
162
+
163
+ Returns:
164
+ A tuple containing the issue as a dictionary and the status code.
165
+
166
+ """
167
+ response = self._get_issue(owner=owner, repository=repository, index=index, **kwargs)
168
+ data, status_code = process_response(response)
169
+ return cast(dict[str, Any], data), status_code
170
+
171
+ def _edit_issue( # noqa: PLR0913
172
+ self,
173
+ owner: str,
174
+ repository: str,
175
+ index: int,
176
+ assignee: str | None = None,
177
+ assignees: list[str] | None = None,
178
+ body: str | None = None,
179
+ due_date: datetime | None = None,
180
+ milestone: int | None = None,
181
+ ref: str | None = None,
182
+ state: Literal["closed", "open"] | None = None,
183
+ title: str | None = None,
184
+ unset_due_date: bool | None = None,
185
+ **kwargs: Any,
186
+ ) -> Response:
187
+ """Edit a specific issue in a repository.
188
+
189
+ Args:
190
+ owner: The owner of the repository.
191
+ repository: The name of the repository.
192
+ index: The index of the issue.
193
+ assignee: The new assignee of the issue.
194
+ assignees: The new assignees of the issue.
195
+ body: The new body of the issue.
196
+ due_date: The new due date of the issue.
197
+ milestone: The new milestone of the issue.
198
+ ref: The new reference of the issue.
199
+ state: The new state of the issue.
200
+ title: The new title of the issue.
201
+ unset_due_date: Whether to unset the due date of the issue.
202
+ **kwargs: Additional arguments for the request.
203
+
204
+ Returns:
205
+ The HTTP response object.
206
+
207
+ """
208
+ endpoint, payload = self._edit_issue_helper(
209
+ owner=owner,
210
+ repository=repository,
211
+ index=index,
212
+ assignee=assignee,
213
+ assignees=assignees,
214
+ body=body,
215
+ due_date=due_date,
216
+ milestone=milestone,
217
+ ref=ref,
218
+ state=state,
219
+ title=title,
220
+ unset_due_date=unset_due_date,
221
+ )
222
+ return self._patch(endpoint=endpoint, json=payload, **kwargs)
223
+
224
+ def edit_issue( # noqa: PLR0913
225
+ self,
226
+ owner: str,
227
+ repository: str,
228
+ index: int,
229
+ assignee: str | None = None,
230
+ assignees: list[str] | None = None,
231
+ body: str | None = None,
232
+ due_date: datetime | None = None,
233
+ milestone: int | None = None,
234
+ ref: str | None = None,
235
+ state: Literal["closed", "open"] | None = None,
236
+ title: str | None = None,
237
+ unset_due_date: bool | None = None,
238
+ **kwargs: Any,
239
+ ) -> tuple[dict[str, Any], int]:
240
+ """Edit a specific issue in a repository.
241
+
242
+ Args:
243
+ owner: The owner of the repository.
244
+ repository: The name of the repository.
245
+ index: The index of the issue.
246
+ assignee: The new assignee of the issue.
247
+ assignees: The new assignees of the issue.
248
+ body: The new body of the issue.
249
+ due_date: The new due date of the issue.
250
+ milestone: The new milestone of the issue.
251
+ ref: The new reference of the issue.
252
+ state: The new state of the issue.
253
+ title: The new title of the issue.
254
+ unset_due_date: Whether to unset the due date of the issue.
255
+ **kwargs: Additional arguments for the request.
256
+
257
+ Returns:
258
+ A tuple containing the edited issue as a dictionary and the status code.
259
+
260
+ """
261
+ response = self._edit_issue(
262
+ owner=owner,
263
+ repository=repository,
264
+ index=index,
265
+ assignee=assignee,
266
+ assignees=assignees,
267
+ body=body,
268
+ due_date=due_date,
269
+ milestone=milestone,
270
+ ref=ref,
271
+ state=state,
272
+ title=title,
273
+ unset_due_date=unset_due_date,
274
+ **kwargs,
275
+ )
276
+ data, status_code = process_response(response)
277
+ return cast(dict[str, Any], data), status_code
@@ -0,0 +1 @@
1
+ """Resource module for Gitea API."""
@@ -0,0 +1,87 @@
1
+ """Asynchronous Resource Base Class for Gitea API interactions."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ from aiohttp import ClientResponse
8
+
9
+ from gitea.client.async_gitea import AsyncGitea
10
+
11
+
12
+ class AsyncResource:
13
+ """Base class for asynchronous Gitea API resources."""
14
+
15
+ def __init__(self, client: AsyncGitea) -> None:
16
+ """Initialize the Resource with a AsyncGitea client.
17
+
18
+ Args:
19
+ client: An instance of the AsyncGitea client.
20
+
21
+ """
22
+ self.client = client
23
+
24
+ async def _get(self, endpoint: str, **kwargs: Any) -> ClientResponse:
25
+ """Perform a GET request.
26
+
27
+ Args:
28
+ endpoint: The API endpoint.
29
+ **kwargs: Additional arguments for the request.
30
+
31
+ Returns:
32
+ The response as a ClientResponse object.
33
+
34
+ """
35
+ return await self.client._request(method="GET", endpoint=endpoint, **kwargs)
36
+
37
+ async def _post(self, endpoint: str, **kwargs: Any) -> ClientResponse:
38
+ """Perform a POST request.
39
+
40
+ Args:
41
+ endpoint: The API endpoint.
42
+ **kwargs: Additional arguments for the request.
43
+
44
+ Returns:
45
+ The response as a ClientResponse object.
46
+
47
+ """
48
+ return await self.client._request(method="POST", endpoint=endpoint, **kwargs)
49
+
50
+ async def _put(self, endpoint: str, **kwargs: Any) -> ClientResponse:
51
+ """Perform a PUT request.
52
+
53
+ Args:
54
+ endpoint: The API endpoint.
55
+ **kwargs: Additional arguments for the request.
56
+
57
+ Returns:
58
+ The response as a ClientResponse object.
59
+
60
+ """
61
+ return await self.client._request(method="PUT", endpoint=endpoint, **kwargs)
62
+
63
+ async def _delete(self, endpoint: str, **kwargs: Any) -> ClientResponse:
64
+ """Perform a DELETE request.
65
+
66
+ Args:
67
+ endpoint: The API endpoint.
68
+ **kwargs: Additional arguments for the request.
69
+
70
+ Returns:
71
+ The response as a ClientResponse object.
72
+
73
+ """
74
+ return await self.client._request(method="DELETE", endpoint=endpoint, **kwargs)
75
+
76
+ async def _patch(self, endpoint: str, **kwargs: Any) -> ClientResponse:
77
+ """Perform a PATCH request.
78
+
79
+ Args:
80
+ endpoint: The API endpoint.
81
+ **kwargs: Additional arguments for the request.
82
+
83
+ Returns:
84
+ The response as a ClientResponse object.
85
+
86
+ """
87
+ return await self.client._request(method="PATCH", endpoint=endpoint, **kwargs)
@@ -0,0 +1,88 @@
1
+ """Base class for Gitea API resources."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TYPE_CHECKING, Any
6
+
7
+ from requests import Response
8
+
9
+ if TYPE_CHECKING:
10
+ from gitea.client.gitea import Gitea
11
+
12
+
13
+ class Resource:
14
+ """Base class for Gitea API resources."""
15
+
16
+ def __init__(self, client: Gitea) -> None:
17
+ """Initialize the Resource with a Gitea client.
18
+
19
+ Args:
20
+ client: An instance of the Gitea client.
21
+
22
+ """
23
+ self.client = client
24
+
25
+ def _get(self, endpoint: str, **kwargs: Any) -> Response:
26
+ """Perform a GET request.
27
+
28
+ Args:
29
+ endpoint: The API endpoint.
30
+ **kwargs: Additional arguments for the request.
31
+
32
+ Returns:
33
+ The HTTP response.
34
+
35
+ """
36
+ return self.client._request(method="GET", endpoint=endpoint, **kwargs)
37
+
38
+ def _post(self, endpoint: str, **kwargs: Any) -> Response:
39
+ """Perform a POST request.
40
+
41
+ Args:
42
+ endpoint: The API endpoint.
43
+ **kwargs: Additional arguments for the request.
44
+
45
+ Returns:
46
+ The HTTP response.
47
+
48
+ """
49
+ return self.client._request(method="POST", endpoint=endpoint, **kwargs)
50
+
51
+ def _put(self, endpoint: str, **kwargs: Any) -> Response:
52
+ """Perform a PUT request.
53
+
54
+ Args:
55
+ endpoint: The API endpoint.
56
+ **kwargs: Additional arguments for the request.
57
+
58
+ Returns:
59
+ The HTTP response.
60
+
61
+ """
62
+ return self.client._request(method="PUT", endpoint=endpoint, **kwargs)
63
+
64
+ def _delete(self, endpoint: str, **kwargs: Any) -> Response:
65
+ """Perform a DELETE request.
66
+
67
+ Args:
68
+ endpoint: The API endpoint.
69
+ **kwargs: Additional arguments for the request.
70
+
71
+ Returns:
72
+ The HTTP response.
73
+
74
+ """
75
+ return self.client._request(method="DELETE", endpoint=endpoint, **kwargs)
76
+
77
+ def _patch(self, endpoint: str, **kwargs: Any) -> Response:
78
+ """Perform a PATCH request.
79
+
80
+ Args:
81
+ endpoint: The API endpoint.
82
+ **kwargs: Additional arguments for the request.
83
+
84
+ Returns:
85
+ The HTTP response.
86
+
87
+ """
88
+ return self.client._request(method="PATCH", endpoint=endpoint, **kwargs)
gitea/user/__init__.py ADDED
@@ -0,0 +1 @@
1
+ """User module for Gitea API."""
@@ -0,0 +1,129 @@
1
+ """Asynchronous User Resource for Gitea API."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, cast
6
+
7
+ from aiohttp import ClientResponse
8
+
9
+ from gitea.resource.async_resource import AsyncResource
10
+ from gitea.user.base import BaseUser
11
+ from gitea.utils.response import process_async_response
12
+
13
+
14
+ class AsyncUser(BaseUser, AsyncResource):
15
+ """Asynchronous Gitea User resource."""
16
+
17
+ async def _get_user(self, username: str | None = None, **kwargs: Any) -> ClientResponse:
18
+ """Asynchronously get user information.
19
+
20
+ Args:
21
+ username: The username of the user to retrieve. If None, retrieves the authenticated user.
22
+ **kwargs: Additional arguments for the request.
23
+
24
+ Returns:
25
+ The authenticated user's information as a ClientResponse object.
26
+
27
+ """
28
+ endpoint, kwargs = self._get_user_helper(username=username, **kwargs)
29
+ return await self._get(endpoint=endpoint, **kwargs)
30
+
31
+ async def get_user(self, username: str | None = None, **kwargs: Any) -> tuple[dict[str, Any], int]:
32
+ """Asynchronously get user information.
33
+
34
+ Args:
35
+ username: The username of the user to retrieve. If None, retrieves the authenticated user.
36
+ **kwargs: Additional arguments for the request.
37
+
38
+ Returns:
39
+ A tuple containing the user information as a dictionary and the status code.
40
+
41
+ """
42
+ response = await self._get_user(username=username, **kwargs)
43
+ data, status_code = await process_async_response(response)
44
+ return cast(dict[str, Any], data), status_code
45
+
46
+ async def _update_user_settings( # noqa: PLR0913
47
+ self,
48
+ diff_view_style: str | None = None,
49
+ full_name: str | None = None,
50
+ hide_activity: bool | None = None,
51
+ hide_email: bool | None = None,
52
+ language: str | None = None,
53
+ location: str | None = None,
54
+ theme: str | None = None,
55
+ website: str | None = None,
56
+ **kwargs: Any,
57
+ ) -> ClientResponse:
58
+ """Asynchronously update user settings.
59
+
60
+ Args:
61
+ diff_view_style: The preferred diff view style.
62
+ full_name: The full name of the user.
63
+ hide_activity: Whether to hide user activity.
64
+ hide_email: Whether to hide user email.
65
+ language: The preferred language.
66
+ location: The location of the user.
67
+ theme: The preferred theme.
68
+ website: The user's website.
69
+ **kwargs: Additional arguments for the request.
70
+
71
+ Returns:
72
+ The response as a ClientResponse object.
73
+
74
+ """
75
+ endpoint, payload, kwargs = self._update_user_settings_helper(
76
+ diff_view_style=diff_view_style,
77
+ full_name=full_name,
78
+ hide_activity=hide_activity,
79
+ hide_email=hide_email,
80
+ language=language,
81
+ location=location,
82
+ theme=theme,
83
+ website=website,
84
+ **kwargs,
85
+ )
86
+ return await self._patch(endpoint=endpoint, json=payload, **kwargs)
87
+
88
+ async def update_user_settings( # noqa: PLR0913
89
+ self,
90
+ diff_view_style: str | None = None,
91
+ full_name: str | None = None,
92
+ hide_activity: bool | None = None,
93
+ hide_email: bool | None = None,
94
+ language: str | None = None,
95
+ location: str | None = None,
96
+ theme: str | None = None,
97
+ website: str | None = None,
98
+ **kwargs: Any,
99
+ ) -> tuple[dict[str, Any], int]:
100
+ """Asynchronously update user settings.
101
+
102
+ Args:
103
+ diff_view_style: The preferred diff view style.
104
+ full_name: The full name of the user.
105
+ hide_activity: Whether to hide user activity.
106
+ hide_email: Whether to hide user email.
107
+ language: The preferred language.
108
+ location: The location of the user.
109
+ theme: The preferred theme.
110
+ website: The user's website.
111
+ **kwargs: Additional arguments for the request.
112
+
113
+ Returns:
114
+ A tuple containing the updated user settings as a dictionary and the status code.
115
+
116
+ """
117
+ response = await self._update_user_settings(
118
+ diff_view_style=diff_view_style,
119
+ full_name=full_name,
120
+ hide_activity=hide_activity,
121
+ hide_email=hide_email,
122
+ language=language,
123
+ location=location,
124
+ theme=theme,
125
+ website=website,
126
+ **kwargs,
127
+ )
128
+ data, status_code = await process_async_response(response)
129
+ return cast(dict[str, Any], data), status_code
gitea/user/base.py ADDED
@@ -0,0 +1,113 @@
1
+ """Base class for Gitea User resource."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+
8
+ class BaseUser:
9
+ """Base class for Gitea User resource."""
10
+
11
+ def _get_user_endpoint(self, username: str | None) -> str:
12
+ """Determine the user endpoint based on username or account ID.
13
+
14
+ Args:
15
+ username: The username of the user.
16
+
17
+ Returns:
18
+ The API endpoint for the user.
19
+
20
+ """
21
+ return "/user" if username is None else f"/users/{username}"
22
+
23
+ def _get_user_helper(self, username: str | None = None, **kwargs: Any) -> tuple[str, dict[str, Any]]:
24
+ """Get user information.
25
+
26
+ Args:
27
+ username: The username of the user to retrieve. If None, retrieves the authenticated user.
28
+ **kwargs: Additional arguments for the request.
29
+
30
+ Returns:
31
+ A tuple containing the endpoint and the request arguments.
32
+ - The API endpoint for the user.
33
+ - A dictionary of request arguments.
34
+
35
+ """
36
+ endpoint = self._get_user_endpoint(username=username)
37
+ default_headers = {
38
+ "Content-Type": "application/json",
39
+ }
40
+ headers = kwargs.get("headers", {})
41
+ headers = {**default_headers, **headers}
42
+ kwargs["headers"] = headers
43
+
44
+ return endpoint, kwargs
45
+
46
+ def _update_user_settings_endpoint(self) -> str:
47
+ """Get the endpoint for updating user settings.
48
+
49
+ Returns:
50
+ The API endpoint for updating user settings.
51
+
52
+ """
53
+ return "/user/settings"
54
+
55
+ def _update_user_settings_helper( # noqa: PLR0913
56
+ self,
57
+ diff_view_style: str | None = None,
58
+ full_name: str | None = None,
59
+ hide_activity: bool | None = None,
60
+ hide_email: bool | None = None,
61
+ language: str | None = None,
62
+ location: str | None = None,
63
+ theme: str | None = None,
64
+ website: str | None = None,
65
+ **kwargs: Any,
66
+ ) -> tuple[str, dict[str, Any], dict[str, Any]]:
67
+ """Get the endpoint and request arguments for updating user settings.
68
+
69
+ Args:
70
+ diff_view_style: The preferred diff view style.
71
+ full_name: The full name of the user.
72
+ hide_activity: Whether to hide the user's activity.
73
+ hide_email: Whether to hide the user's email.
74
+ language: The preferred language.
75
+ location: The location of the user.
76
+ theme: The preferred theme.
77
+ website: The user's website.
78
+ **kwargs: Additional arguments for the request.
79
+
80
+ Returns:
81
+ A tuple containing the endpoint, payload, and request arguments.
82
+ - The API endpoint for updating user settings.
83
+ - A dictionary representing the payload for the request.
84
+ - A dictionary of request arguments.
85
+
86
+ """
87
+ endpoint = self._update_user_settings_endpoint()
88
+ default_headers = {
89
+ "Content-Type": "application/json",
90
+ }
91
+ headers = kwargs.get("headers", {})
92
+ headers = {**default_headers, **headers}
93
+ kwargs["headers"] = headers
94
+
95
+ payload = {}
96
+ if diff_view_style is not None:
97
+ payload["diff_view_style"] = diff_view_style
98
+ if full_name is not None:
99
+ payload["full_name"] = full_name
100
+ if hide_activity is not None:
101
+ payload["hide_activity"] = hide_activity
102
+ if hide_email is not None:
103
+ payload["hide_email"] = hide_email
104
+ if language is not None:
105
+ payload["language"] = language
106
+ if location is not None:
107
+ payload["location"] = location
108
+ if theme is not None:
109
+ payload["theme"] = theme
110
+ if website is not None:
111
+ payload["website"] = website
112
+
113
+ return endpoint, payload, kwargs