MCPcopy Create free account
hub / github.com/agenticsorg/edge-agents / handle_github_command

Function handle_github_command

scripts/agents/devops/src/cli.py:386–448  ·  view source on GitHub ↗

Handle GitHub-related commands.

(args)

Source from the content-addressed store, hash-verified

384
385
386def handle_github_command(args):
387 """Handle GitHub-related commands."""
388 try:
389 # Get GitHub credentials
390 cred_manager = get_credential_manager()
391 github_creds = cred_manager.get_github_credentials()
392
393 # Initialize GitHub service
394 github = GitHubService(token=github_creds.token)
395
396 if args.github_command == 'list-repos':
397 repos = github.list_repositories(org=args.org, user=args.user)
398
399 # Simplify repo data for output
400 simplified_repos = []
401 for repo in repos:
402 simplified_repos.append({
403 'Name': repo['name'],
404 'FullName': repo['full_name'],
405 'Description': repo.get('description', ''),
406 'DefaultBranch': repo['default_branch'],
407 'Stars': repo['stargazers_count'],
408 'Forks': repo['forks_count'],
409 'Language': repo.get('language', '')
410 })
411
412 if not simplified_repos:
413 print(f"{COLORS['yellow']}No repositories found.{COLORS['reset']}")
414 else:
415 print(format_output(simplified_repos, args.output))
416
417 elif args.github_command == 'get-repo':
418 repo = github.get_repository(args.repo, owner=args.owner)
419 print(format_output(repo, args.output))
420
421 elif args.github_command == 'get-readme':
422 readme = github.get_readme(args.repo, owner=args.owner, ref=args.ref)
423 if 'decoded_content' in readme:
424 print(readme['decoded_content'])
425 else:
426 print(format_output(readme, 'json'))
427
428 elif args.github_command == 'list-branches':
429 branches = github.list_branches(args.repo, owner=args.owner)
430
431 # Simplify branch data for output
432 simplified_branches = []
433 for branch in branches:
434 simplified_branches.append({
435 'Name': branch['name'],
436 'SHA': branch['commit']['sha'],
437 'Protected': branch.get('protected', False)
438 })
439
440 if not simplified_branches:
441 print(f"{COLORS['yellow']}No branches found.{COLORS['reset']}")
442 else:
443 print(format_output(simplified_branches, args.output))

Callers 1

mainFunction · 0.70

Calls 10

list_repositoriesMethod · 0.95
get_repositoryMethod · 0.95
get_readmeMethod · 0.95
list_branchesMethod · 0.95
get_credential_managerFunction · 0.85
GitHubServiceClass · 0.85
format_outputFunction · 0.70
handle_cli_errorFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected