Add ticket-driven branch creation flow
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Git;
|
||||
|
||||
class ValidateGitBranchName
|
||||
{
|
||||
public function message(string $branchName): ?string
|
||||
{
|
||||
$trimmedBranchName = trim($branchName);
|
||||
|
||||
if ($trimmedBranchName === '') {
|
||||
return 'Branch name is required.';
|
||||
}
|
||||
|
||||
if (preg_match('/\s/', $trimmedBranchName) === 1) {
|
||||
return 'Branch names must not contain whitespace.';
|
||||
}
|
||||
|
||||
if (
|
||||
str_starts_with($trimmedBranchName, '/') ||
|
||||
str_ends_with($trimmedBranchName, '/') ||
|
||||
str_starts_with($trimmedBranchName, '.') ||
|
||||
str_ends_with($trimmedBranchName, '.')
|
||||
) {
|
||||
return 'Branch names must not start or end with "/" or ".".';
|
||||
}
|
||||
|
||||
if (
|
||||
str_contains($trimmedBranchName, '..') ||
|
||||
str_contains($trimmedBranchName, '//') ||
|
||||
str_contains($trimmedBranchName, '@{')
|
||||
) {
|
||||
return 'Branch names contain an unsupported ref pattern.';
|
||||
}
|
||||
|
||||
if (preg_match('/[~^:?*\[\\\\]/', $trimmedBranchName) === 1) {
|
||||
return 'Branch names contain unsupported characters.';
|
||||
}
|
||||
|
||||
if (str_ends_with($trimmedBranchName, '.lock')) {
|
||||
return 'Branch names must not end with ".lock".';
|
||||
}
|
||||
|
||||
if (preg_match('/[\x00-\x1F\x7F]/', $trimmedBranchName) === 1) {
|
||||
return 'Branch names contain unsupported control characters.';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user