Skip to content

fix: remove secrets_ prefix from github token envvar key #605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/codegen/cli/auth/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
if git_token is None:
rich.print("\n[bold yellow]Warning:[/bold yellow] GitHub token not found")
rich.print("To enable full functionality, please set your GitHub token:")
rich.print(format_command("export SECRETS_GITHUB_TOKEN=<your-token>"))
rich.print(format_command("export GITHUB_TOKEN=<your-token>"))
rich.print("Or pass in as a parameter:")
rich.print(format_command("codegen init --token <your-token>"))

Expand All @@ -77,11 +77,11 @@

try:
if git_token is not None:
Github(login_or_token=git_token).get_repo(self.local_git.full_name)

Check failure on line 80 in src/codegen/cli/auth/session.py

View workflow job for this annotation

GitHub Actions / mypy

error: Argument 1 to "get_repo" of "Github" has incompatible type "str | None"; expected "int | str" [arg-type]
except BadCredentialsException:
rich.print(format_command(f"\n[bold red]Error:[/bold red] Invalid GitHub token={git_token} for repo={self.local_git.full_name}"))
rich.print("[white]Please provide a valid GitHub token for this repository.[/white]")
raise click.Abort()

def __str__(self) -> str:
return f"CodegenSession(user={self.config.repository.user_name}, repo={self.config.repository.repo_name})"

Check failure on line 87 in src/codegen/cli/auth/session.py

View workflow job for this annotation

GitHub Actions / mypy

error: "RepositoryConfig" has no attribute "repo_name" [attr-defined]
2 changes: 1 addition & 1 deletion src/codegen/configs/models/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
class SecretsConfig(BaseConfig):
"""Configuration for various API secrets and tokens.

Loads from environment variables with the SECRETS_ prefix.
Loads from environment variables.
Falls back to .env file for missing values.
"""

def __init__(self, prefix: str = "", *args, **kwargs) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider implementing a fallback mechanism in the SecretsConfig class to support a graceful transition. Here's a suggested approach:

def __init__(self, prefix: str = "", *args, **kwargs) -> None:
    super().__init__(prefix=prefix, *args, **kwargs)
    
    # Check for deprecated token format
    if self.github_token is None:
        deprecated_token = os.getenv("SECRETS_GITHUB_TOKEN")
        if deprecated_token:
            warnings.warn(
                "Using SECRETS_GITHUB_TOKEN is deprecated and will be removed in a future version. "
                "Please use GITHUB_TOKEN instead.",
                DeprecationWarning,
                stacklevel=2
            )
            self.github_token = deprecated_token

This would provide backward compatibility while encouraging migration to the new format.

super().__init__(prefix=prefix, *args, **kwargs)

Check failure on line 12 in src/codegen/configs/models/secrets.py

View workflow job for this annotation

GitHub Actions / mypy

error: "__init__" of "BaseConfig" gets multiple values for keyword argument "prefix" [misc]

github_token: str | None = None
openai_api_key: str | None = None
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/runner/clients/codebase_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"REPOSITORY_PATH": str(self.repo_config.repo_path),
}
if self.git_access_token is not None:
codebase_envs["SECRETS_GITHUB_TOKEN"] = self.git_access_token
codebase_envs["GITHUB_TOKEN"] = self.git_access_token

envs.update(codebase_envs)
return envs
Expand All @@ -40,5 +40,5 @@
if __name__ == "__main__":
test_config = RepoConfig.from_repo_path("/Users/caroljung/git/codegen/codegen-agi")
test_config.full_name = "codegen-sh/codegen-agi"
client = CodebaseClient(test_config, secrets.github_token)

Check failure on line 43 in src/codegen/runner/clients/codebase_client.py

View workflow job for this annotation

GitHub Actions / mypy

error: Module has no attribute "github_token" [attr-defined]
print(client.healthcheck())
4 changes: 2 additions & 2 deletions tests/integration/extension/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
@pytest.fixture
def client() -> LinearClient:
"""Create a Linear client for testing."""
token = os.getenv("SECRETS_GITHUB_TOKEN")
token = os.getenv("GITHUB_TOKEN")
if not token:
pytest.skip("SECRETS_GITHUB_TOKEN environment variable not set")
pytest.skip("GITHUB_TOKEN environment variable not set")
codebase = Codebase.from_repo("codegen-sh/Kevin-s-Adventure-Game")
return codebase

Check failure on line 19 in tests/integration/extension/test_github.py

View workflow job for this annotation

GitHub Actions / mypy

error: Incompatible return value type (got "Codebase[SourceFile[Any, Any, Any, Any, Any, Any], Directory[Any, Any, Any, Any, Any, Any, Any], Symbol[Any, Any], Class[Function[Decorator[Any, Any, Parameter[Any, Any]], CodeBlock[Any, Any], Parameter[Any, Any], Type[Any]], Decorator[Any, Any, Parameter[Any, Any]], CodeBlock[Any, Any], Parameter[Any, Any], Type[Any]], Function[Decorator[Any, Any, Parameter[Any, Any]], CodeBlock[Any, Any], Parameter[Any, Any], Type[Any]], Import[Any], Assignment[Any], Interface[Any, Any, Any, Any], TypeAlias[Any, Any], Parameter[Any, Any], CodeBlock[Any, Any]]", expected "LinearClient") [return-value]


def test_github_view_pr(client: LinearClient) -> None:
"""Test getting an issue from Linear."""
# Link to PR: https://github.com/codegen-sh/Kevin-s-Adventure-Game/pull/419
pr = view_pr(client, 419)

Check failure on line 25 in tests/integration/extension/test_github.py

View workflow job for this annotation

GitHub Actions / mypy

error: Argument 1 to "view_pr" has incompatible type "LinearClient"; expected "Codebase[SourceFile[Any, Any, Any, Any, Any, Any], Directory[Any, Any, Any, Any, Any, Any, Any], Symbol[Any, Any], Class[Function[Decorator[Any, Any, Parameter[Any, Any]], CodeBlock[Any, Any], Parameter[Any, Any], Type[Any]], Decorator[Any, Any, Parameter[Any, Any]], CodeBlock[Any, Any], Parameter[Any, Any], Type[Any]], Function[Decorator[Any, Any, Parameter[Any, Any]], CodeBlock[Any, Any], Parameter[Any, Any], Type[Any]], Import[Any], Assignment[Any], Interface[Any, Any, Any, Any], TypeAlias[Any, Any], Parameter[Any, Any], CodeBlock[Any, Any]]" [arg-type]
print(pr)
Loading