Compare commits

...

1 Commits

Author SHA1 Message Date
openhands
4ea4fb2476 Fix GitHub API authorization headers to use Bearer consistently (issue #6032) 2025-03-17 15:40:56 +00:00
2 changed files with 34 additions and 2 deletions

View File

@@ -27,7 +27,7 @@ class GithubIssueHandler(IssueHandlerInterface):
def get_headers(self) -> dict[str, str]:
return {
'Authorization': f'token {self.token}',
'Authorization': f'Bearer {self.token}',
'Accept': 'application/vnd.github.v3+json',
}
@@ -450,7 +450,7 @@ class GithubPRHandler(GithubIssueHandler):
"""Download comments for a specific pull request from Github."""
url = f'https://api.github.com/repos/{self.owner}/{self.repo}/issues/{pr_number}/comments'
headers = {
'Authorization': f'token {self.token}',
'Authorization': f'Bearer {self.token}',
'Accept': 'application/vnd.github.v3+json',
}
params = {'per_page': 100, 'page': 1}

View File

@@ -643,3 +643,35 @@ def test_pr_handler_get_converted_issues_with_duplicate_issue_refs():
'External context #1.',
'External context #2.',
]
def test_authorization_header_format():
"""Test that the GitHub API is called with the correct authorization header format."""
with patch('requests.get') as mock_get:
# Mock the response
mock_response = MagicMock()
mock_response.json.return_value = []
mock_get.return_value = mock_response
# Create an instance of GithubIssueHandler
handler = GithubIssueHandler('test-owner', 'test-repo', 'test-token')
# Call a method that makes an API request
handler.download_issues()
# Verify that the request was made with the correct authorization header
headers = mock_get.call_args[1]['headers']
assert headers['Authorization'] == 'Bearer test-token'
# Reset the mock
mock_get.reset_mock()
# Create an instance of GithubPRHandler
pr_handler = GithubPRHandler('test-owner', 'test-repo', 'test-token')
# Call a method that makes an API request
pr_handler.download_issues()
# Verify that the request was made with the correct authorization header
headers = mock_get.call_args[1]['headers']
assert headers['Authorization'] == 'Bearer test-token'