Skip to content

Commit

Permalink
Improved regex validation of version in GH repository name.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bajger committed Jan 18, 2024
1 parent fb87ddc commit 723d1d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ PhLImageCreateFromRemoteRepoCliCommandTest >> testValidateRepoFullName [
| commandSpec validRepoNames |

commandSpec := PhLImageCreateFromRemoteRepoCliCommand asCliCommand.
validRepoNames := #('owner/project' 'owner/project:branch' 'owner/some-project:feature/branch-name').
validRepoNames := #('owner/project' 'owner/project:branch' 'owner/some-project:feature/branch-name' 'owner/project:v1' 'owner/project:v1.1' 'owner/project:v1.1a' 'owner/project:V1.1.1a').

validRepoNames do: [:repoName |
|createCommand|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,16 @@ PhLImageCreateFromRemoteRepoCliCommand >> raiseRepoNameInvalid [

{ #category : #private }
PhLImageCreateFromRemoteRepoCliCommand >> regexForRepoName [
|stringWithDash|

|stringWithDash versionRegex|
"e.g. some-project-123"
stringWithDash := '[\w]+-?[\w]+'.

"should match {alphanumeric-chars with dash}/{alphanumeric-chars with dash}:{feature}/{alphanumeric-chars with dash}"
^ stringWithDash, '\/', stringWithDash, '(\:?', stringWithDash, '(\/', stringWithDash, ')?', ')?'
"e.g. v1.2.3b"
versionRegex := '(v|V)\d+(\.\d+)*[a-zA-Z]?$'.

"should match {alphanumeric-chars with dash}/{alphanumeric-chars with dash}:{version} | ({feature}/{alphanumeric-chars with dash})"
^ '{dashString}\\/{dashString}(\\:?(({versionString})|({dashString}(\\/{dashString})?)))?' format: { 'dashString' -> stringWithDash. 'versionString' -> versionRegex. } asDictionary.
]

{ #category : #private }
Expand Down

0 comments on commit 723d1d5

Please sign in to comment.