Skip to content

Commit

Permalink
Merge branch 'master' into set-requests-error-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wescopeland authored Jan 31, 2025
2 parents abe033f + 4367e24 commit 6273b57
Show file tree
Hide file tree
Showing 19 changed files with 421 additions and 125 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ DISCORD_INVITE_ID=
# public feeds
DISCORD_WEBHOOK_ACHIEVEMENTS=
DISCORD_WEBHOOK_CLAIMS=
DISCORD_WEBHOOK_NAME_CHANGES=
DISCORD_WEBHOOK_NEWS=
DISCORD_WEBHOOK_USERS=
# moderation feeds
Expand Down
99 changes: 67 additions & 32 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,49 @@ concurrency:
cancel-in-progress: true

jobs:
changes:
runs-on: ubuntu-22.04
name: Check for changes
outputs:
php: ${{ steps.filter.outputs.php }}
node: ${{ steps.filter.outputs.node }}
steps:
- name: Check changed files
uses: dorny/paths-filter@v3
id: filter
with:
filters: |
php:
- '**/*.php'
- 'composer.json'
- 'composer.lock'
- 'phpstan.neon'
- 'pint.json'
node:
- '**/*.js'
- '**/*.ts'
- '**/*.tsx'
- 'package.json'
- 'pnpm-lock.yaml'
- '*eslint*'
- 'tailwind.config.json'
- 'lang/**/*.json'
php-setup:
needs: changes
runs-on: ubuntu-22.04
name: PHP Setup
outputs:
cache-key: ${{ steps.cache-key.outputs.value }}
steps:
- name: Checkout code
if: ${{ needs.changes.outputs.php == 'true' }}
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Setup PHP
if: ${{ needs.changes.outputs.php == 'true' }}
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
Expand All @@ -27,10 +58,12 @@ jobs:
coverage: none

- name: Generate a cache key
if: ${{ needs.changes.outputs.php == 'true' }}
id: cache-key
run: echo "value=${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}" >> $GITHUB_OUTPUT

- name: Cache composer packages
if: ${{ needs.changes.outputs.php == 'true' }}
id: composer-cache
uses: actions/cache@v4
with:
Expand All @@ -42,50 +75,34 @@ jobs:
${{ runner.os }}-php-
- name: Install
if: steps.composer-cache.outputs.cache-hit != 'true'
if: ${{ needs.changes.outputs.php == 'true' && steps.composer-cache.outputs.cache-hit != 'true' }}
run: composer install --prefer-dist

node-setup:
needs: changes
runs-on: ubuntu-22.04
name: Node.js Setup
outputs:
cache-key: ${{ steps.cache-key.outputs.value }}
steps:
- name: Checkout code
if: ${{ needs.changes.outputs.node == 'true' }}
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Install pnpm
if: ${{ needs.changes.outputs.node == 'true' }}
uses: pnpm/action-setup@v4
with:
version: 9

- name: Use Node 20
if: ${{ needs.changes.outputs.node == 'true' }}
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'

- name: Generate cache key
id: cache-key
run: echo "value=${{ runner.os }}-node-${{ hashFiles('**/pnpm-lock.yaml') }}" >> $GITHUB_OUTPUT

- name: Install
if: steps.node-cache.outputs.cache-hit != 'true'
run: pnpm install --frozen-lockfile --prefer-offline

- name: Cache node_modules
id: node-cache
uses: actions/cache@v4
with:
path: |
node_modules
.pnpm-store
key: ${{ steps.cache-key.outputs.value }}

php-checks:
needs: php-setup
needs: [changes, php-setup]
runs-on: ubuntu-22.04
name: PHP Checks
strategy:
Expand All @@ -99,18 +116,27 @@ jobs:
- check: test
command: composer paratest -- --processes=$(nproc)
steps:
- name: Check PHP changes
if: ${{ needs.changes.outputs.php != 'true' }}
run: echo "No PHP changes; skipping checks" && exit 0

- name: Checkout code
if: ${{ needs.changes.outputs.php == 'true' }}
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Setup PHP
if: ${{ needs.changes.outputs.php == 'true' }}
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
extensions: mbstring, :psr
coverage: none
ini-values: memory_limit=1G

- name: Load composer packages
if: ${{ needs.changes.outputs.php == 'true' }}
uses: actions/cache@v4
with:
path: |
Expand All @@ -119,11 +145,13 @@ jobs:
key: ${{ needs.php-setup.outputs.cache-key }}
restore-keys: |
${{ runner.os }}-php-
- name: Run ${{ matrix.check }}
if: ${{ needs.changes.outputs.php == 'true' }}
run: ${{ matrix.command }}

node-checks:
needs: node-setup
needs: [changes, node-setup]
runs-on: ubuntu-22.04
name: Node.js Checks
strategy:
Expand All @@ -141,26 +169,33 @@ jobs:
APP_URL: https://raweb.test
LARAVEL_BYPASS_ENV_CHECK: 1
steps:
- name: Check Node changes
if: ${{ needs.changes.outputs.node != 'true' }}
run: echo "No Node changes; skipping checks" && exit 0

