-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from mgkimsal/feature/filtered-user-name
fix: treat username, database name and domain name the same
- Loading branch information
Showing
10 changed files
with
201 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of Veyoze CLI. | ||
* | ||
* (c) Mehran Rasulian <mehran.rasulian@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace App\Actions; | ||
|
||
use Illuminate\Support\Str; | ||
use Lorisleiva\Actions\Concerns\AsAction; | ||
|
||
class FormattedBranchName | ||
{ | ||
use AsAction; | ||
|
||
protected const STRING_LIMIT = 64; | ||
|
||
protected const SLUGIFY_DICTIONARY = ['+' => '-', '_' => '-', '@' => '-']; | ||
|
||
public function handle(string $branch, ?string $pattern): string | ||
{ | ||
if (isset($pattern)) { | ||
preg_match($pattern, $branch, $matches); | ||
$branch = array_pop($matches); | ||
} | ||
|
||
$slugged = $this->slugifyIt($branch); | ||
|
||
return Str::limit( | ||
$slugged, | ||
self::STRING_LIMIT | ||
); | ||
} | ||
|
||
protected function slugifyIt(string $branch): string | ||
{ | ||
return Str::slug($branch, '-', 'en', self::SLUGIFY_DICTIONARY); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of Veyoze CLI. | ||
* | ||
* (c) Mehran Rasulian <mehran.rasulian@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace App\Actions; | ||
|
||
use Illuminate\Support\Str; | ||
use Lorisleiva\Actions\Concerns\AsAction; | ||
|
||
class GenerateStandardizedBranchName | ||
{ | ||
use AsAction; | ||
|
||
public function handle(string $branch): string | ||
{ | ||
$firstDigitsOfStringRemoved = preg_replace( | ||
'/^\d+-?/', | ||
'', | ||
$branch | ||
); | ||
|
||
return Str::replace('-', '_', $firstDigitsOfStringRemoved); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
use App\Actions\FormattedBranchName; | ||
|
||
it('verify correct domain generation for various branch formats', function ($actual, $expected) { | ||
expect( | ||
FormattedBranchName::run( | ||
$actual['branch'], | ||
$actual['pattern'], | ||
) | ||
) | ||
->toBe($expected); | ||
}) | ||
->with([ | ||
[ | ||
'actual' => [ | ||
'branch' => 'user_notification+test', | ||
'pattern' => null, | ||
], | ||
'expected' => 'user-notification-test', | ||
], | ||
[ | ||
'actual' => [ | ||
'branch' => 'feature/add-user-notification', | ||
'pattern' => '/feature\/(.*)/i', | ||
], | ||
'expected' => 'add-user-notification', | ||
], | ||
[ | ||
'actual' => [ | ||
'branch' => 'feature/add-user-notification', | ||
'pattern' => '/feature\/(.*)/i', | ||
], | ||
'expected' => 'add-user-notification', | ||
], | ||
[ | ||
'actual' => [ | ||
'branch' => 'feature/add@user-notification', | ||
'pattern' => '/feature\/(.*)/i', | ||
], | ||
'expected' => 'add-user-notification', | ||
], | ||
[ | ||
'actual' => [ | ||
'branch' => 'feature/User-Notification', | ||
'pattern' => '/feature\/(.*)/i', | ||
], | ||
'expected' => 'user-notification', | ||
], | ||
[ | ||
'actual' => [ | ||
'branch' => '360-add-user-notification', | ||
'pattern' => '/\d+/i', | ||
], | ||
'expected' => '360', | ||
], | ||
[ | ||
'actual' => [ | ||
'branch' => 'vyz-145-add-user-notification', | ||
'pattern' => '/vyz-\d+/i', | ||
], | ||
'expected' => 'vyz-145', | ||
], | ||
[ | ||
'actual' => [ | ||
'branch' => 'feature/user@notification!', | ||
'pattern' => '/feature\/(.*)/i', | ||
], | ||
'expected' => 'user-notification', | ||
], | ||
]); | ||
|
||
it('ensure graceful handling of invalid or problematic branch formats', function ($actual, $expected) { | ||
expect( | ||
FormattedBranchName::run( | ||
$actual['branch'], | ||
$actual['pattern'], | ||
) | ||
) | ||
->toBe($expected); | ||
}) | ||
->with([ | ||
[ | ||
'actual' => [ | ||
'branch' => 'feature/user-notification', | ||
'pattern' => '/feature\/(.*)/i', | ||
], | ||
'expected' => 'user-notification', | ||
], | ||
]); |
Oops, something went wrong.