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

ci cd , record games and players to db #5

Merged
merged 21 commits into from
Feb 6, 2024
Merged

ci cd , record games and players to db #5

merged 21 commits into from
Feb 6, 2024

Conversation

Alex-Kopylov
Copy link
Owner

@Alex-Kopylov Alex-Kopylov commented Feb 6, 2024

Summary by CodeRabbit

  • New Features

    • Introduced Continuous Integration/Continuous Deployment (CI/CD) workflow using Docker Compose.
    • Added functionality for saving game data, including poll results and player information, to a database.
    • Implemented error handling improvements, including conditional error messaging based on configuration.
  • Bug Fixes

    • Corrected database connection functionality to utilize updated file path for SQLite database.
    • Fixed error message formatting for better readability in various modules.
  • Documentation

    • Updated README.md to reflect changes in environment variable names.
    • Added .dockerignore file to improve Docker image builds by excluding unnecessary directories.
  • Chores

    • Updated deployment scripts with new environment variables for enhanced configuration.
  • Refactor

    • Revised data models (Game, Player, Record) including attribute renaming, new validation methods, and type adjustments for better data integrity and handling.

@Alex-Kopylov Alex-Kopylov merged commit b38aa4b into main Feb 6, 2024
2 checks passed
Copy link
Contributor

coderabbitai bot commented Feb 6, 2024

Walkthrough

The recent update enhances a Telegram bot project, focusing on Docker integration, CI/CD via GitHub Actions, and database management for storing poll results and game data. Environment variables have been standardized, and error handling improved, ensuring smoother deployment and operation. This overhaul not only streamlines development workflows but also enriches the bot's functionality with better data handling and logging capabilities.

Changes

Files Summary
.dockerignore Excludes __pycache__, .venv, venv directories.
.github/workflows/deploy.yml Adds TELEGRAM_BOT_TOKEN, DEVELOPER_CHAT_ID, SQLITE_DB_FILE_PATH; updates Docker checks.
.github/workflows/develop.yml Introduces CI/CD using Docker Compose; adds SSH deployment and environment variables.
README.md Updates environment variable name to SQLITE_DB_FILE_PATH.
src/__main__.py Removes telegram.Update import; adjusts logging and error messages.
src/callbacks/..., src/handlers/..., src/services/db_service.py Enhances data handling for polls, games, and errors; introduces database saving functions.
src/config.py, src/db.py Updates default values and database path.
src/data_models/... Refines data models with new attributes, validation methods, and error message formatting.
src/get_handlers.py, src/handlers/error_handler.py Minor adjustments in handler setup and error logging.
src/sql/init.sql Adds and renames columns in database schema; minor formatting changes.

