-
Notifications
You must be signed in to change notification settings - Fork 415
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
fix: GitHub repos unique constraint and delete #4037
fix: GitHub repos unique constraint and delete #4037
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Uffizzi Preview |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #4037 +/- ##
=======================================
Coverage 96.41% 96.41%
=======================================
Files 1145 1146 +1
Lines 37295 37373 +78
=======================================
+ Hits 35959 36035 +76
- Misses 1336 1338 +2 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good, but left a number of nits. There is one change I think you should address which is the url__contains
bit since it would bleed data.
api/conftest.py
Outdated
def post_request_mock(mocker: MockerFixture) -> MagicMock: | ||
def mocked_request(*args, **kwargs): | ||
class MockResponse: | ||
def __init__(self, json_data, status_code): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing typing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
api/conftest.py
Outdated
@@ -85,6 +87,25 @@ def pytest_sessionstart(session: pytest.Session) -> None: | |||
fix_issue_3869() | |||
|
|||
|
|||
@pytest.fixture() | |||
def post_request_mock(mocker: MockerFixture) -> MagicMock: | |||
def mocked_request(*args, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing typing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
api/conftest.py
Outdated
def raise_for_status(self) -> None: | ||
pass | ||
|
||
def json(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing typing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
api/integrations/github/github.py
Outdated
@@ -25,6 +26,21 @@ | |||
logger = logging.getLogger(__name__) | |||
|
|||
|
|||
def handle_installation_deleted(payload: dict[str, typing.Any]) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Any
has already been imported from typing
so this should be like the below
def handle_installation_deleted(payload: dict[str, typing.Any]) -> None: | |
def handle_installation_deleted(payload: dict[str, Any]) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
api/integrations/github/github.py
Outdated
installation_id = payload.get("installation", {}).get("id") | ||
try: | ||
GithubConfiguration.objects.get(installation_id=installation_id).delete() | ||
except GithubConfiguration.DoesNotExist: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
installation_id
could be None
which may match the queryset if there are installation_id
matching records with None
in them. I would add an explicit check for installation_id is None
and handle that case separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
api/integrations/github/github.py
Outdated
GithubConfiguration.objects.get(installation_id=installation_id).delete() | ||
except GithubConfiguration.DoesNotExist: | ||
logger.error( | ||
f"Github Configuration with installation_id {installation_id} does not exist" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
f"Github Configuration with installation_id {installation_id} does not exist" | |
f"GitHub Configuration with installation_id {installation_id} does not exist" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
api/integrations/github/models.py
Outdated
], | ||
# Filter by url containing the repository owner and name | ||
url__contains=f"{self.repository_owner}/{self.repository_name}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The match criteria isn't good enough. If a repository owner is named foo
it would also match to examplefoo
. you need to bound the region of the url__contains
so that you're always matching the right object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using regex instead of contains
@@ -639,6 +650,32 @@ def test_github_webhook_delete_installation( | |||
assert not GithubConfiguration.objects.filter(installation_id=1234567).exists() | |||
|
|||
|
|||
def test_github_webhook_with_non_existing_installation( | |||
github_configuration: GithubConfiguration, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
github_configuration: GithubConfiguration, | |
github_configuration: GitHubConfiguration, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this shouldn't be changed as it's the model name.
mocker_logger = mocker.patch("integrations.github.github.logger") | ||
|
||
# When | ||
client = APIClient() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use api_client
fixture
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
||
# Then | ||
mocker_logger.error.assert_called_once_with( | ||
"Github Configuration with installation_id 765432 does not exist" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
"Github Configuration with installation_id 765432 does not exist" | |
"GitHub Configuration with installation_id 765432 does not exist" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Thanks for submitting a PR! Please check the boxes below:
pre-commit
to check lintingdocs/
if required so people know about the feature!Changes
How did you test this code?