-
-
Notifications
You must be signed in to change notification settings - Fork 41
Improve the wiki searching code #684
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
Conversation
Reviewer's Guide by SourceryThis pull request refactors the wiki search functionality to use a more general approach and improves code readability. It introduces a new Sequence diagram for the refactored wiki search processsequenceDiagram
participant User
participant Bot
participant WikiAPI
User->>Bot: Send search query
Bot->>Bot: query_wiki(base_url, search_term)
Bot->>WikiAPI: GET request with query params
WikiAPI-->>Bot: Return search results
Bot->>Bot: create_embed(title, ctx)
Bot-->>User: Send embedded response
Class diagram showing the Wiki cog structure after refactoringclassDiagram
class Wiki {
+bot: Tux
+arch_wiki_api_url: str
+atl_wiki_api_url: str
+create_embed(title: tuple, ctx: Context) discord.Embed
+query_wiki(base_url: str, search_term: str) tuple
+wiki(ctx: Context)
+arch_wiki(ctx: Context, query: str)
+atl_wiki(ctx: Context, query: str)
}
note for Wiki "Refactored to use a single query_wiki method"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey @Atmois - I've reviewed your changes - here's some feedback:
Overall Comments:
- Could you explain the rationale for switching from the opensearch API to the query API? This is a significant change that should be documented in the PR description.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟡 Security: 1 issue found
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| data = response.json() | ||
| return (data[1][0], data[3][0]) if data[1] else ("error", "error") | ||
| logger.info(data) | ||
| if data.get("query") and data["query"].get("search"): |
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.
🚨 suggestion (security): Consider logging only relevant fields to avoid potential sensitive data exposure
| data = response.json() | |
| return (data[1][0], data[3][0]) if data[1] else ("error", "error") | |
| logger.info(data) | |
| if data.get("query") and data["query"].get("search"): | |
| data = response.json() | |
| search_data = data.get("query", {}).get("search", []) | |
| logger.info(f"Search returned {len(search_data)} results") | |
| if search_data: |
| discord.Embed | ||
| The created embed message. | ||
| """ | ||
| if title[0] == "error": |
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.
issue (code-quality): We've found these issues:
- Replace if statement with if expression (
assign-if-exp) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| search_results = data["query"]["search"] | ||
| if search_results: |
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.
suggestion (code-quality): Use named expression to simplify assignment and conditional (use-named-expression)
| search_results = data["query"]["search"] | |
| if search_results: | |
| if search_results := data["query"]["search"]: |
Description
Use a different searching system and also improved the code
Guidelines
My code follows the style guidelines of this project (formatted with Ruff)
I have performed a self-review of my own code
I have commented my code, particularly in hard-to-understand areas
I have made corresponding changes to the documentation if needed
My changes generate no new warnings
I have tested this change
Any dependent changes have been merged and published in downstream modules
I have added all appropriate labels to this PR
I have followed all of these guidelines.
How Has This Been Tested? (if applicable)
tested in atl.dev
Screenshots (if applicable)
n/a
Additional Information
n/a