Skip to content

πŸš€ release: v1.0.0-beta.6#33

Merged
warengonzaga merged 13 commits intomainfrom
dev
Jul 3, 2025
Merged

πŸš€ release: v1.0.0-beta.6#33
warengonzaga merged 13 commits intomainfrom
dev

Conversation

@warengonzaga
Copy link
Member

@warengonzaga warengonzaga commented Jul 3, 2025

Summary by CodeRabbit

  • New Features

    • Added support for setting a default priority for new tickets created via the bot, configurable through an environment variable.
    • Ticket creation now includes the priority field when set, with allowed values of low, medium, high, or critical.
  • Chores

    • Updated environment validation process for improved reliability and structured logging.
    • Updated package version to 1.0.0-beta.6.
    • Improved handling and logging of environment variables throughout the application.

Copilot AI and others added 10 commits July 2, 2025 16:01
Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…afety

Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
…TicketPayload

Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
Co-authored-by: warengonzaga <15052701+warengonzaga@users.noreply.github.com>
Add support for configuring default ticket priority via UNTHREAD_DEFAULT_PRIORITY environment variable
@warengonzaga warengonzaga self-assigned this Jul 3, 2025
Copilot AI review requested due to automatic review settings July 3, 2025 11:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR prepares the v1.0.0-beta.6 release by centralizing environment validation, adding configurable default ticket priority, and cleaning up inline non-null checks.

  • Introduce getDefaultTicketPriority and wire it into ticket creation
  • Add global validateEnvironment() call and remove manual env-var checks
  • Bump version to v1.0.0-beta.6 and update .env.example

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/services/unthread.ts Imported and applied default ticket priority; replaced manual env checks with non-null asserts
src/index.ts Added global env validation; replaced manual token checks with non-null assertions
src/database/connection.ts Removed manual POSTGRES_URL check; added non-null assertion
src/config/env.ts Enhanced validation logging; added getDefaultTicketPriority; removed unused var
package.json Updated version to v1.0.0-beta.6
.env.example Documented UNTHREAD_DEFAULT_PRIORITY
Comments suppressed due to low confidence (5)

src/config/env.ts:36

  • Add UNTHREAD_API_KEY and TELEGRAM_BOT_TOKEN to REQUIRED_ENV_VARS so they’re validated by validateEnvironment() before use.
