Skip to content

Conversation

@Dishant1804
Copy link
Contributor

Resolves #1427

Refactored nest bot /events command to display info same as main page

image

@Dishant1804 Dishant1804 requested a review from arkid15r as a code owner April 26, 2025 16:43
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 26, 2025

Summary by CodeRabbit

  • New Features

    • Event listings now display a flat list of up to 9 upcoming events, each showing the event name, formatted date(s), location, and description.
    • Event locations are now visible in event details.
  • Enhancements

    • Improved date formatting for events, including clearer handling of date ranges.
    • Increased the number of upcoming events shown on the main page from 6 to 9.
  • Bug Fixes

    • More robust event display and testing, reducing reliance on fixed categories and improving reliability.
      """

Summary by CodeRabbit

  • New Features

    • Event listings now display the event location when available.
  • Refactor

    • Events are now shown as a single, flat list instead of being grouped by category.
    • The number of displayed upcoming events is limited to 9.
  • Bug Fixes

    • Improved event display formatting and consistency.
  • Tests

    • Updated tests to reflect the new event structure and display logic.

Walkthrough

The changes refactor the handling and display of events in the Slack integration. The backend logic for gathering event data now returns a flat list of up to nine upcoming events, each including a location field, instead of grouping events by category. The Jinja template is updated to display this flat list without category headers, and to show the event location. The utility function for fetching events is modified to accept a limit parameter, defaulting to nine events. Corresponding tests are updated to reflect the new data structure and output format.

Changes

Files/Paths Change Summary
backend/apps/slack/commands/events.py Refactored to return a flat list of upcoming events (with location), removing category grouping from context.
backend/apps/slack/templates/events.jinja Updated template to iterate over a flat list of events, displaying location and removing category headers/grouping.
backend/apps/slack/utils.py Modified get_events_data to accept a limit parameter (default 9) and return only that many upcoming events.
backend/tests/apps/slack/commands/events_test.py Updated tests to match new event structure, removing category checks and adding assertions for location and flat list.
frontend/src/server/queries/homeQueries.ts Increased the number of upcoming events fetched from 6 to 9 in the GraphQL query.

Assessment against linked issues

Objective Addressed Explanation
Display information similar to the main page: flat list, no categories (#1427)
Show date and location format in event display (#1427)
Limit to 9 upcoming events as on the main page (#1427)
"""
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

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.

@Dishant1804 Dishant1804 changed the title Nestbot events command refactor Nestbot /events command refactor Apr 26, 2025
@Dishant1804 Dishant1804 changed the title Nestbot /events command refactor Nestbot /events command refactor Apr 26, 2025
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: 0

🧹 Nitpick comments (2)
backend/apps/slack/utils.py (1)

120-120: Update function docstring to include the new parameter

