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

Refactor to use rest.search.issuesAndPullRequests #18

Merged
merged 2 commits into from
Jul 4, 2024

Conversation

klaasnicolaas
Copy link
Owner

@klaasnicolaas klaasnicolaas commented Jul 4, 2024

Thanks to this refactor, we can search very specifically for issues and pull requests that are closed but not yet locked.

Summary by CodeRabbit

  • Tests
    • Added and updated test cases for fetching and locking GitHub issues and pull requests.
    • Added new test scenarios for handling rate limits and different activity statuses.
    • Improved test coverage for error handling and debug messaging.

@klaasnicolaas klaasnicolaas added the refactor Improvement of existing code, not introducing new features. label Jul 4, 2024
Copy link

codecov bot commented Jul 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (7ea09bb) to head (3ed7c5e).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #18   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines          102        95    -7     
  Branches        26        15   -11     
=========================================
- Hits           102        95    -7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

coderabbitai bot commented Jul 4, 2024

Walkthrough

Walkthrough

The recent updates enhance testing for fetching and locking GitHub issues and pull requests, integrating rate limit handling and error management. It includes mock data adjustments, new test cases for activity-based issue locking, and revised function parameters. The changes also refactor imports, mock setups, and test case structures to improve robustness and coverage.

Changes

File Path Change Summary
__tests__/fetch_lock.test.ts Introduced tests for fetching and locking GitHub issues/PRs, handling rate limits, and error cases.
__tests__/issues.test.ts Updated mocks, test cases, and parameters for activity-based issue locking.
__tests__/pull_requests.test.ts Modified tests to include fetchIssuesAndPRs and current date for activity-based PR handling.
__tests__/ratelimit.test.ts Removed outdated Octokit function calls.
__tests__/run.test.ts Refactored inputs, date handling, and Octokit mocks; added new test configurations.

Sequence Diagram(s)

sequenceDiagram
    participant Test Suite
    participant GitHub Mock
    participant Core Mock

    Test Suite->>GitHub Mock: Fetch issues and PRs
    GitHub Mock-->>Test Suite: Return fetched items
    Test Suite->>Core Mock: Process items
    Core Mock-->>Test Suite: Return processed results

    Test Suite->>GitHub Mock: Lock stale items
    GitHub Mock-->>Test Suite: Confirm lock

    Note right of Test Suite: New test cases simulate activity-based locking
Loading

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: 0

Outside diff range and nitpick comments (1)
src/index.ts (1)

Line range hint 16-97:
LGTM! But consider removing the unnecessary else clause.

The function is well-written but includes an unnecessary else clause as previous branches break early.

-    } else {
-      core.warning('Initial rate limit too low, stopping processing.')
-    }
+    core.warning('Initial rate limit too low, stopping processing.')
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7ea09bb and e48fa55.

