-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Migrate to X v2 api for media upload #105
base: main
Are you sure you want to change the base?
Conversation
Here's the code health analysis summary for commits Analysis Summary
|
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.
Hello @akrherz, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request addresses the migration to the X (formerly Twitter) v2 API for media uploads. The primary goal is to update the iembot
utility to use the new API endpoints for uploading media when tweeting. The PR also includes a minor update to the ruff-pre-commit
hook version.
Highlights
- API Migration: The core change involves migrating from the older Twitter API to the X v2 API for media uploads, ensuring continued functionality as older APIs are deprecated.
- Media Upload Implementation: The implementation uses
requests_oauthlib
to handle the OAuth1 authentication and uploads media files to the new X API endpoint. - Dependency Update: The pull request updates the
ruff-pre-commit
hook to versionv0.9.7
fromv0.9.1
.
Changelog
- .pre-commit-config.yaml
- Updated
ruff-pre-commit
hook version fromv0.9.1
tov0.9.7
.
- Updated
- src/iembot/util.py
- Imported
OAuth1Session
fromrequests_oauthlib
. - Initialized
OAuth1Session
with consumer key, consumer secret, access token, and access token secret on line 71. - Replaced
api.UploadMediaSimple
with a direct POST request to the X v2 media upload endpoint (https://api.x.com/2/media/upload
) on line 101. - Used
requests.get
to fetch the media content before uploading on line 100. - Modified the media upload logic to include the fetched media content as a file in the POST request on line 103.
- Updated the
media_ids
parameter to use the ID returned by the X v2 API on line 106.
- Imported
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Did you know?
The 'X' logo is part of the Unicode character set as U+1D4E7 (Mathematical Italic Small X).
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request migrates to the X v2 API for media upload, which is a necessary update. The changes are generally well-structured, but there are a few areas where improvements can be made to enhance efficiency and robustness. Please ensure that the updated Twitter API integration is thoroughly tested after addressing the comments.
Summary of Findings
- OAuth1Session Usage: The
OAuth1Session
object is instantiated but the originalOAuth1
object is still being used. Consider removing theOAuth1
object if it's no longer needed. - Media Upload: The media upload logic fetches the entire media content into memory. For larger files, this could lead to memory issues. Consider using a streaming approach.
- Error Handling: The code catches
TwitterError
but doesn't handle potential exceptions during the media upload process (e.g.,requests.exceptions.RequestException
).
Assessment
The pull request updates the Ruff pre-commit hook and migrates the Twitter API usage to v2 for media uploads. The changes seem reasonable, but there are a few areas that could be improved for clarity and efficiency. Please address the comments before merging, and ensure that the updated Twitter API integration is thoroughly tested.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #105 +/- ##
==========================================
- Coverage 40.05% 40.01% -0.04%
==========================================
Files 7 7
Lines 1191 1192 +1
==========================================
Hits 477 477
- Misses 714 715 +1 ☔ View full report in Codecov by Sentry. |
Will sit on this until 25 March 2025 gets closer. Maybe an upstream library will better support this.