Skip to content

πŸ™Œ OpenHands: AI-Driven Development

[Bugfix] Add github_token verification in resolver utils (#7065)

tawago6d75647c404e
diff --git a/openhands/resolver/resolve_issue.py b/openhands/resolver/resolve_issue.py
index a4116579a2..8443b361fd 100644
--- a/openhands/resolver/resolve_issue.py
+++ b/openhands/resolver/resolve_issue.py
@@ -651,7 +651,7 @@ def main() -> None:
if not token:
raise ValueError('Token is required.')
- platform = identify_token(token)
+ platform = identify_token(token, repo)
if platform == Platform.INVALID:
raise ValueError('Token is invalid.')
diff --git a/openhands/resolver/utils.py b/openhands/resolver/utils.py
index d08686d592..d12260a145 100644
--- a/openhands/resolver/utils.py
+++ b/openhands/resolver/utils.py
@@ -4,7 +4,7 @@ import multiprocessing as mp
import os
import re
from enum import Enum
-from typing import Callable
+from typing import Callable, Optional
import pandas as pd
import requests
@@ -22,18 +22,37 @@ class Platform(Enum):
GITLAB = 2
-def identify_token(token: str) -> Platform:
+def identify_token(token: str, repo: Optional[str] = None) -> Platform:
"""
Identifies whether a token belongs to GitHub or GitLab.
Parameters:
token (str): The personal access token to check.
+ repo (str): Repository in format "owner/repo" for GitHub Actions token validation.
Returns:
Platform: "GitHub" if the token is valid for GitHub,
"GitLab" if the token is valid for GitLab,
"Invalid" if the token is not recognized by either.
"""
+ # Try GitHub Actions token format (Bearer) with repo endpoint if repo is provided
+ if repo:
+ github_repo_url = f'https://api.github.com/repos/{repo}'
+ github_bearer_headers = {
+ 'Authorization': f'Bearer {token}',
+ 'Accept': 'application/vnd.github+json',
+ }
+
+ try:
+ github_repo_response = requests.get(
+ github_repo_url, headers=github_bearer_headers, timeout=5
+ )
+ if github_repo_response.status_code == 200:
+ return Platform.GITHUB
+ except requests.RequestException as e:
+ print(f'Error connecting to GitHub API (repo check): {e}')
+
+ # Try GitHub PAT format (token)
github_url = 'https://api.github.com/user'
github_headers = {'Authorization': f'token {token}'}
@@ -44,6 +63,7 @@ def identify_token(token: str) -> Platform:
except requests.RequestException as e:
print(f'Error connecting to GitHub API: {e}')
+ # Try GitLab token
gitlab_url = 'https://gitlab.com/api/v4/user'
gitlab_headers = {'Authorization': f'Bearer {token}'}