@@ -89,6 +89,7 @@ def make_cfapi_request(
8989def get_user_id (api_key : Optional [str ] = None ) -> Optional [str ]:
9090 """Retrieve the user's userid by making a request to the /cfapi/cli-get-user endpoint.
9191
92+ :param api_key: The API key to use. If None, uses get_codeflash_api_key().
9293 :return: The userid or None if the request fails.
9394 """
9495 if not api_key and not ensure_codeflash_api_key ():
@@ -119,75 +120,6 @@ def get_user_id(api_key: Optional[str] = None) -> Optional[str]:
119120 logger .error (f"Failed to look up your userid; is your CF API key valid? ({ response .reason } )" )
120121 return None
121122
122-
123- def validate_api_key (api_key : Optional [str ] = None ) -> None :
124- """Validate that the API key is valid by attempting to retrieve the user ID.
125-
126- Raises OSError if the API key is invalid or missing.
127-
128- :param api_key: The API key to validate. If None, uses get_codeflash_api_key().
129- :raises OSError: If the API key is invalid or missing.
130- """
131- # First check if API key exists
132- if not api_key :
133- api_key = get_codeflash_api_key ()
134-
135- def raise_os_error (msg : str ) -> None :
136- """Raise OSError with the given message."""
137- raise OSError (msg )
138-
139- # Make the request to validate the API key
140- try :
141- response = make_cfapi_request (
142- endpoint = "/cli-get-user" ,
143- method = "GET" ,
144- extra_headers = {"cli_version" : __version__ },
145- api_key = api_key ,
146- suppress_errors = True , # Don't log errors yet, we'll handle it below
147- )
148-
149- if response .status_code == 403 :
150- msg = (
151- "Invalid Codeflash API key. The API key you provided is not valid.\n "
152- "Please generate a new one at https://app.codeflash.ai/app/apikeys ,\n "
153- "then set it as a CODEFLASH_API_KEY environment variable.\n "
154- "For more information, refer to the documentation at "
155- "https://docs.codeflash.ai/getting-started/codeflash-github-actions#add-your-api-key-to-your-repository-secrets"
156- )
157- raise_os_error (msg )
158- elif response .status_code != 200 :
159- msg = (
160- f"Failed to validate API key with Codeflash API (status { response .status_code } ).\n "
161- "Please verify your API key is correct.\n "
162- "You can generate a new one at https://app.codeflash.ai/app/apikeys"
163- )
164- raise_os_error (msg )
165-
166- # Check for version updates
167- if response .status_code == 200 :
168- try :
169- resp_json = response .json ()
170- min_version = resp_json .get ("min_version" )
171- if min_version and version .parse (min_version ) > version .parse (__version__ ):
172- msg = "Your Codeflash CLI version is outdated. Please update to the latest version using `pip install --upgrade codeflash`."
173- raise_os_error (msg )
174- except (json .JSONDecodeError , KeyError , TypeError ):
175- # If response is not JSON or doesn't have min_version, that's okay
176- pass
177-
178- except OSError :
179- # Re-raise OSError as-is
180- raise
181- except Exception as e :
182- # Wrap other exceptions
183- msg = (
184- f"Failed to validate API key: { e } \n "
185- "Please verify your API key is correct.\n "
186- "You can generate a new one at https://app.codeflash.ai/app/apikeys"
187- )
188- raise OSError (msg ) from e
189-
190-
191123def suggest_changes (
192124 owner : str ,
193125 repo : str ,
0 commit comments