The function signature has been updated to include a limit parameter, but the docstring doesn't mention it. Please update the docstring to document this parameter.

 def get_events_data(limit=9):
     """Get events data.
+
+    Args:
+        limit (int, optional): The maximum number of events to fetch. Defaults to 9.

     Returns
         QuerySet or None: A queryset of upcoming events.
backend/apps/slack/commands/events.py (1)

19-28: Verify if sorting is necessary

The code at line 15 sorts the events by start date, but get_events_data() already returns events ordered by start date (as seen in utils.py). Consider removing the redundant sorting to improve performance.

-        sorted_events = sorted(valid_events, key=lambda x: x.start_date)
+        sorted_events = valid_events
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 89afa34 and 5aae346.

📒 Files selected for processing (4)
  • backend/apps/slack/commands/events.py (1 hunks)
  • backend/apps/slack/templates/events.jinja (1 hunks)
  • backend/apps/slack/utils.py (2 hunks)
  • backend/tests/apps/slack/commands/events_test.py (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
backend/apps/slack/utils.py (1)
backend/apps/owasp/models/event.py (1)
  • Event (15-284)
backend/apps/slack/commands/events.py (2)
backend/apps/owasp/models/event.py (1)
  • upcoming_events (57-68)
backend/apps/slack/commands/command.py (1)
  • get_template_context (47-62)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Run backend tests
  • GitHub Check: Run frontend unit tests
  • GitHub Check: Run frontend e2e tests
  • GitHub Check: CodeQL (python)
  • GitHub Check: CodeQL (javascript-typescript)
🔇 Additional comments (9)
backend/apps/slack/utils.py (1)

130-130: LGTM! Optimized database query

Good optimization that limits the number of records fetched from the database, which aligns with the PR objective to display a limited set of upcoming events.

backend/apps/slack/templates/events.jinja (1)

2-4: LGTM! Template updated correctly for flat event list

The template has been appropriately updated to:

  1. Iterate over a flat list of events instead of category-grouped events
  2. Add numeric indexing to the events
  3. Display the event location information

This change aligns with the PR objective to make the event display consistent with the main page.

backend/apps/slack/commands/events.py (3)

17-18: LGTM! Changed to flat event list structure

Good restructuring of the event data from category-based to a simple flat list, which aligns with the PR objective.


25-25: LGTM! Added location information

Good addition of location data from event.suggested_location, which aligns with the PR objective to make event details more consistent with the main page.


32-33: LGTM! Updated context structure

The context structure has been correctly updated to match the new event data organization expected by the template.

backend/tests/apps/slack/commands/events_test.py (4)

9-16: LGTM! Updated MockEvent class

The MockEvent class constructor has been correctly updated to use suggested_location instead of category, aligning with the model changes.


19-39: LGTM! Updated mock event data

Mock events have been appropriately updated to include location information and are pre-sorted by start date, which matches the expected behavior of the actual implementation.


90-111: LGTM! Updated test assertions for first event

The test assertions have been updated to verify the presence and correctness of all fields for the first event, including the new location information.


112-130: LGTM! Added test assertions for second event and footer

Good addition of detailed assertions for the second event and footer block, ensuring comprehensive test coverage of the new event display format.

@Dishant1804
Copy link
Contributor Author

@arkid15r It is ready for review :) -- should we keep the description or remove it?

@Dishant1804
Copy link
Contributor Author

Updated format

image

@Dishant1804 Dishant1804 requested a review from arkid15r April 27, 2025 03:37
@arkid15r arkid15r requested a review from kasya as a code owner April 27, 2025 18:05
Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@arkid15r arkid15r enabled auto-merge April 27, 2025 18:05
@sonarqubecloud
Copy link

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

🧹 Nitpick comments (1)
backend/apps/slack/commands/events.py (1)

22-22: Consider explicitly specifying the event limit.

The AI summary mentions that get_events_data() now supports a limit parameter defaulting to nine events. For clarity and to make the code more self-documenting, consider explicitly passing this limit:

- for event in sorted(get_events_data(), key=lambda e: e.start_date)
+ for event in sorted(get_events_data(limit=9), key=lambda e: e.start_date)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e8acecb and 80eec6a.

📒 Files selected for processing (5)
  • backend/apps/slack/commands/events.py (1 hunks)
  • backend/apps/slack/templates/events.jinja (1 hunks)
  • backend/apps/slack/utils.py (2 hunks)
  • backend/tests/apps/slack/commands/events_test.py (3 hunks)
  • frontend/src/server/queries/homeQueries.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • frontend/src/server/queries/homeQueries.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • backend/apps/slack/utils.py
  • backend/apps/slack/templates/events.jinja
  • backend/tests/apps/slack/commands/events_test.py
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Run frontend unit tests
  • GitHub Check: Run frontend e2e tests
  • GitHub Check: Run backend tests
  • GitHub Check: CodeQL (python)
  • GitHub Check: CodeQL (javascript-typescript)
🔇 Additional comments (2)
backend/apps/slack/commands/events.py (2)

13-23: Improved event data structure with cleaner implementation.

The refactoring simplifies the event data handling by creating a flat list of events sorted by start date, which aligns well with the PR objective of matching the main page format. The code is now more maintainable and easier to understand.


27-27: Good naming for flat event list.

The context key "upcoming_events" clearly communicates the content and purpose of this data structure, making the template implementation more intuitive.

@arkid15r arkid15r added this pull request to the merge queue Apr 27, 2025
Merged via the queue into OWASP:main with commit 17304a8 Apr 27, 2025
22 checks passed
shdwcodr pushed a commit to shdwcodr/Nest that referenced this pull request Jun 5, 2025
* events command refactored

* format changed

* Update code

---------

Co-authored-by: Arkadii Yakovets <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve NestBot /owasp events command

2 participants