-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_token_owner.py
55 lines (42 loc) · 1.8 KB
/
test_token_owner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
"""
Test script to verify that private repositories are included when the token belongs to the user
"""
import asyncio
import os
import sys
from github_stats_analyzer.api import GitHubAPIClient
from github_stats_analyzer.logger import configure_logger
async def test_token_owner():
"""Test if the token belongs to the authenticated user and if private repositories are included"""
# Configure logger
configure_logger(True)
# Get username from command line or environment
username = sys.argv[1] if len(sys.argv) > 1 else os.getenv("GITHUB_USERNAME")
if not username:
print("Please provide a GitHub username as a command line argument or set GITHUB_USERNAME environment variable")
sys.exit(1)
# Create API client
api_client = GitHubAPIClient()
try:
# Check if the token belongs to the authenticated user
is_owner = await api_client.is_token_owner(username)
print(f"Token belongs to user {username}: {is_owner}")
# Get repositories
repos = await api_client.get_user_repos(username)
# Count private and public repositories
private_repos = [repo for repo in repos if repo.private]
public_repos = [repo for repo in repos if not repo.private]
print(f"Total repositories: {len(repos)}")
print(f"Private repositories: {len(private_repos)}")
print(f"Public repositories: {len(public_repos)}")
# Print private repository names if any
if private_repos:
print("\nPrivate repositories:")
for repo in private_repos:
print(f"- {repo.full_name}")
finally:
# Close the API client
await api_client.close()
if __name__ == "__main__":
asyncio.run(test_token_owner())