🐇✨
Changes here, changes there,
Code adapts with flair and care.
Through lines of code, we hop and dance,
Enhancing bots, by chance and glance.
🌟🐾

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4d3e8e3 and 097bf11.
Files ignored due to path filters (1)
  • docker-compose.yaml is excluded by: !**/*.yaml
Files selected for processing (17)
  • .dockerignore (1 hunks)
  • .github/workflows/deploy.yml (2 hunks)
  • .github/workflows/develop.yml (1 hunks)
  • README.md (1 hunks)
  • src/main.py (2 hunks)
  • src/callbacks/receive_poll_answer.py (1 hunks)
  • src/config.py (1 hunks)
  • src/data_models/Game.py (1 hunks)
  • src/data_models/Player.py (1 hunks)
  • src/data_models/Record.py (1 hunks)
  • src/db.py (1 hunks)
  • src/get_handlers.py (1 hunks)
  • src/handlers/error_handler.py (3 hunks)
  • src/handlers/game.py (2 hunks)
  • src/handlers/save.py (2 hunks)
  • src/services/db_service.py (2 hunks)
  • src/sql/init.sql (3 hunks)
Files skipped from review due to trivial changes (2)
  • .dockerignore
  • README.md
Additional comments: 13
src/get_handlers.py (1)
  • 16-16: LGTM!
src/config.py (1)
  • 10-14: LGTM!
src/__main__.py (1)
  • 33-37: LGTM!
src/data_models/Record.py (1)
  • 33-35: LGTM!
src/handlers/game.py (1)
  • 35-39: LGTM!
.github/workflows/deploy.yml (1)
  • 30-39: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [33-47]

LGTM!

src/callbacks/receive_poll_answer.py (1)
  • 16-40: LGTM!
.github/workflows/develop.yml (1)
  • 1-47: LGTM!
src/db.py (1)
  • 10-10: LGTM!
src/sql/init.sql (1)
  • 3-12: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [6-53]

LGTM!

src/handlers/error_handler.py (1)
  • 38-50: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [25-50]

LGTM!

src/services/db_service.py (1)
  • 25-64: LGTM!
src/handlers/save.py (1)
  • 92-99: LGTM!

Comment on lines +9 to +13
first_name: Optional[str | None]
full_name: Optional[str | None]
last_name: Optional[str | None]
is_bot: Optional[bool] = False
language_code: Optional[str | None]
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure the use of Optional[str | None] is intentional. Typically, Optional[str] suffices as it already implies None can be a value, making the explicit | None redundant.

- first_name: Optional[str | None]
+ first_name: Optional[str]

Apply this change to full_name, last_name, and language_code as well.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
first_name: Optional[str | None]
full_name: Optional[str | None]
last_name: Optional[str | None]
is_bot: Optional[bool] = False
language_code: Optional[str | None]
first_name: Optional[str]
full_name: Optional[str]
last_name: Optional[str]
is_bot: Optional[bool] = False
language_code: Optional[str]

Comment on lines +15 to +18
@field_validator("is_bot", mode="after")
@classmethod
def validate_bot(cls, v: bool) -> str:
return "TRUE" if v else "FALSE" # sqlite3 does not support boolean type
Copy link
Contributor

Choose a reason for hiding this comment

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

The validate_bot method's return type is incorrect. It should return bool instead of str to match the field type is_bot. Adjust the method to directly return the boolean value.

- def validate_bot(cls, v: bool) -> str:
+ def validate_bot(cls, v: bool) -> bool:
-     return "TRUE" if v else "FALSE"
+     return v

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
@field_validator("is_bot", mode="after")
@classmethod
def validate_bot(cls, v: bool) -> str:
return "TRUE" if v else "FALSE" # sqlite3 does not support boolean type
@field_validator("is_bot", mode="after")
@classmethod
def validate_bot(cls, v: bool) -> bool:
return v # sqlite3 does not support boolean type

Comment on lines +13 to +24
@field_validator("results", mode="after")
@classmethod
def validate_results(cls, v: dict) -> Literal["CH", "DH", "FW", "LW"]:
outcomes = set(v.values())
if "I'm Canceler Hitler" in outcomes:
return "CH"
if "I'm Dead Hitler" in outcomes:
return "DH"
if "I'm Liberal Winner" in outcomes:
return "LW"
if "I'm Fascistic Winner" in outcomes:
return "FW"
Copy link
Contributor

Choose a reason for hiding this comment

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

The validate_results method's return type should match the expected type of the results attribute. If results is intended to be a dict, the method's return type and implementation need adjustment. Consider revising the method or the attribute type to ensure consistency.

- def validate_results(cls, v: dict) -> Literal["CH", "DH", "FW", "LW"]:
+ # Adjust the method or the attribute type to ensure consistency.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
@field_validator("results", mode="after")
@classmethod
def validate_results(cls, v: dict) -> Literal["CH", "DH", "FW", "LW"]:
outcomes = set(v.values())
if "I'm Canceler Hitler" in outcomes:
return "CH"
if "I'm Dead Hitler" in outcomes:
return "DH"
if "I'm Liberal Winner" in outcomes:
return "LW"
if "I'm Fascistic Winner" in outcomes:
return "FW"
@field_validator("results", mode="after")
@classmethod
def validate_results(cls, v: dict): # Adjust the method or the attribute type to ensure consistency.
outcomes = set(v.values())
if "I'm Canceler Hitler" in outcomes:
return "CH"
if "I'm Dead Hitler" in outcomes:
return "DH"
if "I'm Liberal Winner" in outcomes:
return "LW"
if "I'm Fascistic Winner" in outcomes:
return "FW"


def main() -> None:
if not config.TELEGRAM_BOT_TOKEN:
raise ValueError("TELEGRAM_BOT_TOKEN env variable" "wasn't porpoused.")
raise ValueError("TELEGRAM_BOT_TOKEN env variable" "wasn't purposed.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure the error message concatenation is intentional. It appears there might be a missing space between "TELEGRAM_BOT_TOKEN env variable" and "wasn't purposed."

- raise ValueError("TELEGRAM_BOT_TOKEN env variable" "wasn't purposed.")
+ raise ValueError("TELEGRAM_BOT_TOKEN env variable wasn't purposed.")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
raise ValueError("TELEGRAM_BOT_TOKEN env variable" "wasn't purposed.")
raise ValueError("TELEGRAM_BOT_TOKEN env variable wasn't purposed.")

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.

1 participant