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

Functional to OOP refactor for fetch_issues method #105

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

JacobCWBillings
Copy link

@JacobCWBillings JacobCWBillings commented Mar 29, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new class, GithubExtraction, that improves the process of fetching GitHub issues and issue IDs.
  • Refactor

    • Refactored the existing issue fetching functionality to use the new GithubExtraction class.
  • Tests

    • Added comprehensive test cases for the new GithubExtraction class to ensure reliable fetching of GitHub issues and issue IDs.

Copy link
Contributor

coderabbitai bot commented Apr 12, 2024

Warning

Rate limit exceeded

@JacobCWBillings has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 27 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 187cfa5 and 90fae80.

Walkthrough

In this update, the GitHub ETL processing system has been refactored to improve modularity and functionality. The fetch_issues and fetch_raw_issues functions have been moved into a new GithubExtraction class. This class now handles operations for fetching issues and issue IDs, streamlining the extraction process. New tests were added and existing ones updated to ensure robust validation. These changes enhance readability, maintainability, and scalability of the ETL pipeline.

Changes

Files Change Summary
dags/.../github_etl.py, dags/.../extract/__init__.py Refactored fetch_issues to use the new GithubExtraction class and updated imports accordingly.
dags/.../extract/github_extraction.py Introduced GithubExtraction class for fetching raw GitHub issues and issue IDs.
dags/.../extract/issues.py Moved functions into GithubIssueExtraction class and added new methods for fetching issues and issue IDs.
dags/.../schema/__init__.py, dags/.../schema/issue.py Added GitHubIssueID class and updated schema exports.
dags/.../tests/integration/test_github_etl_fetch_issue_ids.py Added tests for fetching GitHub issue IDs with GithubExtraction class.
dags/.../tests/integration/test_github_etl_fetch_issues.py, dags/.../test_github_etl_... Updated tests to use methods from the new GithubExtraction class and added tests for fetching raw issue data.

Sequence Diagrams

New ETL Flow

sequenceDiagram
    participant User
    participant ETL_Process
    participant GithubExtraction
    User->>ETL_Process: Call fetch_issues()
    ETL_Process->>GithubExtraction: Instantiate and call fetch_issues
    GithubExtraction->>GitHub_API: Fetch Issues
    GitHub_API-->>GithubExtraction: Return Issues
    GithubExtraction-->>ETL_Process: Return processed Issues
    ETL_Process-->>User: Return final data
Loading

Old vs. New Flow Comparison

%% Old
sequenceDiagram
    participant User
    participant ETL_Process
    participant fetch_issues_function
    User->>ETL_Process: Call fetch_issues()
    ETL_Process->>fetch_issues_function: Directly call fetch_issues
    fetch_issues_function->>GitHub_API: Fetch Issues
    GitHub_API-->>fetch_issues_function: Return Issues
    fetch_issues_function-->>ETL_Process: Return processed Issues
    ETL_Process-->>User: Return final data
Loading
%% New
sequenceDiagram
    participant User
    participant ETL_Process
    participant GithubExtraction
    User->>ETL_Process: Call fetch_issues()
    ETL_Process->>GithubExtraction: Instantiate and call fetch_issues
    GithubExtraction->>GitHub_API: Fetch Issues
    GitHub_API-->>GithubExtraction: Return Issues
    GithubExtraction-->>ETL_Process: Return processed Issues
    ETL_Process-->>User: Return final data
Loading

Poem

In the code where data thrives,
A rabbit’s touch, the ETL revives. 🐇
Extractor class now stands tall,
Fetching issues, IDs, it covers all.
With tests robust, the data flows,
In modular streams, the system grows. 🚀
For GitHub’s heart, a brighter prose.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

github_issue_ids: list[GitHubIssueID] = []
for record in records:
issue = GitHubIssueID.from_dict(record)
github_issues_ids.append(issue)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the undefined variable github_issues_ids. It seems there is a typo in the variable name when appending to the list.

- github_issues_ids.append(issue)
+ github_issue_ids.append(issue)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
github_issues_ids.append(issue)
github_issue_ids.append(issue)

from datetime import datetime
from unittest import TestCase

from pathlib import Path
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the unused import Path from pathlib.

- from pathlib import Path

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
from pathlib import Path

