-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Conversation
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 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. WalkthroughIn this update, the GitHub ETL processing system has been refactored to improve modularity and functionality. The Changes
Sequence DiagramsNew ETL FlowsequenceDiagram
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
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
%% 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
Poem
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this 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) |
There was a problem hiding this comment.
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.
github_issues_ids.append(issue) | |
github_issue_ids.append(issue) |
from datetime import datetime | ||
from unittest import TestCase | ||
|
||
from pathlib import Path |
There was a problem hiding this comment.
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.
from pathlib import Path |
@@ -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 |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
There was a problem hiding this 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
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 infetch_issues
is correctly implemented.
29-34
: Method delegation in_fetch_raw_issue_ids
is correctly implemented.
36-39
: Method delegation infetch_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
: Methodfetch_issues
correctly processes raw issue data intoGitHubIssue
objects. Well-implemented transformation logic.dags/hivemind_etl_helpers/tests/integration/test_github_etl_fetch_raw_issue_ids.py (6)
8-15
: Test setup insetUp
method is correctly implemented, ensuring a clean state for each test.
16-22
: Test casetest_get_empty_results_no_from_date
correctly checks for empty results when no issues are present.
23-29
: Test casetest_get_empty_results
correctly checks for empty results when filtering by a future date.
30-72
: Test casetest_get_single_issue_id_single_repo
correctly retrieves a single issue ID, verifying the correct behavior.
73-140
: Test casetest_get_multiple_issue_ids_single_repo
correctly retrieves multiple issue IDs, verifying the correct behavior.
142-208
: Test casetest_get_multiple_issue_ids_single_repo_with_filtering
correctly retrieves issue IDs with date filtering, verifying the correct behavior.
There was a problem hiding this 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
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 theGithubExtraction
class is correctly utilized in other modules.Verification successful
The
GithubExtraction
class is indeed being utilized across various modules within thehivemind_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-matchesLength 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-matchesLength of output: 539
There was a problem hiding this 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
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 specifiedfrom_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.
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)")) |
There was a problem hiding this comment.
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.
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) | ||
|
There was a problem hiding this comment.
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.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this 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
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
Summary by CodeRabbit
New Features
GithubExtraction
, that improves the process of fetching GitHub issues and issue IDs.Refactor
GithubExtraction
class.Tests
GithubExtraction
class to ensure reliable fetching of GitHub issues and issue IDs.