Files ignored due to path filters (1)
  • dist/index.js is excluded by !**/dist/**
Files selected for processing (6)
  • tests/fetch_lock.test.ts (1 hunks)
  • tests/issues.test.ts (4 hunks)
  • tests/pull_requests.test.ts (4 hunks)
  • tests/ratelimit.test.ts (2 hunks)
  • tests/run.test.ts (4 hunks)
  • src/index.ts (3 hunks)
Files not reviewed due to errors (1)
  • tests/pull_requests.test.ts (no review received)
Additional context used
Biome
src/index.ts

[error] 152-155: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)

Additional comments not posted (19)
__tests__/run.test.ts (3)

3-3: Import statement looks good.

The import of run from src/index is correct and necessary for the test.


14-18: Mock date setup looks good.

Setting a mock date using jest.useFakeTimers().setSystemTime(currentDate) is a good practice for consistent test results.


32-34: Mock Octokit setup looks good.

The search.issuesAndPullRequests method is correctly mocked in the mockOctokit object.

__tests__/ratelimit.test.ts (4)

30-32: Mock Octokit setup looks good.

The search.issuesAndPullRequests method is correctly mocked in the mockOctokit object.


Line range hint 3-3:
Import statements look good.

The import of processPullRequests and fetchIssuesAndPRs from src/index is correct and necessary for the test.


Line range hint 14-18:
Mock date setup looks good.

Setting a mock date using jest.useFakeTimers().setSystemTime(currentDate) is a good practice for consistent test results.


32-34: Mock Octokit setup looks good.

The search.issuesAndPullRequests method is correctly mocked in the mockOctokit object.

__tests__/issues.test.ts (3)

3-3: Import statements look good.

The import of processIssues and fetchIssuesAndPRs from src/index is correct and necessary for the test.


14-18: Mock date setup looks good.

Setting a mock date using jest.useFakeTimers().setSystemTime(currentDate) is a good practice for consistent test results.


32-34: Mock Octokit setup looks good.

The search.issuesAndPullRequests method is correctly mocked in the mockOctokit object.

__tests__/fetch_lock.test.ts (5)

62-78: LGTM! Test case for rate limit warning is well-written.

The test case correctly mocks the rate limit response and verifies the warning.


80-87: LGTM! Test case for fetching issues and PRs is well-written.

The test case correctly mocks the API call and verifies the parameters.


89-117: LGTM! Test case for fetching multiple pages of issues and PRs is well-written.

The test case correctly mocks the API calls and verifies the results.


119-136: LGTM! Test case for handling errors during fetching is well-written.

The test case correctly mocks the error response and verifies the error handling.


138-155: LGTM! Test case for handling errors during locking is well-written.

The test case correctly mocks the error response and verifies the error handling.

src/index.ts (4)

98-160: LGTM! Function fetchIssuesAndPRs is well-written.

The function includes proper error handling and correctly fetches issues and PRs.

Tools
Biome

[error] 152-155: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)


164-212: LGTM! Function processIssues is well-written.

The function includes proper logging and error handling.


214-256: LGTM! Function processPullRequests is well-written.

The function includes proper logging and error handling.


258-294: LGTM! Function lockItem is well-written.

The function includes proper error handling.

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

Outside diff range and nitpick comments (1)
src/index.ts (1)

Line range hint 16-95:
The run function is well-structured but can be optimized.

The function correctly initializes inputs, checks the rate limit, fetches issues and PRs, processes them, and checks the rate limit again. However, the else clause after checking the rate limit can be omitted for cleaner code.

-    }
-    core.warning('Initial rate limit too low, stopping processing.')
+    } else {
+      core.warning('Initial rate limit too low, stopping processing.')
+    }
Tools
Biome

[error] 151-154: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e48fa55 and 3ed7c5e.

Files ignored due to path filters (1)
  • dist/index.js is excluded by !**/dist/**
Files selected for processing (2)
  • tests/fetch_lock.test.ts (1 hunks)
  • src/index.ts (2 hunks)
Additional context used
Biome
src/index.ts

[error] 151-154: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)

Additional comments not posted (12)
__tests__/fetch_lock.test.ts (7)

1-11: Good setup for mocking core and GitHub modules.

The initial setup logic correctly mocks the necessary modules and defines mock objects for core and GitHub.


12-57: Initialization and setup for tests are well done.

The beforeEach block correctly initializes the mock Octokit instance and sets up the test environment.


59-97: Test case for rate limit buffer is well-implemented.

The test case correctly simulates a rate limit condition and verifies that the appropriate warning is issued.


99-106: Test case for fetching issues and PRs is accurate.

The test case correctly verifies the fetching logic and ensures that the API call is made with the correct parameters.


108-136: Test case for fetching multiple pages of issues and PRs is thorough.

The test case correctly simulates multiple pages and verifies that all items are fetched.


138-155: Test case for error handling during fetching is effective.

The test case correctly simulates an error and verifies that the appropriate failure message is set.


157-174: Test case for error handling during locking is effective.

The test case correctly simulates an error and verifies that the appropriate failure message is set.

src/index.ts (5)

97-159: The fetchIssuesAndPRs function is well-implemented.

The function correctly handles fetching closed issues and PRs, checks the rate limit, and handles pagination.

Tools
Biome

[error] 151-154: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)


163-211: The processIssues function is well-implemented.

The function correctly processes and locks inactive issues, and sets the output for locked issues.


213-255: The processPullRequests function is well-implemented.

The function correctly processes and locks inactive pull requests, and sets the output for locked pull requests.


257-293: The lockItem function is well-implemented.

The function correctly handles the locking logic and error handling.


Line range hint 294-311:
The checkRateLimit function is well-implemented.

The function correctly handles the rate limit checking and error handling.

Tools
Biome

[error] 151-154: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)

@klaasnicolaas klaasnicolaas merged commit c3ddbe8 into main Jul 4, 2024
14 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jul 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
refactor Improvement of existing code, not introducing new features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant