Skip to content

Commit

Permalink
Check for dict
Browse files Browse the repository at this point in the history
  • Loading branch information
ImprintNav committed Jul 13, 2023
1 parent 2b8d260 commit 5d186db
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions tools/src/scie_pants/pants_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
import logging
import os
import urllib.parse
from typing import Any, Dict, List
from dataclasses import dataclass
from pathlib import Path
from subprocess import CalledProcessError
from typing import Callable, Iterator
from typing import Any, Callable, Dict, Iterator, List
from xml.etree import ElementTree

import tomlkit
Expand Down Expand Up @@ -43,9 +42,11 @@ def pants_find_links_option(self, pants_version_selected: Version) -> str:
)
return f"--python-repos-{option_name}={operator}['{self.find_links}']"


class TagNotFoundError(Exception):
pass


def determine_find_links(
ptex: Ptex,
pants_version: str,
Expand Down Expand Up @@ -120,7 +121,7 @@ def determine_tag_version(
github_api_url = (
f"https://api.github.com/repos/pantsbuild/pants/git/refs/tags/{urllib.parse.quote(tag)}"
)
github_releases_url="https://github.com/pantsbuild/pants/releases"
github_releases_url = "https://github.com/pantsbuild/pants/releases"
headers = (
{"Authorization": f"Bearer {github_api_bearer_token}"}
if github_api_bearer_token
Expand All @@ -129,9 +130,9 @@ def determine_tag_version(
github_api_response: Dict[str, Any]
try:
github_api_response = ptex.fetch_json(github_api_url, **headers)
# If the response is a list, multiple matches were found, which means the supplied tag
# is not an exact match against any tag
if isinstance(github_api_response, list):
# If the response is not a dict, it typically means multiple matches were found, which
# means the supplied tag is not an exact match against any tag
if not isinstance(github_api_response, dict):
raise TagNotFoundError(f"Could not find Pants tag {tag} in {github_releases_url}")
except CalledProcessError as e:
raise TagNotFoundError(f"Could not find Pants tag {tag} in {github_releases_url}: {e}")
Expand Down

0 comments on commit 5d186db

Please sign in to comment.