diff --git a/src/WingetCreateCLI/Commands/BaseCommand.cs b/src/WingetCreateCLI/Commands/BaseCommand.cs index fd9fa837..bd79b2f4 100644 --- a/src/WingetCreateCLI/Commands/BaseCommand.cs +++ b/src/WingetCreateCLI/Commands/BaseCommand.cs @@ -741,12 +741,12 @@ protected async Task CheckGitHubTokenAndSetClient() /// Submits a pull request with multifile manifests using the user's GitHub access token. /// /// Wrapper object for manifest object models to be submitted. - /// Manifest root name. /// Optional parameter specifying the title for the pull request. /// Optional parameter specifying whether the new submission should replace an existing manifest. /// Optional parameter specifying the version of the manifest to be replaced. + /// Manifest root name. /// A representing the success of the asynchronous operation. - protected async Task GitHubSubmitManifests(Manifests manifests, string manifestRoot = Constants.WingetManifestRoot, string prTitle = null, bool shouldReplace = false, string replaceVersion = null) + protected async Task GitHubSubmitManifests(Manifests manifests, string prTitle = null, bool shouldReplace = false, string replaceVersion = null, string manifestRoot = Constants.WingetManifestRoot) { // Community repo only supports yaml submissions. if (this.WingetRepo == DefaultWingetRepo && @@ -768,7 +768,7 @@ protected async Task GitHubSubmitManifests(Manifests manifests, string man try { - Octokit.PullRequest pullRequest = await this.GitHubClient.SubmitPullRequestAsync(manifests, this.SubmitPRToFork, manifestRoot, prTitle, shouldReplace, replaceVersion); + Octokit.PullRequest pullRequest = await this.GitHubClient.SubmitPullRequestAsync(manifests, this.SubmitPRToFork, prTitle, shouldReplace, replaceVersion, manifestRoot); this.PullRequestNumber = pullRequest.Number; PullRequestEvent pullRequestEvent = new PullRequestEvent { IsSuccessful = true, PullRequestNumber = pullRequest.Number }; TelemetryManager.Log.WriteEvent(pullRequestEvent); diff --git a/src/WingetCreateCLI/Commands/SubmitCommand.cs b/src/WingetCreateCLI/Commands/SubmitCommand.cs index fc162b0b..81d248b0 100644 --- a/src/WingetCreateCLI/Commands/SubmitCommand.cs +++ b/src/WingetCreateCLI/Commands/SubmitCommand.cs @@ -131,7 +131,7 @@ private async Task SubmitManifest() // TODO: Add Font Root Support // See issue: See issue https://github.com/microsoft/winget-create/issues/647 - return await this.GitHubSubmitManifests(manifests, this.PRTitle, WingetCreateCore.Common.Constants.WingetManifestRoot, this.Replace, this.ReplaceVersion); + return await this.GitHubSubmitManifests(manifests, this.PRTitle, this.Replace, this.ReplaceVersion, WingetCreateCore.Common.Constants.WingetManifestRoot); } else if (Directory.Exists(expandedPath) && ValidateManifest(expandedPath, this.Format)) { @@ -145,7 +145,7 @@ private async Task SubmitManifest() // TODO: Add Font Root Support // See issue: See issue https://github.com/microsoft/winget-create/issues/647 - return await this.GitHubSubmitManifests(manifests, this.PRTitle, WingetCreateCore.Common.Constants.WingetManifestRoot, this.Replace, this.ReplaceVersion); + return await this.GitHubSubmitManifests(manifests, this.PRTitle, this.Replace, this.ReplaceVersion, WingetCreateCore.Common.Constants.WingetManifestRoot); } else { diff --git a/src/WingetCreateCLI/Commands/UpdateCommand.cs b/src/WingetCreateCLI/Commands/UpdateCommand.cs index d8523e59..bbb916ba 100644 --- a/src/WingetCreateCLI/Commands/UpdateCommand.cs +++ b/src/WingetCreateCLI/Commands/UpdateCommand.cs @@ -321,10 +321,10 @@ await this.UpdateManifestsInteractively(initialManifests) : return await this.LoadGitHubClient(true) ? (commandEvent.IsSuccessful = await this.GitHubSubmitManifests( updatedManifests, - Constants.WingetManifestRoot, this.GetPRTitle(updatedManifests, originalManifests), this.Replace, - this.ReplaceVersion)) + this.ReplaceVersion, + Constants.WingetManifestRoot)) : false; } diff --git a/src/WingetCreateCore/Common/GitHub.cs b/src/WingetCreateCore/Common/GitHub.cs index 17b243e3..a2b06e98 100644 --- a/src/WingetCreateCore/Common/GitHub.cs +++ b/src/WingetCreateCore/Common/GitHub.cs @@ -137,12 +137,12 @@ public async Task> GetManifestContentAsync(string packageId, string /// /// Wrapper object for manifest object models to be submitted in the PR. /// Bool indicating whether or not to submit the PR via a fork. - /// The manifest root name. /// Optional parameter specifying the title for the pull request. /// Optional parameter specifying whether the new submission should replace an existing manifest. /// Optional parameter specifying the version of the manifest to be replaced. + /// The manifest root name. /// Pull request object. - public Task SubmitPullRequestAsync(Manifests manifests, bool submitToFork, string manifestRoot = Constants.WingetManifestRoot, string prTitle = null, bool shouldReplace = false, string replaceVersion = null) + public Task SubmitPullRequestAsync(Manifests manifests, bool submitToFork, string prTitle = null, bool shouldReplace = false, string replaceVersion = null, string manifestRoot = Constants.WingetManifestRoot) { Dictionary contents = new Dictionary(); string id; @@ -191,6 +191,16 @@ public async Task ClosePullRequest(int pullRequestId) await this.DeletePullRequestBranch(pullRequestId); } + /// + /// Retrieves a pull request based on the provided pull request id. + /// + /// The pull request number. + /// A representing the asynchronous operation. + public async Task GetPullRequest(int pullRequestId) + { + return await this.github.PullRequest.Get(this.wingetRepoOwner, this.wingetRepo, pullRequestId); + } + /// /// Merges an open pull request. /// diff --git a/src/WingetCreateTests/WingetCreateTests/E2ETests/E2ETests.cs b/src/WingetCreateTests/WingetCreateTests/E2ETests/E2ETests.cs index 933b5b8f..1d351537 100644 --- a/src/WingetCreateTests/WingetCreateTests/E2ETests/E2ETests.cs +++ b/src/WingetCreateTests/WingetCreateTests/E2ETests/E2ETests.cs @@ -84,6 +84,7 @@ private async Task RunSubmitAndUpdateFlow(string packageId, string manifestPath, }; ClassicAssert.IsTrue(await submitCommand.Execute(), "Command should have succeeded"); this.AssertValidationOutput(format); + await this.AssertPRTitle(submitCommand.PullRequestNumber, pullRequestTitle); // Clear output for the next command this.sw.GetStringBuilder().Clear(); @@ -118,6 +119,7 @@ await mergeRetryPolicy.ExecuteAsync(async () => // Since SubmitToGitHub is true, the command will first validate the manifest & then submit the PR this.AssertValidationOutput(format); + await this.AssertPRTitle(submitCommand.PullRequestNumber, pullRequestTitle); await this.gitHub.ClosePullRequest(updateCommand.PullRequestNumber); } @@ -133,5 +135,11 @@ private void AssertValidationOutput(ManifestFormat format) Assert.That(output, Does.Contain(Resources.SkippingManifestValidation_Message), "Skipping manifest validation message should be shown"); } } + + private async Task AssertPRTitle(int pullRequestNumber, string expectedTitle) + { + Octokit.PullRequest pr = await this.gitHub.GetPullRequest(pullRequestNumber); + Assert.That(pr.Title, Is.EqualTo(expectedTitle), "PR title should match the expected title"); + } } } diff --git a/src/WingetCreateTests/WingetCreateTests/UnitTests/GitHubTests.cs b/src/WingetCreateTests/WingetCreateTests/UnitTests/GitHubTests.cs index 7392be32..55f2425c 100644 --- a/src/WingetCreateTests/WingetCreateTests/UnitTests/GitHubTests.cs +++ b/src/WingetCreateTests/WingetCreateTests/UnitTests/GitHubTests.cs @@ -104,7 +104,7 @@ public async Task GetLatestManifestAndSubmitPR() manifests.SingletonManifest = Serialization.DeserializeFromString(latestManifest.First()); Assert.That(manifests.SingletonManifest.PackageIdentifier, Is.EqualTo(TestConstants.TestPackageIdentifier), FailedToRetrieveManifestFromId); - Octokit.PullRequest pullRequest = await this.gitHub.SubmitPullRequestAsync(manifests, this.SubmitPRToFork, root, TestConstants.TestPRTitle); + Octokit.PullRequest pullRequest = await this.gitHub.SubmitPullRequestAsync(manifests, this.SubmitPRToFork, TestConstants.TestPRTitle, false, null, root); Assert.That(TestConstants.TestPRTitle, Is.EqualTo(pullRequest.Title), TitleMismatch); await this.gitHub.ClosePullRequest(pullRequest.Number); StringAssert.StartsWith(string.Format(GitHubPullRequestBaseUrl, this.WingetPkgsTestRepoOwner, this.WingetPkgsTestRepo), pullRequest.HtmlUrl, PullRequestFailedToGenerate);