@amindadgar amindadgar self-requested a review April 24, 2024 08:42
@@ -1,5 +1,6 @@
# flake8: noqa
from .comments import fetch_comments
from .commit import fetch_commits
from .issues import fetch_issues
from .github_extraction import GithubExtraction
from .issues import GithubIssueExtraction
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove line 5 and import the GithubIssueExtraction directly from its file in test cases.

# self.comment_extraction = GitHubCommentExtraction()
self.issue_extraction = GithubIssueExtraction()

def _fetch_raw_issues(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this as we wouldn't use it directly.

Copy link
Member

@amindadgar amindadgar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes. Could you please clarify what was the usage of GitHubIssueId here?
Also, added some other comments on github_extraction.py, please have a look.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between fe72a60 and cd9d8b6.
Files selected for processing (3)
  • dags/hivemind_etl_helpers/src/db/github/extract/github_extraction.py (1 hunks)
  • dags/hivemind_etl_helpers/src/db/github/extract/issues.py (1 hunks)
  • dags/hivemind_etl_helpers/tests/integration/test_github_etl_fetch_raw_issue_ids.py (1 hunks)
Additional comments not posted (15)
dags/hivemind_etl_helpers/src/db/github/extract/github_extraction.py (5)

8-15: Initialization looks good. Consider tracking the commented lines for future expansions in your project management tools.


17-22: Method delegation in _fetch_raw_issues is correctly implemented.


24-27: Method delegation in fetch_issues is correctly implemented.


29-34: Method delegation in _fetch_raw_issue_ids is correctly implemented.


36-39: Method delegation in fetch_issue_ids is correctly implemented.

dags/hivemind_etl_helpers/src/db/github/extract/issues.py (4)

8-17: Initialization of Neo4j connection in __init__ is well-documented and correctly implemented.


18-77: Method _fetch_raw_issues is well-documented and correctly implements the Neo4j query execution.


79-128: Method _fetch_raw_issue_ids is well-documented and correctly implements the Neo4j query execution.


130-158: Method fetch_issues correctly processes raw issue data into GitHubIssue objects. Well-implemented transformation logic.

dags/hivemind_etl_helpers/tests/integration/test_github_etl_fetch_raw_issue_ids.py (6)

8-15: Test setup in setUp method is correctly implemented, ensuring a clean state for each test.


16-22: Test case test_get_empty_results_no_from_date correctly checks for empty results when no issues are present.


23-29: Test case test_get_empty_results correctly checks for empty results when filtering by a future date.


30-72: Test case test_get_single_issue_id_single_repo correctly retrieves a single issue ID, verifying the correct behavior.


73-140: Test case test_get_multiple_issue_ids_single_repo correctly retrieves multiple issue IDs, verifying the correct behavior.


142-208: Test case test_get_multiple_issue_ids_single_repo_with_filtering correctly retrieves issue IDs with date filtering, verifying the correct behavior.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between cd9d8b6 and 345805b.
Files selected for processing (1)
  • dags/hivemind_etl_helpers/src/db/github/extract/init.py (1 hunks)
Additional comments not posted (1)
dags/hivemind_etl_helpers/src/db/github/extract/__init__.py (1)

4-4: Ensure that the GithubExtraction class is correctly utilized in other modules.

Verification successful

The GithubExtraction class is indeed being utilized across various modules within the hivemind_etl_helpers project. This includes both main and test modules, indicating a thorough integration of the class following its introduction or modification.

  • Main Usage: The class is used in github_etl.py, which likely serves as a central module for GitHub ETL processes.
  • Test Coverage: There is extensive test coverage as evidenced by its usage in multiple integration test files, ensuring that the class functions as expected across different scenarios.
  • Definition and Initialization: The class is defined in github_extraction.py and is correctly imported in the __init__.py file, facilitating its accessibility across the project.

This confirms that the GithubExtraction class is correctly utilized in other modules as intended.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the `GithubExtraction` class is being used in other modules as expected.

# Test: Search for the class usage in Python files. Expect: Occurrences in files where it should be used.
rg --type python 'GithubExtraction' --files-with-matches

Length of output: 87



Script:

#!/bin/bash
# Description: Re-verify the usage of the `GithubExtraction` class in other modules.

# Correcting the file type specification error and re-running the search for class usage in Python files.
rg 'GithubExtraction' --type py --files-with-matches

Length of output: 539

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 345805b and f290eb8.

Files selected for processing (1)
  • dags/hivemind_etl_helpers/tests/integration/test_github_etl_fetch_raw_issue_ids.py (1 hunks)
Additional comments not posted (2)
dags/hivemind_etl_helpers/tests/integration/test_github_etl_fetch_raw_issue_ids.py (2)

16-21: Good test coverage for scenarios with no specified from_date.

This test effectively checks the behavior when no date is provided, which is critical for ensuring the method handles such cases gracefully.


23-28: This test properly handles the scenario where issues are fetched from a specific start date.

It's important to verify that the method respects the from_date parameter correctly, and this test does that well.

Comment on lines +9 to +14
def setUp(self) -> None:
self.extractor = GithubExtraction()
neo4j_connection = Neo4jConnection()
self.neo4j_driver = neo4j_connection.connect_neo4j()
with self.neo4j_driver.session() as session:
session.execute_write(lambda tx: tx.run("MATCH (n) DETACH DELETE (n)"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using mocks for Neo4j interactions to improve test isolation and speed.

It's generally a good practice to mock external services in unit tests to ensure tests do not fail due to external dependencies and are faster to run.

Comment on lines 30 to 59
def test_get_single_issue_single_repo_minimum_info(self):
with self.neo4j_driver.session() as session:
session.execute_write(
lambda tx: tx.run(
"""
CREATE (i:Issue)<-[:CREATED]-(:GitHubUser {login: "author #1"})
SET
i.latestSavedAt = "2024-02-15T06:10:02.262000000Z",
i.comments = 0,
i.created_at = "2024-02-06T10:23:50Z",
i.number = 1,
i.updated_at = "2024-02-06T12:56:05Z",
i.repository_id = 123,
i.id = 21200001,
i.node_id = "some_id"

CREATE (repo:Repository {id: 123, full_name: "Org/SampleRepo"})
"""
)
)


repository_ids = [123]
issues = self.extractor._fetch_raw_issues(
repository_id=repository_ids, from_date=datetime(2024, 1, 1)
)

self.assertEqual(len(issues), 1)
self.assertEqual(issues[0]["id"], 21200001)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure clarity in test setup by separating data creation from assertion logic.

Splitting the setup (Neo4j data creation) and the actual test logic into separate methods or sections can improve readability and maintainability of tests.

Comment on lines 60 to 101
def test_get_single_issue_single_repo_complete_info(self):
with self.neo4j_driver.session() as session:
session.execute_write(
lambda tx: tx.run(
"""
CREATE (i:Issue)<-[:CREATED]-(:GitHubUser {login: "author #1"})
SET
i.state_reason = "completed",
i.body = "explanation of some sample issue",
i.latestSavedAt = "2024-02-15T06:10:02.262000000Z",
i.closed_at = "2024-02-06T12:56:05Z",
i.comments = 0,
i.created_at = "2024-02-06T10:23:50Z",
i.title = "some sample title",
i.url = "https://api.github.com/repos/GitHub/some_repo/issues/1",
i.author_association = "CONTRIBUTOR",
i.labels_url = "https://api.github.com/repos/GitHub/some_repo/issues/1/labels{/name}",
i.number = 1,
i.updated_at = "2024-02-06T12:56:05Z",
i.events_url = "https://api.github.com/repos/GitHub/some_repo/issues/1/events",
i.html_url = "https://github.com/GitHub/some_repo/issues/1",
i.comments_url = "https://api.github.com/repos/GitHub/some_repo/issues/1/comments",
i.repository_id = 123,
i.id = 21200001,
i.repository_url = "https://api.github.com/repos/GitHub/some_repo",
i.state = "closed",
i.locked = false,
i.timeline_url = "https://api.github.com/repos/GitHub/some_repo/issues/1/timeline",
i.node_id = "some_id"

CREATE (repo:Repository {id: 123, full_name: "Org/SampleRepo"})
"""
)
)

repository_ids = [123]
issues = self.extractor._fetch_raw_issues(
repository_id=repository_ids, from_date=datetime(2024, 1, 1)
)

self.assertEqual(len(issues), 1)
self.assertEqual(issues[0]["id"], 21200001)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comprehensive test, but consider using transactional fixtures for setup.

Using transactional fixtures or mocks for database setup can help isolate the tests better and make them more reliable and easier to maintain.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f290eb8 and 187cfa5.

Files selected for processing (1)
  • dags/hivemind_etl_helpers/tests/integration/test_github_etl_fetch_raw_issue_ids.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • dags/hivemind_etl_helpers/tests/integration/test_github_etl_fetch_raw_issue_ids.py

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.

2 participants