const REQUIRED_ENV_VARS = [

src/config/env.ts:99

  • Consider adding unit tests for getDefaultTicketPriority() to cover valid, invalid, and missing environment values.
export function getDefaultTicketPriority(): 3 | 5 | 7 | 9 | undefined {

src/services/unthread.ts:324

  • Add tests for createTicketJSON to verify that priority is only added to the payload when UNTHREAD_DEFAULT_PRIORITY is set.
    if (defaultPriority !== undefined) {

src/services/unthread.ts:318

  • [nitpick] The non-null assertion on CHANNEL_ID is redundant; it’s already asserted when declared. You can drop the ! here.
        channelId: CHANNEL_ID!,

src/index.ts:293

  • [nitpick] Since PLATFORM_REDIS_URL is checked in validateEnvironment(), the ! assertion here is no longer needed.
            await BotsStore.initialize(db, process.env.PLATFORM_REDIS_URL!);

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 3, 2025

πŸ“ Walkthrough

Walkthrough

Sir, the system has received several updates. A new environment variable for default ticket priority has been introduced, with corresponding logic to handle and validate it. Logging has been standardized using LogEngine, and environment variable checks have been centralized for reliability. The package version has also been incremented.

Changes

Files/Paths Change Summary
.env.example, .env.railway Added UNTHREAD_DEFAULT_PRIORITY variable with documentation on allowed values and behavior.
package.json Updated version from 1.0.0-beta.5.1 to 1.0.0-beta.6.
src/config/env.ts Switched logging to LogEngine, removed WEBHOOK_REDIS_URL from required vars, added priority handler.
src/database/connection.ts Removed explicit check for POSTGRES_URL; now assumes presence with non-null assertion.
src/index.ts Centralized environment validation; replaced manual checks with assertions after validation.
src/services/unthread.ts Added CreateTicketPayload interface, integrated default priority, streamlined env var handling.

πŸ“œ Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between dca8f66 and 6061007.

πŸ“’ Files selected for processing (1)
  • .env.railway (1 hunks)
βœ… Files skipped from review due to trivial changes (1)
  • .env.railway
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Validate Changes
  • GitHub Check: Build Development Images

πŸͺ§ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 or @coderabbitai auto title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

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

🧹 Nitpick comments (1)
src/config/env.ts (1)

13-13: Minor documentation inconsistency detected, sir.

The documentation references WEBHOOK_REDIS_URL as required, however, the AI summary indicates this variable was removed from the required list. Consider updating the documentation to reflect the current implementation state.

- * - WEBHOOK_REDIS_URL: Redis connection for webhook event processing
πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 81911a5 and f76f1fb.

πŸ“’ Files selected for processing (6)
  • .env.example (1 hunks)
  • package.json (1 hunks)
  • src/config/env.ts (3 hunks)
  • src/database/connection.ts (1 hunks)
  • src/index.ts (3 hunks)
  • src/services/unthread.ts (5 hunks)
🧰 Additional context used
🧠 Learnings (2)
πŸ““ Common learnings
Learnt from: warengonzaga
PR: wgtechlabs/unthread-telegram-bot#24
File: docker-compose.yaml:29-29
Timestamp: 2025-06-22T10:12:09.684Z
Learning: The Unthread Telegram Bot project is currently in beta development phase (v1.0.0-beta.2) and does not yet have official versioned Docker builds available, making the use of :latest tags acceptable for development purposes in docker-compose.yaml.
package.json (1)
Learnt from: warengonzaga
PR: wgtechlabs/unthread-telegram-bot#24
File: docker-compose.yaml:29-29
Timestamp: 2025-06-22T10:12:09.684Z
Learning: The Unthread Telegram Bot project is currently in beta development phase (v1.0.0-beta.2) and does not yet have official versioned Docker builds available, making the use of :latest tags acceptable for development purposes in docker-compose.yaml.
🧬 Code Graph Analysis (2)
src/database/connection.ts (1)
src/config/env.ts (1)
  • isProduction (84-86)
src/services/unthread.ts (1)
src/config/env.ts (1)
  • getDefaultTicketPriority (99-115)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Validate Changes
πŸ”‡ Additional comments (15)
package.json (1)

3-3: Excellent, sir! Version advancement proceeds as expected.

The progression from beta.5.1 to beta.6 follows proper semantic versioning protocols for your beta release cycle. This aligns perfectly with the new priority configuration feature and environment validation enhancements detailed in the accompanying modifications.

.env.example (1)

34-37: Splendid documentation, sir! Priority configuration implemented with exceptional clarity.

The new UNTHREAD_DEFAULT_PRIORITY environment variable is meticulously documented with clear value mappings and usage instructions. The default value of 5 (medium) represents a sensible baseline, and the guidance about empty values creating tickets without priority is precisely what users need to understand the feature behavior.

src/database/connection.ts (2)

66-66: Consistent application of the new validation pattern, sir.

The non-null assertion for POSTGRES_URL in the logging context maintains consistency with the validation approach established at line 59.


59-59: Validation Confirmed: POSTGRES_URL is Covered by Centralized Env Validation

Certainly, sir. I have verified that validateEnvironment() in src/config/env.ts iterates over REQUIRED_ENV_VARS, which includes "POSTGRES_URL", and will throw if it’s absent. The non-null assertion on process.env.POSTGRES_URL is therefore safe.

β€’ Location: src/config/env.ts (REQUIRED_ENV_VARS array, lines 39–43)
β€’ No further changes required.

src/index.ts (3)

31-33: Excellent architectural decision, sir! Environment validation now proceeds with military precision.

The centralized environment validation approach ensures all critical configuration issues are identified before any service initialization begins. This early validation pattern prevents partial system initialization failures and provides clearer error messaging to operators.


58-58: Non-null assertion now operates under validated conditions, sir.

With the upstream environment validation in place, this assertion operates with confidence that TELEGRAM_BOT_TOKEN has been verified for presence and validity.


293-293: Platform Redis URL assertion follows the established validation protocol, sir.

The non-null assertion for PLATFORM_REDIS_URL maintains consistency with the centralized validation pattern, ensuring the BotsStore initialization proceeds with verified configuration.

src/services/unthread.ts (4)

122-134: Superb interface definition, sir! The CreateTicketPayload structure exhibits proper typing discipline.

The new interface provides excellent type safety for the Unthread API payload, with the optional priority field correctly typed to match the allowed values (3, 5, 7, 9). This ensures compile-time validation of the payload structure and prevents invalid priority values from reaching the API.


222-223: Environment variable assertions now operate under validated conditions, sir.

The non-null assertions for UNTHREAD_API_KEY and UNTHREAD_SLACK_CHANNEL_ID align perfectly with the centralized validation pattern established throughout the codebase.


310-326: Priority configuration implementation demonstrates excellent conditional logic, sir.

The implementation correctly retrieves the default priority from the centralized configuration and conditionally includes it in the payload only when defined. This approach prevents sending undefined or invalid priority values to the Unthread API while maintaining backward compatibility for installations without priority configuration.


348-349: Logging enhancement provides valuable operational intelligence, sir.

The inclusion of priority information in the ticket creation log (with a sensible fallback of 'not set') provides operators with clear visibility into the priority assignment behavior, facilitating debugging and operational monitoring.

src/config/env.ts (4)

31-32: Sir, excellent choice implementing structured logging.

The LogEngine integration represents a significant upgrade from primitive console logging methods. This will provide superior observability and debugging capabilities across your application infrastructure.


58-67: Structured error reporting now operational, sir.

The enhanced error logging with detailed context and user-friendly guidance transforms what was once a crude validation process into an elegant diagnostic system. The structured approach with missingVariables and totalMissing provides actionable intelligence for troubleshooting.


70-71: System status reporting elevated to professional standards.

The success logging with environment mode indication provides clear operational visibility - precisely what any well-engineered system requires.


95-115: Priority validation system: sophisticated and bulletproof.

The getDefaultTicketPriority function demonstrates exceptional engineering:

  • Graceful handling of undefined environment variables
  • Robust validation against Unthread API constraints
  • Appropriate warning system for invalid configurations
  • Precise TypeScript typing with union types

The implementation elegantly balances flexibility with safety, sir.

Docstrings generation was requested by @warengonzaga.

* #33 (comment)

The following files were modified:

* `src/config/env.ts`
* `src/services/unthread.ts`
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 3, 2025

Note

Generated docstrings for this pull request at #34

@warengonzaga warengonzaga merged commit f0955c1 into main Jul 3, 2025
4 of 5 checks passed
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.

3 participants