Skip to content

feat: add buzz refresh command for autodata refresh#138

Merged
narthur merged 5 commits intomainfrom
copilot/add-refresh-command-autodata
Oct 20, 2025
Merged

feat: add buzz refresh command for autodata refresh#138
narthur merged 5 commits intomainfrom
copilot/add-refresh-command-autodata

Conversation

Copy link
Contributor

Copilot AI commented Oct 20, 2025

  • Add RefreshGoal function to beeminder.go to call Beeminder API refresh endpoint
  • Add handleRefreshCommand function to main.go to handle CLI command
  • Update main() switch case to include "refresh" command
  • Update printHelp() to document the new refresh command
  • Add tests for RefreshGoal function in beeminder_test.go
  • Build and test the implementation
  • Update README.md with refresh command documentation
  • Address CodeRabbit feedback: make tests actually verify function behavior
  • Address CodeRabbit feedback: extend BaseURL support to all API functions
  • Address CodeRabbit feedback: extract repeated BaseURL pattern into helper

Summary

Successfully implemented the buzz refresh <goalslug> command and addressed all CodeRabbit feedback.

Latest Changes (commit: refactor: extract getBaseURL helper)

  • Added getBaseURL(config) helper function to eliminate code duplication
  • Replaced 6 instances of duplicated BaseURL fallback logic with calls to the helper
  • Follows DRY (Don't Repeat Yourself) principle
  • All tests pass with 31.6% coverage
  • Cleaner, more maintainable codebase
Original prompt

Let's add a new refresh command, like buzz refresh goal_slug, to have Beeminder refresh autodata for a goal.

https://api.beeminder.com/#refresh


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Summary by CodeRabbit

  • New Features

    • Added a new buzz refresh command to manually queue a goal graph refresh (asynchronous, same effect as the web refresh button).
    • Config can include an optional custom API base URL for advanced setups.
  • Documentation

    • Added usage, example, and notes explaining the refresh command and its asynchronous behavior.
  • Tests

    • Added unit tests covering queued refresh success, queued failure, and API error handling.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 20, 2025

Walkthrough

Adds a CLI command buzz refresh <goalslug>, a RefreshGoal API function that calls Beeminder's refresh_graph endpoint, unit tests using a mock HTTP server, a Config.BaseURL field, and README documentation. The CLI invokes the API to queue an asynchronous Beeminder autodata refresh.

Changes

Cohort / File(s) Summary
Documentation
README.md
Added docs for the buzz refresh <goalslug> command: usage, example, relation to the Beeminder autodata refresh button, and note that the operation is asynchronous.
Core API Implementation
beeminder.go
Replaced hard-coded Beeminder API URLs with a base URL resolved via getBaseURL(config) (defaults to https://www.beeminder.com). Added RefreshGoal(config *Config, goalSlug string) (bool, error) which GETs /users/{username}/goals/{goalSlug}/refresh_graph.json, requires HTTP 200, decodes a boolean response, and returns it or an error.
Test Coverage
beeminder_test.go
Added TestRefreshGoalWithMockServer with subtests: "successful refresh" (returns true), "unsuccessful refresh" (returns false), and "API error" (HTTP 500). Uses a mock HTTP server to validate request path, response decoding, and error handling.
CLI Integration
main.go
Added buzz refresh <goalslug> subcommand and handleRefreshCommand handler: validates args and config, loads config, calls RefreshGoal, and reports whether the refresh was queued. Updated help/usage output and command dispatch to include refresh.
Configuration
config.go
Added BaseURL string \json:"base_url,omitempty"`toConfigto allow an optional API base URL;getBaseURLdefaults tohttps://www.beeminder.com` when unset.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "feat: add buzz refresh command for autodata refresh" clearly and accurately describes the primary objective of the pull request. The PR implements a new CLI command buzz refresh <goalslug> to queue autodata refreshes on Beeminder, which is precisely what the title conveys. The title is specific and concise, uses the conventional "feat:" prefix, and focuses on the main deliverable without unnecessary details. While the PR includes secondary changes like BaseURL refactoring and test coverage, the title appropriately highlights the core feature being introduced.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch copilot/add-refresh-command-autodata

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Co-authored-by: narthur <4655422+narthur@users.noreply.github.com>
Copilot AI changed the title [WIP] Add refresh command for Beeminder autodata feat: add buzz refresh command for autodata refresh Oct 20, 2025
Copilot AI requested a review from narthur October 20, 2025 19:02
@narthur narthur marked this pull request as ready for review October 20, 2025 19:02
@narthur
Copy link
Collaborator

narthur commented Oct 20, 2025

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 20, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: Repository: PinePeakDigital/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8f5e373 and 74f3d74.

📒 Files selected for processing (4)
  • README.md (1 hunks)
  • beeminder.go (1 hunks)
  • beeminder_test.go (1 hunks)
  • main.go (3 hunks)
🔇 Additional comments (6)
main.go (4)

224-224: LGTM!

The help text clearly documents the new refresh command and follows the existing format.


246-248: LGTM!

The command dispatcher correctly routes the "refresh" command to the new handler.


254-254: LGTM!

The available commands list is correctly updated to include "refresh".


513-548: LGTM!

The implementation follows the established pattern from other command handlers like handleAddCommand. The argument validation, configuration loading, and error handling are all appropriate. The output clearly distinguishes between successful queueing and unsuccessful refresh attempts.

beeminder.go (1)

329-351: LGTM!

The implementation is consistent with other API functions in the file. It properly handles errors, validates the response status, and correctly decodes the boolean result. The function signature and error handling follow the established patterns.

README.md (1)

107-119: LGTM!

The documentation is clear, comprehensive, and helpful. It provides a good example, explains the use cases, and importantly notes the asynchronous nature of the operation to set correct user expectations.

@narthur
Copy link
Collaborator

narthur commented Oct 20, 2025

@copilot Please address coderabbit feedback. Your instructions file tells you how to access the feedback.

Co-authored-by: narthur <4655422+narthur@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 20, 2025

@copilot Please address coderabbit feedback. Your instructions file tells you how to access the feedback.

Fixed in commit 74f3d74. Added BaseURL field to Config struct and updated RefreshGoal() to use it with fallback to production URL. Tests now actually call the function with mock servers and verify URL construction, HTTP method, response decoding, and error handling.

Copilot AI requested a review from narthur October 20, 2025 19:15
@narthur
Copy link
Collaborator

narthur commented Oct 20, 2025

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 20, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: Repository: PinePeakDigital/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 74f3d74 and f68e5cc.

📒 Files selected for processing (3)
  • beeminder.go (1 hunks)
  • beeminder_test.go (1 hunks)
  • config.go (1 hunks)
🔇 Additional comments (3)
config.go (1)

16-16: LGTM! Clean addition for testability.

The optional BaseURL field is well-documented and properly tagged. This enables testing with mock servers while maintaining backward compatibility.

beeminder.go (1)

331-355: Function implementation is correct.

The implementation properly handles the configurable base URL, constructs the correct API endpoint, and includes appropriate error handling and resource cleanup.

beeminder_test.go (1)

581-669: Excellent test coverage! Addresses previous feedback.

The tests now properly verify RefreshGoal behavior by:

  • Setting config.BaseURL to the mock server URL
  • Actually calling RefreshGoal() (addressing the previous review feedback)
  • Verifying HTTP method, URL construction, and response decoding
  • Covering success, failure, and error scenarios

This provides comprehensive coverage for the new functionality.

@narthur
Copy link
Collaborator

narthur commented Oct 20, 2025

@copilot Please address coderabbit feedback. Your instructions file tells you how to access the feedback.

Co-authored-by: narthur <4655422+narthur@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 20, 2025

@copilot Please address coderabbit feedback. Your instructions file tells you how to access the feedback.

Addressed in commit (hash will be added after push). Extended BaseURL support to all API functions (FetchGoals, GetLastDatapointValue, CreateDatapoint, FetchGoalWithDatapoints, CreateGoal) for consistency and improved testability across the codebase.

@narthur
Copy link
Collaborator

narthur commented Oct 20, 2025

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 20, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: Repository: PinePeakDigital/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f68e5cc and 214969f.

📒 Files selected for processing (1)
  • beeminder.go (6 hunks)
🔇 Additional comments (1)
beeminder.go (1)

348-375: No changes required. Goal slugs are restricted to URL-safe characters by design.

After verification, Beeminder uses "slug-like" naming similar to GitHub repositories and Slack channels, with an opinionated design philosophy. Goals use concise one-word names, with the goalname used in the URL. The codebase pattern of not encoding the goalSlug parameter is consistent across all functions (GetLastDatapointValue, CreateDatapoint, FetchGoalWithDatapoints, and RefreshGoal) and reflects the intended use of URL-safe slug identifiers. The RefreshGoal function implementation follows the established pattern correctly.

@narthur
Copy link
Collaborator

narthur commented Oct 20, 2025

@copilot Please address coderabbit feedback. Your instructions file tells you how to access the feedback.

Co-authored-by: narthur <4655422+narthur@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 20, 2025

@copilot Please address coderabbit feedback. Your instructions file tells you how to access the feedback.

Addressed in commit (will update with hash). Extracted the repeated BaseURL pattern into a getBaseURL(config) helper function and replaced all 6 occurrences to follow the DRY principle.

Copilot AI requested a review from narthur October 20, 2025 19:38
@narthur
Copy link
Collaborator

narthur commented Oct 20, 2025

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 20, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: Repository: PinePeakDigital/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 214969f and f743bdd.

📒 Files selected for processing (1)
  • beeminder.go (6 hunks)
🔇 Additional comments (2)
beeminder.go (2)

44-46: Consistent helper usage across all API functions.

All five existing API functions (FetchGoals, GetLastDatapointValue, CreateDatapoint, FetchGoalWithDatapoints, CreateGoal) now consistently use the getBaseURL helper. This improves maintainability and testability as requested in previous feedback.

Also applies to: 230-232, 261-263, 284-286, 309-311


342-365: LGTM! Clean implementation following established patterns.

The RefreshGoal function is well-implemented:

  • Follows the same structure and error-handling pattern as other API functions in this file
  • Correctly uses the getBaseURL helper for testability
  • Appropriate error propagation for network failures, non-OK status codes, and decode errors
  • Return signature (bool, error) matches the API response structure

The implementation is consistent with the existing codebase and addresses the requirements outlined in the PR objectives.

@github-actions
Copy link

github-actions bot commented Oct 20, 2025

🚀 Pre-release Build Ready

Test builds are ready! Install directly using the bin command:

# Install the pre-release
bin install https://github.com/PinePeakDigital/buzz/releases/tag/pr-138-latest buzz-pr-138
# Run the pre-release
buzz-pr-138
# Uninstall the pre-release
bin remove buzz-pr-138

Direct Download Links

Or download binaries directly from the pre-release page:

💡 No GitHub login required for downloads!

🗑️ This pre-release will be automatically deleted when the PR is closed.

@narthur narthur merged commit 87563a9 into main Oct 20, 2025
7 checks passed
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