Skip to content
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

GitAuto: Add an integration test to is_repo_forked() in services/github/repo_manager.py #533

Closed
wants to merge 2 commits into from

Conversation

gitauto-for-dev[bot]
Copy link
Contributor

@gitauto-for-dev gitauto-for-dev bot commented Feb 4, 2025

Resolves #516

Why is this feature needed?

This integration test is required to verify that the function is_repo_forked in services/github/repo_manager.py correctly identifies a forked repository using the GitHub API. It enhances our test coverage and ensures our logic works as expected when interfacing with GitHub.

What and how are we changing? Why this approach?

• Added a new constant, FORKED_REPO = "DeepSeek-R1", in tests/constants.py.
• Created an integration test in tests/services/github/test_repo_manager.py that:

  • Retrieves the GitHub token from the environment.
  • Skips the test gracefully if GITHUB_TOKEN isn’t provided.
  • Calls is_repo_forked with the provided constant to assess if the repository is correctly detected as forked.

This approach leverages the actual GitHub API, ensuring that our function interacts as expected with the external service while maintaining control over the test environment.

What actions are required from users?

Users (or CI pipelines) must supply a valid GITHUB_TOKEN as an environment variable for this integration test to run. If the token is missing, the test will be skipped.

How does it work? (Technical details)

• The test imports the function is_repo_forked from services/github/repo_manager.py along with the forked repository constant from tests/constants.py.
• It retrieves GITHUB_TOKEN from the environment using os.getenv().
• If no token exists, pytest.skip is invoked to avoid test failure in local environments missing the token.
• With the token present, the test calls is_repo_forked(FORKED_REPO, token=token) and asserts that the returned result is True, ensuring that the repository "DeepSeek-R1" is identified as forked.
• The test uses the GitHub API documentation as a reference for expected behavior.

Is it backwards compatible?

Yes, the changes are fully backwards compatible. The addition of a constant and an integration test does not impact the existing functionality. Moreover, the test is self-contained and conditional, ensuring no disruptions in environments without a GITHUB_TOKEN.

Any other considerations?

• This integration test depends on the network and the availability of the GitHub API.
• Future improvements may consider adding more tests for different repository types (e.g., non-forked repositories) or mocking the GitHub API responses to facilitate testing without external dependencies.
• Ensure that the GITHUB_TOKEN provided has sufficient permissions to access repository details on GitHub.

git fetch origin
git checkout gitauto-wes/issue-516-20250204-152047
git pull origin gitauto-wes/issue-516-20250204-152047

Copy link

codecov bot commented Feb 4, 2025

Codecov Report

Attention: Patch coverage is 72.72727% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
tests/services/github/test_repo_manager.py 70.00% 2 Missing and 1 partial ⚠️
Flag Coverage Δ
unittests 49.54% <72.72%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
tests/constants.py 100.00% <100.00%> (ø)
tests/services/github/test_repo_manager.py 70.00% <70.00%> (ø)

@hiroshinishio hiroshinishio deleted the gitauto-wes/issue-516-20250204-152047 branch February 5, 2025 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an integration test to is_repo_forked() in services/github/repo_manager.py
1 participant