Skip to content

Commit 1884dc8

Browse files
committed
fix: Fixed issues not being listed
1 parent a8e9ade commit 1884dc8

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/linear_cli/api/auth/core.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66

77
import logging
8+
import os
89
from datetime import datetime, timedelta
910
from typing import Any
1011

@@ -64,7 +65,7 @@ def __init__(
6465
self._load_stored_credentials()
6566

6667
def _load_stored_credentials(self) -> None:
67-
"""Load credentials from secure storage."""
68+
"""Load credentials from secure storage or environment variable."""
6869
credentials = self.storage.retrieve_credentials()
6970
if credentials:
7071
self._access_token = credentials.get("access_token")
@@ -75,6 +76,18 @@ def _load_stored_credentials(self) -> None:
7576
self._token_expires_at = datetime.fromisoformat(expires_at)
7677

7778
logger.debug("Loaded stored credentials")
79+
else:
80+
# Check for API key in environment variable
81+
api_key = os.getenv("LINEAR_API_KEY")
82+
if api_key:
83+
# Validate the API key before using it
84+
if self._validate_api_key(api_key):
85+
self._access_token = api_key
86+
self._refresh_token = None
87+
self._token_expires_at = None # API keys don't expire
88+
logger.info("Loaded API key from LINEAR_API_KEY environment variable")
89+
else:
90+
logger.warning("Invalid API key found in LINEAR_API_KEY environment variable")
7891

7992
def _save_credentials(self) -> None:
8093
"""Save credentials to secure storage."""
@@ -161,7 +174,7 @@ def _validate_api_key(self, api_key: str) -> bool:
161174
# Validate by calling viewer query - minimal API call that confirms both authentication and basic API access
162175
query = "query { viewer { id name } }"
163176
headers = {
164-
"Authorization": f"Bearer {api_key}",
177+
"Authorization": api_key,
165178
"Content-Type": "application/json",
166179
}
167180
data = {"query": query}

src/linear_cli/api/client/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def _get_auth_headers(self) -> dict[str, str]:
7777
raise AuthenticationError("No valid access token available")
7878

7979
return {
80-
"Authorization": f"Bearer {token}",
80+
"Authorization": token,
8181
"Content-Type": "application/json",
8282
}
8383

@@ -351,7 +351,7 @@ async def get_issues(
351351
"first": limit,
352352
"after": after,
353353
"filter": issue_filter,
354-
"orderBy": {"field": order_by, "direction": "DESC"},
354+
"orderBy": order_by,
355355
}
356356

357357
result = await self.execute_query(GET_ISSUES_QUERY, variables)

0 commit comments

Comments
 (0)