Skip to content

feat(integration-discord): add purge-invites command#333

Merged
gvieira18 merged 3 commits into
4.xfrom
feat/discord-purge-invites
Jun 17, 2026
Merged

feat(integration-discord): add purge-invites command#333
gvieira18 merged 3 commits into
4.xfrom
feat/discord-purge-invites

Conversation

@gvieira18

Copy link
Copy Markdown
Member

Summary

  • Add discord:purge-invites Artisan command to delete unused Discord guild invites (max_age=0, uses=0)
  • Support --dry-run to preview matches and --include-expiring to also target time-limited unused invites
  • Display timezone-converted Created At using app.display_timezone
  • Jitter between DELETE calls (200–500ms) to avoid Discord rate limits
  • Individual error handling per invite — partial failures don't abort the batch

Test plan

  • php artisan discord:purge-invites --dry-run — lists matching invites without deleting
  • php artisan discord:purge-invites — deletes matching invites
  • php artisan discord:purge-invites --include-expiring --dry-run — includes expiring invites
  • Re-running after purge shows "No unused invites found"
  • 9 unit/feature tests pass (php artisan test --filter=PurgeUnusedInvites)

Artisan command to delete unused Discord guild invites.
Supports --dry-run preview and --include-expiring flag.
@gvieira18 gvieira18 requested a review from a team June 16, 2026 21:22
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Pro

Run ID: d41d429b-fb7d-43a5-8b74-74835eaf696b

📥 Commits

Reviewing files that changed from the base of the PR and between 95f3ba4 and 71a6621.

📒 Files selected for processing (2)
  • app-modules/integration-discord/src/Sync/Actions/PurgeUnusedInvitesAction.php
  • app-modules/integration-discord/tests/Unit/Sync/PurgeUnusedInvitesActionTest.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • app-modules/integration-discord/tests/Unit/Sync/PurgeUnusedInvitesActionTest.php

📝 Walkthrough

Walkthrough

Adds a discord:purge-invites Artisan command to the Discord integration module. Two Saloon transport request classes are introduced: ListGuildInvites (GET) and DeleteInvite (DELETE) with HTTP method and endpoint tests. PurgeUnusedInvitesAction lists guild invites, filters those with uses === 0 and optionally max_age === 0 or expiring invites, optionally deletes with randomized throttling, and returns structured totals including formatted invite metadata. The command accepts optional guild_id argument, --dry-run, and --include-expiring flags, renders matched invite details in a table, and returns appropriate exit codes. PurgeUnusedInvitesCommand is registered in IntegrationDiscordServiceProvider. Comprehensive unit tests cover all action scenarios including failure per-invite handling and both transport requests. Four Composer dependencies are updated to next patch/minor versions.

Possibly related PRs

  • he4rt/heartdevs.com#179: Introduced the IntegrationDiscordServiceProvider foundation that this PR extends with new command registration.
  • he4rt/heartdevs.com#207: Also extends IntegrationDiscordServiceProvider::boot() to register a new Discord Artisan command in the console command list.
  • he4rt/heartdevs.com#261: Also modifies IntegrationDiscordServiceProvider to register a Discord sync Artisan command in the console boot block.

Suggested reviewers

  • danielhe4rt
  • Clintonrocha98
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title accurately summarizes the main change: adding a purge-invites Artisan command for Discord integration.
Description check ✅ Passed Description is directly related to the changeset, detailing the command's functionality, options, and testing approach.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@app-modules/integration-discord/src/Sync/Actions/PurgeUnusedInvitesAction.php`:
- Around line 27-30: The response from ListGuildInvites is not validated for
success before calling json() on it, meaning error responses from Discord will
be processed as if they were valid invite lists. Add a response status check
immediately after the send() call for ListGuildInvites, consistent with the
validation pattern used in the delete loop (around line 71), to ensure the
response indicates success before attempting to parse and process the invites
data.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 748d69b7-e316-4951-8096-fa6b36fea819

📥 Commits

Reviewing files that changed from the base of the PR and between 9af5ded and 95f3ba4.

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
📒 Files selected for processing (9)
  • app-modules/integration-discord/src/IntegrationDiscordServiceProvider.php
  • app-modules/integration-discord/src/Sync/Actions/PurgeUnusedInvitesAction.php
  • app-modules/integration-discord/src/Sync/Console/PurgeUnusedInvitesCommand.php
  • app-modules/integration-discord/src/Transport/Requests/Invites/DeleteInvite.php
  • app-modules/integration-discord/src/Transport/Requests/Invites/ListGuildInvites.php
  • app-modules/integration-discord/tests/Unit/Sync/PurgeUnusedInvitesActionTest.php
  • app-modules/integration-discord/tests/Unit/Transport/Requests/DeleteInviteTest.php
  • app-modules/integration-discord/tests/Unit/Transport/Requests/ListGuildInvitesTest.php
  • composer.json

@Clintonrocha98 Clintonrocha98 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!!!

@gvieira18 gvieira18 merged commit 54cd9e3 into 4.x Jun 17, 2026
6 checks passed
@gvieira18 gvieira18 deleted the feat/discord-purge-invites branch June 17, 2026 21:10
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.

2 participants