Skip to content
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: Solve delete GitHub integration issue #4622

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions api/integrations/github/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,20 @@ def post_comment_to_github(
def delete_github_installation(installation_id: str) -> requests.Response:
url = f"{GITHUB_API_URL}app/installations/{installation_id}"
headers = build_request_headers(installation_id, use_jwt=True)
response = requests.delete(url, headers=headers, timeout=GITHUB_API_CALLS_TIMEOUT)
response.raise_for_status()
return response
try:
response = requests.delete(
url, headers=headers, timeout=GITHUB_API_CALLS_TIMEOUT
)
response.raise_for_status()
return response
except HTTPError:
response_content = response.content.decode("utf-8")
error_data = json.loads(response_content)
if error_data.get("message") == "Not Found" and response.status_code == 404:
logger.info(
f"The GitHub application with the installation ID: {installation_id} was not found."
)
return response


def fetch_search_github_resource(
Expand Down
12 changes: 4 additions & 8 deletions api/tests/unit/integrations/github/test_unit_github_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def test_delete_github_configuration(


@responses.activate
def test_cannot_delete_github_configuration_when_delete_github_installation_response_was_404(
def test_can_delete_github_configuration_when_delete_github_installation_response_was_404(
admin_client_new: APIClient,
organisation: Organisation,
github_configuration: GithubConfiguration,
Expand All @@ -213,18 +213,14 @@ def test_cannot_delete_github_configuration_when_delete_github_installation_resp
method="DELETE",
url=f"{GITHUB_API_URL}app/installations/{github_configuration.installation_id}",
status=404,
json={"message": "not found"},
json={"message": "Not Found", "status": "404"},
)

# When
response = admin_client_new.delete(url)
# Then
assert response.status_code == status.HTTP_502_BAD_GATEWAY
assert (
response.json()["detail"]
== "Failed to delete GitHub Installation. Error: 404 Client Error: Not Found for url: https://api.github.com/app/installations/1234567" # noqa: E501
)
assert GithubConfiguration.objects.filter(id=github_configuration.id).exists()
assert response.status_code == status.HTTP_204_NO_CONTENT
assert not GithubConfiguration.objects.filter(id=github_configuration.id).exists()


def test_get_github_repository(
Expand Down
Loading