fix(resolver): Allow using github.token in Actions and fix base_domain handling (#7934)

This commit is contained in:
Tei1988 2025-04-19 05:50:59 +09:00 committed by GitHub
parent 0e0f043e59
commit 523c6d03c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 11 additions and 3 deletions

View File

@ -584,6 +584,12 @@ def main() -> None:
parser = argparse.ArgumentParser(
description='Send a pull request to Github or Gitlab.'
)
parser.add_argument(
'--selected-repo',
type=str,
default=None,
help='repository to send pull request in form of `owner/repo`.',
)
parser.add_argument(
'--token',
type=str,
@ -677,7 +683,7 @@ def main() -> None:
)
username = my_args.username if my_args.username else os.getenv('GIT_USERNAME')
platform = identify_token(token, None, my_args.base_domain)
platform = identify_token(token, my_args.selected_repo, my_args.base_domain)
if platform == Platform.INVALID:
raise ValueError('Token is invalid.')

View File

@ -21,7 +21,7 @@ class Platform(Enum):
def identify_token(
token: str, selected_repo: str | None = None, base_domain: str = 'github.com'
token: str, selected_repo: str | None = None, base_domain: str | None = 'github.com'
) -> Platform:
"""
Identifies whether a token belongs to GitHub or GitLab.
@ -37,7 +37,7 @@ def identify_token(
"Invalid" if the token is not recognized by either.
"""
# Determine GitHub API base URL based on domain
if base_domain == 'github.com':
if base_domain is None or base_domain == 'github.com':
github_api_base = 'https://api.github.com'
else:
github_api_base = f'https://{base_domain}/api/v3'

View File

@ -1249,6 +1249,7 @@ def test_main(
mock_args.target_branch = None
mock_args.reviewer = None
mock_args.pr_title = None
mock_args.selected_repo = None
mock_parser.return_value.parse_args.return_value = mock_args
# Setup environment variables

View File

@ -1151,6 +1151,7 @@ def test_main(
mock_args.target_branch = None
mock_args.reviewer = None
mock_args.pr_title = None
mock_args.selected_repo = None
mock_parser.return_value.parse_args.return_value = mock_args
# Setup environment variables