-
-
Notifications
You must be signed in to change notification settings - Fork 18
Add GitHub notifications namespace #477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| """GitHub notification models""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Any, Dict | ||
|
|
||
| from .base import GitHubDataModelBase | ||
| from .repository import GitHubRepositoryModel | ||
|
|
||
|
|
||
| class _Subject(GitHubDataModelBase): | ||
| """Notification subject.""" | ||
|
|
||
| title: str | None = None | ||
| url: str | None = None | ||
| latest_comment_url: str | None = None | ||
| type: str | None = None | ||
|
|
||
|
|
||
| class GitHubNotificationModel(GitHubDataModelBase): | ||
| """ | ||
| GitHub notification data class. | ||
|
|
||
| https://docs.github.com/en/rest/activity/notifications | ||
| """ | ||
|
|
||
| id: str | None = None | ||
| repository: GitHubRepositoryModel | None = None | ||
| subject: _Subject | None = None | ||
| reason: str | None = None | ||
| unread: bool | None = None | ||
| updated_at: str | None = None | ||
| last_read_at: str | None = None | ||
| url: str | None = None | ||
| subscription_url: str | None = None | ||
|
|
||
| def _generate_repository(self, data: Dict[str, Any] | None) -> GitHubRepositoryModel: | ||
| """Generate repository data.""" | ||
| return GitHubRepositoryModel(data) if data else None | ||
|
|
||
| def _generate_subject(self, data: Dict[str, Any] | None) -> _Subject: | ||
| """Generate subject data.""" | ||
| return _Subject(data) if data else None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| """ | ||
| Methods for the notifications namespace | ||
|
|
||
| https://docs.github.com/en/rest/activity/notifications | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| from ..const import GitHubRequestKwarg | ||
| from ..models.notification import GitHubNotificationModel | ||
| from ..models.response import GitHubResponseModel | ||
| from .base import BaseNamespace | ||
|
|
||
|
|
||
| class GitHubNotificationsNamespace(BaseNamespace): | ||
| """Methods for the notifications namespace""" | ||
|
|
||
| async def list( | ||
| self, | ||
| *, | ||
| all: bool = False, | ||
| participating: bool = False, | ||
| since: str | None = None, | ||
| before: str | None = None, | ||
| page: int = 1, | ||
| per_page: int = 50, | ||
| params: dict[str, str] | None = None, | ||
| **kwargs: Any, | ||
| ) -> GitHubResponseModel[list[GitHubNotificationModel]]: | ||
| """ | ||
| List notifications for the authenticated user | ||
|
|
||
| https://docs.github.com/en/rest/activity/notifications#list-notifications-for-the-authenticated-user | ||
| """ | ||
| request_params = {} | ||
| if all: | ||
| request_params["all"] = "true" | ||
| if participating: | ||
| request_params["participating"] = "true" | ||
| if since: | ||
| request_params["since"] = since | ||
| if before: | ||
| request_params["before"] = before | ||
| if page != 1: | ||
| request_params["page"] = str(page) | ||
| if per_page != 50: | ||
| request_params["per_page"] = str(per_page) | ||
| if params: | ||
| request_params.update(params) | ||
|
|
||
| response = await self._client.async_call_api( | ||
| endpoint="/notifications", | ||
| params=request_params, | ||
| **kwargs, | ||
| ) | ||
| response.data = [GitHubNotificationModel(data) for data in response.data] | ||
| return response | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| [ | ||
| { | ||
| "id": "1", | ||
| "repository": { | ||
| "id": 1296269, | ||
| "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", | ||
| "name": "Hello-World", | ||
| "full_name": "octocat/Hello-World", | ||
| "owner": { | ||
| "login": "octocat", | ||
| "id": 1, | ||
| "node_id": "MDQ6VXNlcjE=", | ||
| "avatar_url": "https://github.com/images/error/octocat_happy.gif", | ||
| "gravatar_id": "", | ||
| "url": "https://api.github.com/users/octocat", | ||
| "html_url": "https://github.com/octocat", | ||
| "type": "User", | ||
| "site_admin": false | ||
| }, | ||
| "private": false, | ||
| "html_url": "https://github.com/octocat/Hello-World", | ||
| "description": "This your first repo!", | ||
| "fork": false, | ||
| "url": "https://api.github.com/repos/octocat/Hello-World" | ||
| }, | ||
| "subject": { | ||
| "title": "Greetings", | ||
| "url": "https://api.github.com/repos/octokit/octokit.rb/issues/123", | ||
| "latest_comment_url": "https://api.github.com/repos/octokit/octokit.rb/issues/comments/123", | ||
| "type": "Issue" | ||
| }, | ||
| "reason": "subscribed", | ||
| "unread": true, | ||
| "updated_at": "2014-11-07T22:01:45Z", | ||
| "last_read_at": "2014-11-07T22:01:45Z", | ||
| "url": "https://api.github.com/notifications/threads/1", | ||
| "subscription_url": "https://api.github.com/notifications/threads/1/subscription" | ||
| } | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| """Test notifications namespace.""" | ||
| # pylint: disable=missing-docstring | ||
| import pytest | ||
|
|
||
| from aiogithubapi import GitHubAPI | ||
| from aiogithubapi.models.notification import GitHubNotificationModel | ||
|
|
||
| from tests.common import ( | ||
| MockedRequests, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_list_notifications(github_api: GitHubAPI, mock_requests: MockedRequests): | ||
| response = await github_api.notifications.list() | ||
| assert response.status == 200 | ||
| assert isinstance(response.data, list) | ||
| assert len(response.data) == 1 | ||
| assert isinstance(response.data[0], GitHubNotificationModel) | ||
| assert response.data[0].id == "1" | ||
| assert response.data[0].subject.title == "Greetings" | ||
| assert response.data[0].reason == "subscribed" | ||
| assert response.data[0].unread is True | ||
| assert mock_requests.called == 1 | ||
| assert mock_requests.last_request["url"] == "https://api.github.com/notifications" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.