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

Add rename function option to return activity ID from uploaded activity #89

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

Conversation

jat255
Copy link

@jat255 jat255 commented Jan 6, 2025

Resolves #88.

Not much to describe apart from the PR title.

I modified upload() to use Client.request to be able to access the "location" response header, which contains the URL needed to fetch the activity ID of the uploaded file. This is not returned initially when the file is uploaded, as it takes Garmin some time to process the activity. I implemented a simple polling process to check if the ID is ready, backing off by half a second with each try. If it doesn't return the value within 5 tries, it gives up.

The headers include with the rename() implementation are what I found to be the minimum required, but I'm not very experienced with the Garmin API, so maybe you have a better implementation.

I also edited the readme to describe the new functionality with a demo.

Summary by CodeRabbit

  • New Features
    • Added ability to retrieve Garmin Connect activity ID after uploading an activity.
    • Introduced method to rename activities on Garmin Connect.
  • Documentation
    • Updated README with new upload method usage and example code.
  • Improvements
    • Enhanced upload method with optional ID retrieval.
    • Implemented retry mechanism for fetching activity ID.
    • Noted potential delay in upload process due to server response time.

Copy link
Contributor

coderabbitai bot commented Jan 6, 2025

Warning

Rate limit exceeded

@jat255 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 27 minutes and 16 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 467c804 and 1008493.

📒 Files selected for processing (2)
  • README.md (1 hunks)
  • garth/http.py (2 hunks)

Walkthrough

The pull request introduces enhanced functionality for Garmin Connect activity management in the garth library. The changes focus on two main features: retrieving the internal activity ID after upload and renaming activities. The upload method now supports an optional return_id flag that allows users to obtain the Garmin-assigned activity identifier. A new rename method has been added to the Client class, enabling users to change the title of an uploaded activity directly through the library.

Changes

File Changes
README.md Updated upload method example to demonstrate return_id functionality
garth/http.py - Added return_id parameter to upload method
- Implemented ID retrieval mechanism with retry logic
- Added new rename method for changing activity titles

Assessment against linked issues

Objective Addressed Explanation
Support renaming activities [#88]
Retrieve activity ID after upload [#88]

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>, 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 922f3c3 and 88abe86.

📒 Files selected for processing (2)
  • README.md (1 hunks)
  • garth/http.py (2 hunks)
🧰 Additional context used
🪛 Markdownlint (0.37.0)
README.md

315-315: Expected: 1; Actual: 2
Multiple consecutive blank lines

(MD012, no-multiple-blanks)


293-293: Expected: 80; Actual: 85
Line length

(MD013, line-length)

🔇 Additional comments (1)
garth/http.py (1)

188-192: 🧹 Nitpick (assertive)

Clarify the docstring for return_id.
The docstring is clear but might benefit from explicit mention of the five-attempt retry limit and half-second exponential backoff.

- (default: ``False``). This requires polling to see if Garmin
- Connect has finished processing the activity, so setting this
- option to ``True`` may introduce some delay
+ (default: ``False``). Setting ``True`` initiates a process that attempts 
+ to retrieve the Garmin Connect activity ID over up to five polls, 
+ each spaced out by an incremental half-second delay.

Likely invalid or redundant comment.

garth/http.py Show resolved Hide resolved
garth/http.py Outdated Show resolved Hide resolved
garth/http.py Outdated Show resolved Hide resolved
garth/http.py Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
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: 4

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 88abe86 and 467c804.

📒 Files selected for processing (2)
  • README.md (1 hunks)
  • garth/http.py (2 hunks)
🧰 Additional context used
🪛 Markdownlint (0.37.0)
README.md

260-260: Expected: 80; Actual: 85
Line length

(MD013, line-length)

🔇 Additional comments (6)
garth/http.py (4)

4-4: Revisit selective import approach
A previous comment suggested that if you plan on using more functions from the time module, it might be consistent to just import time instead of only sleep; otherwise, importing just one function is fine.


188-192: Neat addition of the return_id parameter
The signature cleanly communicates the new functionality. No concerns; this looks great.


231-254: Handle unexpected status codes in ID retrieval loop
This loop only checks for 202 or 201. Consider explicitly handling 4xx or 5xx to provide clearer error messages when ID retrieval fails for other reasons (e.g., permission issues).


257-292: Offer a more informative error mechanism
Raising a generic GarthHTTPError on non-204 statuses is valid, but providing a custom exception or returning a status object can help users handle partial successes or parse more details efficiently.

README.md (2)

253-258: Good documentation of the new return_id feature
Adding these details clarifies how to retrieve the Garmin-internal activity ID. This is helpful for advanced usage.


294-317: Renaming workflow is clearly explained
The documentation nicely walks users through fetching the new ID and applying a rename. No issues.

garth/http.py Outdated Show resolved Hide resolved
garth/http.py Show resolved Hide resolved
garth/http.py Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
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.

Renaming activities?
1 participant