Skip to content

Conversation

@JoanFo1456
Copy link
Contributor

Something made webhooks be arrays now, this pull request should fix the problem.

@coderabbitai
Copy link

coderabbitai bot commented Oct 16, 2025

📝 Walkthrough

Walkthrough

The PR changes webhook processing to conditionally decode/wrap payload data and to build headers only for Regular webhook types. It also updates WebhookConfiguration::replaceVars to accept arrays or objects, converting objects to arrays before performing replacements.

Changes

Cohort / File(s) Summary
Webhook Processing
app/Jobs/ProcessWebhook.php
Conditional JSON decoding: payload data is decoded/wrapped only when it's a string; non-string data is left unchanged. Header construction and replacement occur only for Regular webhook types; other types receive empty headers.
Webhook Configuration Utilities
app/Models/WebhookConfiguration.php
Method signature updated to replaceVars(array|object $replacement, string $subject): string. If $replacement is an object, it's normalized to an array via toArray() before preg_replace_callback. Docblock updated to reflect the union type.

Sequence Diagram

sequenceDiagram
    participant Processor as ProcessWebhook
    participant Config as WebhookConfiguration
    participant Handler as Webhook Handler

    Processor->>Processor: Check webhook type
    alt Regular webhook
        Processor->>Processor: If data is string → json_decode & wrap
        Processor->>Processor: Build headers & perform replacements
    else Other webhook types
        Processor->>Processor: Leave data as-is
        Processor->>Processor: Set empty headers
    end

    Processor->>Config: replaceVars(replacement, subject)
    alt replacement is object
        Config->>Config: Convert object → array via toArray()
    else replacement is array
        Config->>Config: Use array as-is
    end

    Config->>Config: Execute preg_replace_callback
    Config-->>Processor: Return processed subject
    Processor->>Handler: Send processed payload & headers
Loading

Possibly related PRs

  • pelican-dev/panel#1704: Makes related changes to WebhookConfiguration::replaceVars and adjusts header/data handling for Regular webhooks.

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title "Repair webhooks once again" is directly related to the changeset, which focuses on fixing webhook handling across two key files. The changes address webhook data processing (conditional wrapping based on data type and webhook type) and the replaceVars method signature (to accept both array and object types). The title correctly identifies the primary action as repairing webhooks, which aligns with the PR objectives stated in the description. While the title could be more specific about the exact nature of the fixes (data type handling, configuration changes), it is sufficiently clear that a teammate scanning history would understand the changeset is addressing webhook functionality issues.
Description Check ✅ Passed The pull request description is related to the changeset. It states "Something made webhooks be arrays now, this pull request should fix the problem," which directly corresponds to the modifications in the code. The changes in ProcessWebhook.php and WebhookConfiguration.php demonstrate handling for different data types (arrays, strings, objects) and conditional logic for webhook type processing, which supports the stated intent to fix webhook array-related issues. Although the description is brief and casual in tone, it conveys meaningful information about the problem being addressed and is clearly on-topic.

📜 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 873816a and 47de070.

📒 Files selected for processing (1)
  • app/Jobs/ProcessWebhook.php (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/Jobs/ProcessWebhook.php

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@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)
app/Jobs/ProcessWebhook.php (1)

32-35: Consider simplifying the data extraction logic.

The multi-step extraction process (get first element, check count, reset if single) is difficult to follow. The purpose of this transformation isn't immediately clear from the code.

Consider adding a comment explaining why this transformation is necessary, or refactor to a dedicated method with a clear name like extractWebhookData().

app/Models/WebhookConfiguration.php (1)

176-180: Add defensive check for the toArray() method.

While the change to accept array|object adds flexibility, calling toArray() without verifying the method exists could cause a fatal error if an incompatible object is passed.

Consider adding a defensive check:

 public function replaceVars(array|object $replacement, string $subject): string
 {
     if (is_object($replacement)) {
+        if (!method_exists($replacement, 'toArray')) {
+            $replacement = (array) $replacement;
+        } else {
             $replacement = $replacement->toArray();
+        }
     }

     return preg_replace_callback(

Alternatively, if only specific object types are expected (e.g., Eloquent models), consider using a more specific union type or interface constraint in the method signature.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1a4fa5e and 2c98489.

📒 Files selected for processing (2)
  • app/Jobs/ProcessWebhook.php (2 hunks)
  • app/Models/WebhookConfiguration.php (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
app/Jobs/ProcessWebhook.php (1)
app/Models/WebhookConfiguration.php (1)
  • replaceVars (176-191)
🔇 Additional comments (2)
app/Jobs/ProcessWebhook.php (2)

37-39: Good defensive coding for type handling.

The conditional check ensures JSON decoding only happens when necessary, and the fallback to an empty array prevents errors from invalid JSON.


60-68: Empty headers for non-Regular webhooks are correct
Discord webhooks don’t support custom headers, which matches the UI configuration.

Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com>
Copy link

@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: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2c98489 and 873816a.

📒 Files selected for processing (1)
  • app/Jobs/ProcessWebhook.php (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
app/Jobs/ProcessWebhook.php (1)
app/Models/WebhookConfiguration.php (1)
  • replaceVars (176-191)

@notAreYouScared notAreYouScared merged commit 3c25b43 into pelican-dev:main Nov 9, 2025
25 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants