Skip to content

Commit

Permalink
fix: Solve delete GitHub integration issue (#4622)
Browse files Browse the repository at this point in the history
  • Loading branch information
novakzaballa authored Sep 23, 2024
1 parent 37db0e0 commit b4d3310
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
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

0 comments on commit b4d3310

Please sign in to comment.