Skip to content

Fix broken endpoints #39

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

Merged
merged 11 commits into from
Apr 18, 2025
Merged

Fix broken endpoints #39

merged 11 commits into from
Apr 18, 2025

Conversation

j4rs
Copy link
Member

@j4rs j4rs commented Apr 17, 2025

V1 uses /v1/... instead of /api/v1, so version 2.0 of this gem is breaking v1.

Summary by CodeRabbit

  • Bug Fixes

    • Corrected test descriptions and expectations to accurately reflect API versioning and error message formatting.
    • Fixed base URL for the v1 API to resolve issues introduced in version 2.
  • Refactor

    • Improved API base URL construction for better flexibility and maintainability.
  • Tests

    • Added and updated tests to verify API version handling and base URL logic.
    • Enabled debugging in the test environment.
  • Chores

    • Updated .gitignore to exclude .byebug_history files.
    • Added a GitHub Actions workflow to automate running tests on Ruby 2.7 and 3.4.
  • Documentation

    • Added CI status badge to the README and improved formatting for API version usage notes.

Copy link
Contributor

coderabbitai bot commented Apr 17, 2025

Warning

Rate limit exceeded

@j4rs has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 6 minutes and 29 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

Reviewing files that changed from the base of the PR and between b10cf52 and bd8fed9.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • lib/pipedrive/api_operations/request.rb (2 hunks)

Walkthrough

The changes update several aspects of the codebase related to API base URL construction, test coverage, and development tooling. The .gitignore file is modified to exclude .byebug_history. The BASE_URL constant in the Pipedrive module is updated to remove the /api suffix. In Pipedrive::APIOperations::Request, two new class methods, api_version_prefix and api_base_url, are introduced to centralize and streamline the construction of API base URLs, and the api_client method is refactored to use this new logic. Test files are updated to reflect changes in API version handling and hash formatting in error messages, as well as to add new tests for the api_base_url class method, covering scenarios for both v1 and v2 API support. Additionally, the byebug debugger is now required in the test suite setup. A new GitHub Actions workflow is added to automate running RSpec tests on Ruby 2.7 and 3.4 in an Ubuntu environment. The README is updated to include a CI badge and formatting adjustments. The version constant is incremented to 2.0.1, and a changelog entry documents the fixes and automation additions.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ResourceClass
    participant RequestClass

    Client->>ResourceClass: Call .api_base_url
    alt supports v2 API
        ResourceClass->>RequestClass: .api_base_url (returns BASE_URL + "/api/v2")
    else does not support v2 API
        ResourceClass->>RequestClass: .api_base_url (returns BASE_URL + "/v1")
    end
    RequestClass-->>ResourceClass: Return constructed base URL
    ResourceClass-->>Client: Return base URL
Loading

Possibly related PRs


🪧 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6fa830f and 0b7a08a.

