Skip to content

Commit

Permalink
Remove whitespace from branch name (#499)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdanish-kh authored Jan 11, 2024
1 parent 2cc15ce commit 2882727
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/WingetCreateCore/Common/GitHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ private async Task<PullRequest> SubmitPRAsync(string packageId, string version,
repo = await this.github.Repository.Get(this.wingetRepoOwner, this.wingetRepo);
}

string newBranchName = $"{packageId}-{version}-{Guid.NewGuid()}";
string newBranchName = $"{packageId}-{version}-{Guid.NewGuid()}".Replace(" ", string.Empty);
string newBranchNameHeads = $"heads/{newBranchName}";

if (string.IsNullOrEmpty(prTitle))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
PackageIdentifier: TestPublisher.VersionWithWhitespace
PackageVersion: test whitespace version
PackageName: Test app
Publisher: Test publisher
License: MIT
ShortDescription: A manifest used to test the branch name is trimmed of whitespace.
InstallerLocale: en-US
Installers:
- Architecture: x64
InstallerUrl: https://fakedomain.com/WingetCreateTestExeInstaller.exe
InstallerType: exe
InstallerSha256: A7803233EEDB6A4B59B3024CCF9292A6FFFB94507DC998AA67C5B745D197A5DC
PackageLocale: en-US
ManifestType: singleton
ManifestVersion: 1.0.0
27 changes: 27 additions & 0 deletions src/WingetCreateTests/WingetCreateTests/UnitTests/GitHubTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Microsoft.WingetCreateUnitTests
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -77,5 +78,31 @@ public async Task GetLatestManifestAndSubmitPR()
await this.gitHub.ClosePullRequest(pullRequest.Number);
StringAssert.StartsWith(string.Format(GitHubPullRequestBaseUrl, this.WingetPkgsTestRepoOwner, this.WingetPkgsTestRepo), pullRequest.HtmlUrl, PullRequestFailedToGenerate);
}

/// <summary>
/// Verifies that the branch name is trimmed of whitespace when submitting a PR. Successful PR generation verifies that the branch name was trimmed.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Test]
public async Task RemoveWhitespaceFromBranchName()
{
string packageId = "TestPublisher.VersionWithWhitespace";
List<string> manifestContents = TestUtils.GetInitialManifestContent($"{packageId}.yaml");
Manifests manifests = Serialization.DeserializeManifestContents(manifestContents);
Assert.That(manifests.SingletonManifest.PackageIdentifier, Is.EqualTo(packageId), FailedToRetrieveManifestFromId);

PullRequest pullRequest = new();
try
{
pullRequest = await this.gitHub.SubmitPullRequestAsync(manifests, this.SubmitPRToFork);
}
catch (Exception e)
{
Assert.Fail($"Failed to generate pull request. {e.Message}");
}

await this.gitHub.ClosePullRequest(pullRequest.Number);
StringAssert.StartsWith(string.Format(GitHubPullRequestBaseUrl, this.WingetPkgsTestRepoOwner, this.WingetPkgsTestRepo), pullRequest.HtmlUrl, PullRequestFailedToGenerate);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<None Update="Resources\Multifile.MsixTest\Multifile.MsixTest.locale.en-US.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\TestPublisher.VersionWithWhitespace.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Resources\TestPublisher.RetainInstallerFields.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down

0 comments on commit 2882727

Please sign in to comment.