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 #519

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 1, 2025

Resolves #516
"""

What is the feature

This pull request adds an integration test for the is_repo_forked() function in services/github/repo_manager.py. The integration test leverages real GitHub data through the GH_APP_TOKEN (as provided by .github/workflows/pytest.yml) to verify that the function correctly distinguishes between forked and non-forked repositories. The test will use:

  • OWNER from tests/constants.py as the owner.
  • REPO from tests/constants.py for a non-forked repository.
  • A new constant FORKED_REPO (to be defined in tests/constants.py) for a forked repository.

How to implement the feature and why

  1. In tests/constants.py:

    • Add a new constant FORKED_REPO with the name of a known forked repository owned by OWNER. This will help in testing both cases.
  2. Create an integration test file (e.g., tests/integration/test_github_repo_manager.py):

    • Import the constants (OWNER, REPO, FORKED_REPO) from tests/constants.py.
    • Import the is_repo_forked() function from services/github/repo_manager.py.
    • Retrieve GH_APP_TOKEN from the environment variables.
    • Write two integration tests:
      a. Test that is_repo_forked(OWNER, REPO) returns False, confirming the function detects a non-forked repository.
      b. Test that is_repo_forked(OWNER, FORKED_REPO) returns True, confirming the function properly identifies a forked repository.

This approach is aligned with modern best practices by implementing a clear, definitive integration test that verifies the behavior of the GitHub API call using actual credentials provided by the CI workflow. Using integration tests ensures that any changes in the GitHub API or our implementation are detected early.

Anything the issuer needs to do

  • Please ensure that FORKED_REPO in tests/constants.py is configured with the name of a valid forked repository under the OWNER account.
  • No further action required.
    """
git checkout gitauto-wes/issue-516-20250131-230446
git pull origin gitauto-wes/issue-516-20250131-230446```

Copy link
Contributor Author

gitauto-for-dev bot commented Feb 1, 2025

The error arises because the import statement is using a forward slash (/) instead of the correct dot (.) to separate module names. In Python, module imports must use dots, so the line:

from tests/constants import OWNER, REPO, FORKED_REPO

should be changed to:

from tests.constants import OWNER, REPO, FORKED_REPO

This minimal change corrects the syntax error in the file tests/integration/test_repo_manager.py (line 5) without altering the intended functionality.

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