📒 Files selected for processing (7)
  • .gitignore (1 hunks)
  • lib/pipedrive.rb (1 hunks)
  • lib/pipedrive/api_operations/request.rb (2 hunks)
  • spec/lib/pipedrive/activity_spec.rb (1 hunks)
  • spec/lib/pipedrive/pipedrive_spec.rb (1 hunks)
  • spec/lib/pipedrive/resource_spec.rb (1 hunks)
  • spec/spec_helper.rb (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
lib/pipedrive/api_operations/request.rb (1)
lib/pipedrive.rb (1)
  • api_version (47-49)
spec/lib/pipedrive/resource_spec.rb (1)
lib/pipedrive/api_operations/request.rb (1)
  • api_base_url (25-27)
🪛 RuboCop (1.73)
lib/pipedrive/api_operations/request.rb

[convention] 21-21: Add empty line after guard clause.

(Layout/EmptyLineAfterGuardClause)

🔇 Additional comments (8)
.gitignore (1)

13-13: Good addition to gitignore

Adding .byebug_history to gitignore is an appropriate practice when using the byebug debugger, ensuring debug artifacts don't get committed to version control.

spec/spec_helper.rb (1)

9-9: Appropriate addition of byebug for testing

Adding the byebug require statement is helpful for debugging during test development. This complements the gitignore update to exclude the debug history file.

lib/pipedrive.rb (1)

27-27: This change addresses the core endpoint path issue

Modifying the BASE_URL constant by removing the /api segment is a key part of fixing the endpoint discrepancy described in the PR. This change helps ensure that version 1 of the API correctly uses endpoints prefixed with /v1/... instead of the incorrect /api/v1.

Let's verify this change works with the existing API version handling:

#!/bin/bash
# Search for how this BASE_URL is used in conjunction with API version prefixes
rg -A 5 "BASE_URL" --type ruby
spec/lib/pipedrive/activity_spec.rb (1)

33-33: Fixed test description to match actual behavior

This change corrects the test description to accurately reflect what's being tested. The test asserts that the API version is :v2, but the description incorrectly stated "returns v1 api version". Good catch to improve test clarity.

spec/lib/pipedrive/pipedrive_spec.rb (1)

117-117: Updated hash syntax in error message expectation

This change updates the expected error data string format from Ruby's older hashrocket syntax ({:abc=>123}) to the newer symbol key syntax ({abc: 123}). This reflects modern Ruby coding style.

Let's verify this matches how errors are actually formatted in the codebase:

#!/bin/bash
# Look for how error data is formatted in the error classes or handlers
rg "error.*data.*hash" --type ruby
spec/lib/pipedrive/resource_spec.rb (1)

34-54: Tests for the new URL construction logic look good.

The new test suite for api_base_url properly covers both scenarios for API version construction. It verifies that resources supporting v2 API receive the correct URL prefix api/v2 and those that don't support v2 API correctly use just v1. This aligns perfectly with the PR's objective to fix the broken endpoints and ensure compatibility with version 1 of the API.

lib/pipedrive/api_operations/request.rb (2)

25-27: Base URL construction looks correct.

This method properly combines the BASE_URL constant with the appropriate version prefix, ensuring that v1 API calls use "/v1/" and v2 API calls use "/api/v2" as intended by the PR.


51-51: URL construction has been centralized correctly.

Updated to use the new api_base_url method instead of directly constructing the URL. This change aligns with the PR's objective to fix endpoint paths and ensures consistent URL construction throughout the codebase.

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Lite

📥 Commits

Reviewing files that changed from the base of the PR and between 0b7a08a and 16d2483.

📒 Files selected for processing (1)
  • .github/workflows/ci.yml (1 hunks)
🔇 Additional comments (5)
.github/workflows/ci.yml (5)

1-2: Workflow naming is descriptive
The workflow name "Run tests" clearly conveys its purpose.


8-11: Job configuration is solid
Using runs-on: ubuntu-latest is standard for cross‑platform CI.


12-14: Checkout step is up-to-date
actions/checkout@v4 correctly checks out the repository code.


21-23: RSpec invocation is correct
Running bundle exec rspec will execute your test suite. If you later introduce other test tasks (linting, coverage), you can chain them here.


3-7:

❓ Verification inconclusive

Verify branch triggers align with your default branch
The workflow triggers on push to master. If your repository’s default branch is main (or others), consider adding it here to ensure tests run on all primary branches.

You can update the triggers as follows:

 on:
-  pull_request:
-  push:
-    branches: [master]
+  pull_request:
+  push:
+    branches: [master, main]

Please confirm your repo’s default branch name(s) and adjust accordingly.


Align CI workflow triggers with your repository’s default branch
The push trigger currently only includes master. If your default branch is main (or another name), add it here so CI runs on all primary branches:

 on:
-  pull_request:
-  push:
-    branches: [master]
+  pull_request:
+  push:
+    branches: [master, main]

Please confirm your repo’s default branch name(s) and adjust the branches list accordingly.

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

♻️ Duplicate comments (1)
.github/workflows/ci.yml (1)

1-28: 🧹 Nitpick (assertive)

Great job setting up the CI workflow!

The GitHub Actions workflow is well-structured and follows good practices:

  • Triggers on both PRs and pushes to master
  • Tests against both Ruby 2.7 (older) and 3.4 (newer)
  • Uses bundler caching for faster builds
  • Has clear step names and organization

Consider adding an intermediate Ruby version (like 3.0 or 3.1) to your matrix for broader compatibility coverage:

-        ruby-version: [2.7, 3.4]
+        ruby-version: [2.7, 3.0, 3.4]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Lite

📥 Commits

Reviewing files that changed from the base of the PR and between c72624b and f7cef5e.

📒 Files selected for processing (2)
  • .github/workflows/ci.yml (1 hunks)
  • lib/pipedrive/api_operations/request.rb (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
lib/pipedrive/api_operations/request.rb (1)
lib/pipedrive.rb (1)
  • api_version (47-49)
🔇 Additional comments (2)
lib/pipedrive/api_operations/request.rb (2)

26-28: Good URL construction pattern

This method appropriately centralizes the base URL construction logic, which makes the code more maintainable and addresses the endpoint path issue.


52-52: Correct refactoring of the API client

Good job refactoring the API client to use the new api_base_url method instead of manually constructing the URL. This change ensures consistent URL construction throughout the codebase.

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Lite

📥 Commits

Reviewing files that changed from the base of the PR and between f7cef5e and b10cf52.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • lib/pipedrive/version.rb (1 hunks)
🔇 Additional comments (1)
lib/pipedrive/version.rb (1)

4-4: Bump version constant to 2.0.1
The version has been correctly updated from 2.0.0 to 2.0.1 to reflect the v1 API endpoint fix and CI workflow addition.

j4rs and others added 2 commits April 17, 2025 20:30
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@j4rs j4rs merged commit 152adb9 into master Apr 18, 2025
3 checks passed
@j4rs j4rs deleted the fix-broken-endpoints branch April 18, 2025 00:32
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.

1 participant