-
Notifications
You must be signed in to change notification settings - Fork 656
Sanitize Participant #4588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Sanitize Participant #4588
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
src/GitVersion.Core.Tests/Helpers/ParticipantSanitizerTests.cs
This file contains hidden or 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,67 @@ | ||
using GitVersion.Testing.Helpers; | ||
|
||
namespace GitVersion.Core.Tests.Helpers; | ||
|
||
[TestFixture] | ||
public class ParticipantSanitizerTests | ||
{ | ||
[TestCase("feature/1234-is-id-with-something-kebab", "feature_1234_is_id_with_something_kebab")] | ||
[TestCase("feature/1234-IsSomethingPascalCase", "feature_1234_IsSomethingPascalCase")] | ||
[TestCase("feature/Caps-lower-something-kebab", "feature_Caps_lower_something_kebab")] | ||
[TestCase("feature/Caps-lower-is-kebab", "feature_Caps_lower_is_kebab")] | ||
[TestCase("kebab-folder/1234-is-id-with-something-kebab", "kebab_folder_1234_is_id_with_something_kebab")] | ||
[TestCase("kebab-folder/1234-IsSomethingPascalCase", "kebab_folder_1234_IsSomethingPascalCase")] | ||
[TestCase("kebab-folder/Caps-lower-something-kebab", "kebab_folder_Caps_lower_something_kebab")] | ||
[TestCase("kebab-folder/Caps-lower-is-kebab", "kebab_folder_Caps_lower_is_kebab")] | ||
[TestCase("PascalCaseFolder/1234-is-id-with-something-kebab", "PascalCaseFolder_1234_is_id_with_something_kebab")] | ||
[TestCase("PascalCaseFolder/1234-IsSomethingPascalCase", "PascalCaseFolder_1234_IsSomethingPascalCase")] | ||
[TestCase("PascalCaseFolder/Caps-lower-something-kebab", "PascalCaseFolder_Caps_lower_something_kebab")] | ||
[TestCase("PascalCaseFolder/Caps-lower-is-kebab", "PascalCaseFolder_Caps_lower_is_kebab")] | ||
[TestCase("1234-is-id-with-something-kebab", "1234_is_id_with_something_kebab")] | ||
[TestCase("1234-IsSomethingPascalCase", "1234_IsSomethingPascalCase")] | ||
[TestCase("Caps-lower-something-kebab", "Caps_lower_something_kebab")] | ||
[TestCase("Caps-lower-is-kebab", "Caps_lower_is_kebab")] | ||
[TestCase("feature/all-lower-is-kebab", "feature_all_lower_is_kebab")] | ||
[TestCase("feature/24321-Upperjustoneword", "feature_24321_Upperjustoneword")] | ||
[TestCase("feature/justoneword", "feature_justoneword")] | ||
[TestCase("feature/PascalCase", "feature_PascalCase")] | ||
[TestCase("feature/PascalCase-with-kebab", "feature_PascalCase_with_kebab")] | ||
[TestCase("feature/12414", "feature_12414")] | ||
[TestCase("feature/12414/12342-FeatureStoryTaskWithShortDescription", "feature_12414_12342_FeatureStoryTaskWithShortDescription")] | ||
[TestCase("feature/12414/12342-Short-description", "feature_12414_12342_Short_description")] | ||
[TestCase("feature/12414/12342-short-description", "feature_12414_12342_short_description")] | ||
[TestCase("feature/12414/12342-Short-Description", "feature_12414_12342_Short_Description")] | ||
[TestCase("release/1.0.0", "release_1_0_0")] | ||
[TestCase("releases", "releases")] | ||
[TestCase("feature", "feature")] | ||
[TestCase("feature/tfs1-Short-description", "feature_tfs1_Short_description")] | ||
[TestCase("feature/f2-Short-description", "feature_f2_Short_description")] | ||
[TestCase("feature/bug1", "feature_bug1")] | ||
[TestCase("f2", "f2")] | ||
[TestCase("feature/f2", "feature_f2")] | ||
[TestCase("feature/story2", "feature_story2")] | ||
[TestCase("master", "master")] | ||
[TestCase("develop", "develop")] | ||
[TestCase("main", "main")] | ||
public void SanitizeValidParticipant_ShouldReturnExpectedResult(string input, string expected) | ||
{ | ||
var actual = ParticipantSanitizer.SanitizeParticipant(input); | ||
actual.ShouldBe(expected); | ||
} | ||
|
||
[TestCase("")] | ||
[TestCase(" ")] | ||
public void SanitizeEmptyOrWhitespaceParticipant_ShouldThrow(string value) | ||
{ | ||
var exception = Should.Throw<ArgumentException>(() => ParticipantSanitizer.SanitizeParticipant(value)); | ||
exception.Message.ShouldBe("The value cannot be an empty string or composed entirely of whitespace. (Parameter 'participant')"); | ||
} | ||
|
||
[TestCase("feature/")] | ||
[TestCase("/")] | ||
public void SanitizeInvalidParticipant_ShouldThrow(string value) | ||
{ | ||
var exception = Should.Throw<ArgumentException>(() => ParticipantSanitizer.SanitizeParticipant(value)); | ||
exception.Message.ShouldBe("The value cannot end with a folder separator ('/'). (Parameter 'participant')"); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,26 @@ | ||
using GitVersion.Core; | ||
|
||
namespace GitVersion.Testing.Helpers; | ||
|
||
public static class ParticipantSanitizer | ||
{ | ||
/// <summary> | ||
/// Converts a participant identifier to a standardized format that won't break PlantUml. | ||
/// </summary> | ||
/// <param name="participant">The participant identifier to convert. This value cannot be null, empty, or consist only of whitespace.</param> | ||
public static string SanitizeParticipant(string participant) | ||
{ | ||
GuardAgainstInvalidParticipants(participant); | ||
|
||
return RegexPatterns.Output.SanitizeParticipantRegex().Replace(participant, "_"); | ||
} | ||
|
||
private static void GuardAgainstInvalidParticipants(string participant) | ||
{ | ||
ArgumentException.ThrowIfNullOrWhiteSpace(participant); | ||
if (participant.EndsWith('/')) | ||
{ | ||
throw new ArgumentException("The value cannot end with a folder separator ('/').", nameof(participant)); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.