Skip to content
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
13 changes: 10 additions & 3 deletions forklet/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,22 @@ async def run_download():
def info(ctx, repository: str, ref: str):
"""Show information about a repository."""

try:
async def get_repo_info():
"""Fetch repository information asynchronously."""

app = ForkletCLI()
app.initialize_services(ctx.obj.get('token'))

owner, repo_name = app.parse_repository_string(repository)

# Get repository info
repo_info = app.github_service.get_repository_info(owner, repo_name)
git_ref = app.github_service.resolve_reference(owner, repo_name, ref)
repo_info = await app.github_service.get_repository_info(owner, repo_name)
git_ref = await app.github_service.resolve_reference(owner, repo_name, ref)

return repo_info, git_ref

try:
repo_info, git_ref = asyncio.run(get_repo_info())

# Display information
click.echo(f"📊 Repository: {repo_info.full_name}")
Expand Down
2 changes: 1 addition & 1 deletion forklet/infrastructure/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ def setup_logger(


#### GLOBAL LOGGER INSTANCE
logger = setup_logger("Forklet")
logger = setup_logger("Forklet")
2 changes: 0 additions & 2 deletions forklet/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,3 @@ class DownloadConfig:
__all__ = [
"DownloadConfig",
]


2 changes: 1 addition & 1 deletion forklet/models/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
VERSION = "0.1.1"

#### USER AGENT
USER_AGENT = f"Forklet-GitHub-Downloader/{VERSION}"
USER_AGENT = f"Forklet-GitHub-Downloader/{VERSION}"
2 changes: 0 additions & 2 deletions forklet/models/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,5 +255,3 @@ def touch(self) -> None:
"DownloadResult",
"CacheEntry",
]


2 changes: 0 additions & 2 deletions forklet/models/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,3 @@ class GitHubFile:
"RepositoryInfo",
"GitHubFile",
]


2 changes: 0 additions & 2 deletions forklet/models/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,3 @@ class StructuredLogRecord:
__all__ = [
"StructuredLogRecord",
]


13 changes: 11 additions & 2 deletions tests/infrastructure/test_rate_limiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
# Adjust this import path to match your project's structure
from forklet.infrastructure.rate_limiter import RateLimiter, RateLimitInfo

# Mark all tests in this file as asyncio
# pytestmark = pytest.mark.asyncio


## 1. RateLimitInfo Helper Class Tests
Expand Down Expand Up @@ -125,7 +127,7 @@ async def test_acquire_uses_adaptive_delay(mock_sleep):
rl = RateLimiter(default_delay=1.0)

# Mock time.time() to simulate time passing
with patch('time.time', side_effect=[1000.0, 1000.1, 1000.2, 1000.3]) as mock_time:
with patch('time.time', side_effect=[1000.0, 1000.1, 1000.2, 1000.3]):
# Ensure rate limit is not exhausted
rl.rate_limit_info.remaining = 2000

Expand All @@ -137,6 +139,12 @@ async def test_acquire_uses_adaptive_delay(mock_sleep):
# SECOND call: This call is close to the first one, triggering the delay.
await rl.acquire()

# Check that sleep was called. The exact value has jitter, so we check if it was called.
# mock_sleep.assert_called()
# The first call to time.time() is at the start of acquire(),
# the second is for _last_request. The delay calculation uses the first one.
# Expected delay is around 1.0 seconds.
# assert mock_sleep.call_args[0][0] > 0.5
# Assert that sleep was finally called on the second run
mock_sleep.assert_called()
# The delay should be > 0 because elapsed time (0.1s) < default_delay (1.0s)
Expand All @@ -147,7 +155,8 @@ async def test_acquire_updates_last_request_time():
"""Test that acquire() correctly updates the _last_request timestamp."""
rl = RateLimiter()

with patch('time.time', return_value=12345.0) as mock_time:
with patch('time.time', return_value=12345.0):
# Patch sleep to make the test run instantly
with patch('asyncio.sleep'):
await rl.acquire()
assert rl._last_request == 12345.0
Expand Down