Added git url validation for Azure DevOps repositories#134
Conversation
Azure DevOps repositories have a different format compared to GitHub urls. This update adds RegEx support for Azure DevOps repos.
There was a problem hiding this comment.
Pull request overview
Adds Azure DevOps repository URL support to the existing Git URL validation utility so PolyRepo can accept additional clone URL formats (including percent-encoded spaces in project/repo names).
Changes:
- Expanded
GitUrlUtilitiesURL validation regex to accept Azure DevOps HTTPS and SSH clone URL formats. - Added unit tests covering Azure DevOps URL examples.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/Dutchskull.Aspire.PolyRepo/GitUrlUtilities.cs |
Extends the Git URL validation regex to include Azure DevOps URL patterns. |
src/Dutchskull.Aspire.PolyRepo.Tests.Unit/GitUrlUtilitiesTests.cs |
Adds unit test inputs for Azure DevOps URLs (HTTPS + SSH). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| !string.IsNullOrEmpty(url) && GitUrlRegex().IsMatch(url); | ||
|
|
||
| [GeneratedRegex(@"^(?:git|https?|git@[\w\.]+):\/\/[\w\.@\:\/\-~]+\.git(?:\/)?$")] | ||
| [GeneratedRegex(@"^(?:(?:git|https?):\/\/[^\s]+\.git(?:\/)?|https:\/\/(?:[\w.-]+@)?dev\.azure\.com\/[^\/\s]+\/[^\/\s]+\/_git\/[^\/\s]+(?:\/)?|git@ssh\.dev\.azure\.com:v3\/[^\/\s]+\/[^\/\s]+\/[^\/\s]+(?:\/)?)$")] |
There was a problem hiding this comment.
The new Azure DevOps patterns allow percent-encoded names (e.g., %20), but GetProjectNameFromGitUrl later derives the local folder name by taking the last / segment verbatim. With Azure DevOps URLs this will produce a repository path containing %20 sequences instead of spaces (and other escaped characters), which is likely not the intended behavior given the goal of supporting spaces in project names. Consider URL-decoding the extracted segment(s) before using them as a directory name (and ensure decoding is safe for filesystem paths).
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
WhiteOlivierus
left a comment
There was a problem hiding this comment.
Thank you for the intrest and the pr. Love to see test because it makes my life easier. I have one ask. But the feature would be welcome.
| { | ||
| internal static string GetProjectNameFromGitUrl(string gitUrl) => | ||
| gitUrl.RemovePostfix(".git").Split('/')[^1]; | ||
| internal static string GetProjectNameFromGitUrl(string gitUrl) |
There was a problem hiding this comment.
Is it maybe an idea to create a Uri object and get the segment you want by index? The reason I did some string math before is because it was a simple Uri. Now that it is more complex, a more simple solution that would scale would be nice.
There was a problem hiding this comment.
Are you looking for "simpler", or more performant? I just pushed some changes with some optimizations for parsing and validation the URI.
There was a problem hiding this comment.
I would like it simpler. Because I can image gitea and gitlab also having different Uri's and then it is interesting to just have a index to change of which segment of the uri you want to have.
I am moving, so it could be that I will react after Monday.
Optimizing hot path
Azure DevOps repositories have a different format compared to GitHub urls. This update adds RegEx support for Azure DevOps repos, including support for spaces in project names.