- name: Checkout code
if: ${{ needs.changes.outputs.node == 'true' }}
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Install pnpm
if: ${{ needs.changes.outputs.node == 'true' }}
uses: pnpm/action-setup@v4
with:
version: 9

- name: Use Node 20
if: ${{ needs.changes.outputs.node == 'true' }}
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'
- name: Restore node_modules
uses: actions/cache@v4
with:
path: |
node_modules
.pnpm-store
key: ${{ needs.node-setup.outputs.cache-key }}

- name: Install dependencies
if: ${{ needs.changes.outputs.node == 'true' }}
run: pnpm install --frozen-lockfile --prefer-offline

- name: Run ${{ matrix.check }}
if: ${{ needs.changes.outputs.node == 'true' }}
run: ${{ matrix.command }}
env: ${{ matrix.env || fromJSON('{}') }}
env: ${{ matrix.env || fromJSON('{}') }}
27 changes: 27 additions & 0 deletions app/Community/Actions/ApproveNewDisplayNameAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@

use App\Models\User;
use App\Models\UserUsername;
use GuzzleHttp\Client;
use Throwable;

class ApproveNewDisplayNameAction
{
public function execute(User $user, UserUsername $changeRequest): void
{
$oldDisplayName = $user->display_name;

// Automatically mark conflicting requests as denied.
UserUsername::where('username', $changeRequest->username)
->where('id', '!=', $changeRequest->id)
Expand All @@ -24,5 +28,28 @@ public function execute(User $user, UserUsername $changeRequest): void
$user->save();

sendDisplayNameChangeConfirmationEmail($user, $changeRequest->username);

$this->notifyDiscord($user, $oldDisplayName, $changeRequest->username);
}

private function notifyDiscord(User $user, string $oldName, string $newName): void
{
$webhookUrl = config('services.discord.webhook.name-changes');

if (!$webhookUrl) {
return;
}

$profileUrl = "https://retroachievements.org/user/{$user->username}";
$payload = [
'content' => "[{$user->username}]({$profileUrl}) - Display name changed from **{$oldName}** to **{$newName}**.",
];

try {
(new Client())->post($webhookUrl, ['json' => $payload]);
} catch (Throwable $e) {
// Similar to our other Discord notifications, do nothing.
// But don't flash a server error to the user.
}
}
}
11 changes: 11 additions & 0 deletions app/Filament/Resources/EventAchievementResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public static function infolist(Infolist $infolist): Infolist
Infolists\Components\TextEntry::make('active_through')
->label('Active Through')
->date(),
Infolists\Components\TextEntry::make('achievement.Points')
->label('Points'),
])
->columns(['xl' => 4, 'md' => 2]),

Expand Down Expand Up @@ -154,6 +156,15 @@ public static function form(Form $form): Form
->label('Active Through')
->native(false)
->date(),

Forms\Components\Group::make()
->relationship('achievement')
->schema([
Forms\Components\Select::make('Points')
->options([1 => '1', 2 => '2', 3 => '3', 4 => '4', 5 => '5'])
->default(1)
->required(),
]),
]),

Forms\Components\Section::make()
Expand Down
1 change: 1 addition & 0 deletions app/Filament/Resources/EventResource/Pages/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ protected function handleRecordCreation(array $data): Model
'Title' => 'Placeholder',
'Description' => 'TBD',
'MemAddr' => '0=1',
'Points' => 1,
'Flags' => AchievementFlag::OfficialCore->value,
'GameID' => $game->id,
'user_id' => $user_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public function form(Form $form): Form
{
/** @var Event $event */
$event = $this->getOwnerRecord();
$minAchievements = 1;
$maxAchievements = $event->achievements()->count();
$minPoints = 1;
$maxPoints = $event->achievements()->count();
$isNew = true;

if (!$event->awards()->exists()) {
Expand All @@ -52,12 +52,12 @@ public function form(Form $form): Form

$previousTier = $event->awards()->where('tier_index', $tierIndex - 1)->first();
if ($previousTier) {
$minAchievements = $previousTier->achievements_required + 1;
$minPoints = $previousTier->points_required + 1;
}

$nextTier = $event->awards()->where('tier_index', $tierIndex + 1)->first();
if ($nextTier) {
$maxAchievements = $nextTier->achievements_required - 1;
$maxPoints = $nextTier->points_required - 1;
}
}

Expand All @@ -68,11 +68,11 @@ public function form(Form $form): Form
->maxLength(40)
->required(),

Forms\Components\TextInput::make('achievements_required')
->default($maxAchievements)
Forms\Components\TextInput::make('points_required')
->default($maxPoints)
->numeric()
->minValue($minAchievements)
->maxValue($maxAchievements)
->minValue($minPoints)
->maxValue($maxPoints)
->required(),

Forms\Components\TextInput::make('tier_index')
Expand Down Expand Up @@ -117,7 +117,7 @@ public function table(Table $table): Table
Tables\Columns\TextColumn::make('label')
->label('Label'),

Tables\Columns\TextColumn::make('achievements_required'),
Tables\Columns\TextColumn::make('points_required'),
])
->filters([

Expand Down
Loading

0 comments on commit 6273b57

Please sign in to comment.