|
11 | 11 | from py_trees.display import render_dot_tree, unicode_tree |
12 | 12 |
|
13 | 13 | from .bht.conversation_state import InboxMessage |
14 | | -from .bht.conversation_tree import ( |
15 | | - create_conversation_root_node, |
16 | | - initialize_conversation_tree, |
17 | | -) |
| 14 | +from .bht.conversation_tree import initialize_conversation_tree |
18 | 15 | from .bht.tree import TreeInspector, async_tick_tock, initialize_tree_and_state |
19 | 16 | from .config import load_config |
20 | 17 | from .conversation_models import ConversationArgs, InboxMessage |
21 | | - |
22 | | -# from .github_app_auth import GitHubAppAuth, load_private_key_from_file |
23 | 18 | from .github_client_async import GitHubClientAsync |
24 | 19 | from .logging_config import setup_logging |
25 | 20 | from .models import ReleaseArgs, ReleaseType, SlackArgs |
@@ -356,115 +351,5 @@ def slack_bot( |
356 | 351 | ) |
357 | 352 |
|
358 | 353 |
|
359 | | -@app.command() |
360 | | -def test_github_app( |
361 | | - github_app_id: str = typer.Option(..., "--github-app-id", help="GitHub App ID"), |
362 | | - github_private_key_file: str = typer.Option( |
363 | | - ..., "--github-private-key-file", help="Path to GitHub App private key file" |
364 | | - ), |
365 | | - repo: str = typer.Option( |
366 | | - "redis/docker-library-redis", |
367 | | - "--repo", |
368 | | - help="Repository to test (default: redis/docker-library-redis)", |
369 | | - ), |
370 | | - workflow_file: str = typer.Option( |
371 | | - "release_build_and_test.yml", |
372 | | - "--workflow-file", |
373 | | - help="Workflow file to dispatch (default: release_build_and_test.yml)", |
374 | | - ), |
375 | | - workflow_ref: str = typer.Option( |
376 | | - "main", "--workflow-ref", help="Git ref to run workflow on (default: main)" |
377 | | - ), |
378 | | - workflow_inputs: Optional[str] = typer.Option( |
379 | | - None, |
380 | | - "--workflow-inputs", |
381 | | - help='Workflow inputs as JSON string (e.g., \'{"key": "value"}\')', |
382 | | - ), |
383 | | -) -> None: |
384 | | - """[TEST] Test GitHub App authentication and workflow dispatch. |
385 | | -
|
386 | | - This command tests GitHub App authentication by: |
387 | | - 1. Loading the private key from file |
388 | | - 2. Generating a JWT token |
389 | | - 3. Getting an installation token for the specified repository |
390 | | - 4. Dispatching a workflow using the installation token |
391 | | -
|
392 | | - Example: |
393 | | - redis-release test-github-app \\ |
394 | | - --github-app-id 123456 \\ |
395 | | - --github-private-key-file /path/to/private-key.pem \\ |
396 | | - --repo redis/docker-library-redis \\ |
397 | | - --workflow-file release_build_and_test.yml \\ |
398 | | - --workflow-ref main \\ |
399 | | - --workflow-inputs '{"release_tag": "8.4-m01-int1"}' |
400 | | - """ |
401 | | - setup_logging() |
402 | | - |
403 | | - try: |
404 | | - # Load private key |
405 | | - logger.info(f"Loading private key from {github_private_key_file}") |
406 | | - private_key = load_private_key_from_file(github_private_key_file) |
407 | | - logger.info("[green]Private key loaded successfully[/green]") |
408 | | - |
409 | | - # Create GitHub App auth helper |
410 | | - app_auth = GitHubAppAuth(app_id=github_app_id, private_key=private_key) |
411 | | - |
412 | | - # Get installation token |
413 | | - logger.info(f"Getting installation token for repo: {repo}") |
414 | | - |
415 | | - async def get_token_and_dispatch() -> None: |
416 | | - token = await app_auth.get_token_for_repo(repo) |
417 | | - if not token: |
418 | | - logger.error("[red]Failed to get installation token[/red]") |
419 | | - raise typer.Exit(1) |
420 | | - |
421 | | - logger.info("[green]Successfully obtained installation token[/green]") |
422 | | - logger.info(f"Token (first 20 chars): {token[:20]}...") |
423 | | - |
424 | | - # Parse workflow inputs |
425 | | - inputs = {} |
426 | | - if workflow_inputs: |
427 | | - try: |
428 | | - inputs = json.loads(workflow_inputs) |
429 | | - logger.info(f"Workflow inputs: {inputs}") |
430 | | - except json.JSONDecodeError as e: |
431 | | - logger.error(f"[red]Invalid JSON in workflow inputs:[/red] {e}") |
432 | | - raise typer.Exit(1) |
433 | | - |
434 | | - # Create GitHub client with the installation token |
435 | | - github_client = GitHubClientAsync(token=token) |
436 | | - |
437 | | - # Dispatch workflow |
438 | | - logger.info( |
439 | | - f"Dispatching workflow {workflow_file} on {repo} at ref {workflow_ref}" |
440 | | - ) |
441 | | - try: |
442 | | - await github_client.trigger_workflow( |
443 | | - repo=repo, |
444 | | - workflow_file=workflow_file, |
445 | | - inputs=inputs, |
446 | | - ref=workflow_ref, |
447 | | - ) |
448 | | - logger.info("[green]Workflow dispatched successfully![/green]") |
449 | | - logger.info( |
450 | | - f"Check workflow runs at: https://github.com/{repo}/actions" |
451 | | - ) |
452 | | - except Exception as e: |
453 | | - logger.error(f"[red]Failed to dispatch workflow:[/red] {e}") |
454 | | - raise typer.Exit(1) |
455 | | - |
456 | | - # Run async function |
457 | | - asyncio.run(get_token_and_dispatch()) |
458 | | - |
459 | | - except FileNotFoundError: |
460 | | - logger.error( |
461 | | - f"[red]Private key file not found:[/red] {github_private_key_file}" |
462 | | - ) |
463 | | - raise typer.Exit(1) |
464 | | - except Exception as e: |
465 | | - logger.error(f"[red]Unexpected error:[/red] {e}", exc_info=True) |
466 | | - raise typer.Exit(1) |
467 | | - |
468 | | - |
469 | 354 | if __name__ == "__main__": |
470 | 355 | app() |
0 commit comments