fix invalid urls

This commit is contained in:
Enzo Nunes
2025-03-01 19:20:17 +00:00
parent 2e6a6f23c8
commit 7c38a708b4
2 changed files with 7 additions and 9 deletions

View File

@@ -73,21 +73,12 @@ def get_lines_of_code(owner, repository):
return number_of_lines_of_code return number_of_lines_of_code
def is_valid_repository(owner, repository, request_headers):
repository_url = f"https://api.github.com/repos/{owner}/{repository}"
repository_response = requests.get(repository_url, headers=request_headers)
return repository_response.status_code == 200
def PICable(owner, repository, token): def PICable(owner, repository, token):
margin_percentage = round(MARGIN * 100) margin_percentage = round(MARGIN * 100)
request_headers = {"Authorization": f"token {token}"} request_headers = {"Authorization": f"token {token}"}
picable_report = f"Analysis complete for the repository {owner}/{repository}.\n\n" picable_report = f"Analysis complete for the repository {owner}/{repository}.\n\n"
repository_url = f"https://www.github.com/{owner}/{repository}" repository_url = f"https://www.github.com/{owner}/{repository}"
if not is_valid_repository(owner, repository, request_headers):
return f"Invalid repository: {owner}/{repository} :x:"
stars = get_stars_info(owner, repository, request_headers) stars = get_stars_info(owner, repository, request_headers)
if stars == -1: if stars == -1:
return "Error fetching stars info. :x:" return "Error fetching stars info. :x:"

View File

@@ -69,6 +69,13 @@ async def picable(interaction: Interaction, owner: str, repository: str):
url = f"https://api.github.com/repos/{owner}/{repository}" url = f"https://api.github.com/repos/{owner}/{repository}"
headers = {"Authorization": f"token {github_token}"} headers = {"Authorization": f"token {github_token}"}
response = requests.get(url, headers=headers) response = requests.get(url, headers=headers)
if not response.status_code == 200:
await interaction.followup.send(
f"Invalid Repository. Please check the repository name and owner and try again. :x:"
)
return
response.raise_for_status() response.raise_for_status()
repo_info = response.json() repo_info = response.json()
repository_size_kb = repo_info["size"] repository_size_kb = repo_info["size"]