Skip to content

Commit 30a66e7

Browse files
tawagoadityasoni9998
authored andcommitted
[Bugfix] Add github_token verification in resolver utils (All-Hands-AI#7065)
1 parent d608708 commit 30a66e7

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

openhands/resolver/resolve_issue.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ def int_or_none(value: str) -> int | None:
651651
if not token:
652652
raise ValueError('Token is required.')
653653

654-
platform = identify_token(token)
654+
platform = identify_token(token, repo)
655655
if platform == Platform.INVALID:
656656
raise ValueError('Token is invalid.')
657657

openhands/resolver/utils.py

+22-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
import re
66
from enum import Enum
7-
from typing import Callable
7+
from typing import Callable, Optional
88

99
import pandas as pd
1010
import requests
@@ -22,18 +22,37 @@ class Platform(Enum):
2222
GITLAB = 2
2323

2424

25-
def identify_token(token: str) -> Platform:
25+
def identify_token(token: str, repo: Optional[str] = None) -> Platform:
2626
"""
2727
Identifies whether a token belongs to GitHub or GitLab.
2828
2929
Parameters:
3030
token (str): The personal access token to check.
31+
repo (str): Repository in format "owner/repo" for GitHub Actions token validation.
3132
3233
Returns:
3334
Platform: "GitHub" if the token is valid for GitHub,
3435
"GitLab" if the token is valid for GitLab,
3536
"Invalid" if the token is not recognized by either.
3637
"""
38+
# Try GitHub Actions token format (Bearer) with repo endpoint if repo is provided
39+
if repo:
40+
github_repo_url = f'https://api.github.com/repos/{repo}'
41+
github_bearer_headers = {
42+
'Authorization': f'Bearer {token}',
43+
'Accept': 'application/vnd.github+json',
44+
}
45+
46+
try:
47+
github_repo_response = requests.get(
48+
github_repo_url, headers=github_bearer_headers, timeout=5
49+
)
50+
if github_repo_response.status_code == 200:
51+
return Platform.GITHUB
52+
except requests.RequestException as e:
53+
print(f'Error connecting to GitHub API (repo check): {e}')
54+
55+
# Try GitHub PAT format (token)
3756
github_url = 'https://api.github.com/user'
3857
github_headers = {'Authorization': f'token {token}'}
3958

@@ -44,6 +63,7 @@ def identify_token(token: str) -> Platform:
4463
except requests.RequestException as e:
4564
print(f'Error connecting to GitHub API: {e}')
4665

66+
# Try GitLab token
4767
gitlab_url = 'https://gitlab.com/api/v4/user'
4868
gitlab_headers = {'Authorization': f'Bearer {token}'}
4969

0 commit comments

Comments
 (0)