Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/WingetCreateCLI/Commands/BaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -741,12 +741,12 @@ protected async Task<bool> CheckGitHubTokenAndSetClient()
/// Submits a pull request with multifile manifests using the user's GitHub access token.
/// </summary>
/// <param name="manifests">Wrapper object for manifest object models to be submitted.</param>
/// <param name="manifestRoot">Manifest root name.</param>
/// <param name="prTitle">Optional parameter specifying the title for the pull request.</param>
/// <param name="shouldReplace">Optional parameter specifying whether the new submission should replace an existing manifest.</param>
/// <param name="replaceVersion">Optional parameter specifying the version of the manifest to be replaced.</param>
/// <param name="manifestRoot">Manifest root name.</param>
/// <returns>A <see cref="Task"/> representing the success of the asynchronous operation.</returns>
protected async Task<bool> GitHubSubmitManifests(Manifests manifests, string manifestRoot = Constants.WingetManifestRoot, string prTitle = null, bool shouldReplace = false, string replaceVersion = null)
protected async Task<bool> 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 &&
Expand All @@ -768,7 +768,7 @@ protected async Task<bool> 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);
Expand Down
4 changes: 2 additions & 2 deletions src/WingetCreateCLI/Commands/SubmitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private async Task<bool> 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))
{
Expand All @@ -145,7 +145,7 @@ private async Task<bool> 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
{
Expand Down
4 changes: 2 additions & 2 deletions src/WingetCreateCLI/Commands/UpdateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
14 changes: 12 additions & 2 deletions src/WingetCreateCore/Common/GitHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ public async Task<List<string>> GetManifestContentAsync(string packageId, string
/// </summary>
/// <param name="manifests">Wrapper object for manifest object models to be submitted in the PR.</param>
/// <param name="submitToFork">Bool indicating whether or not to submit the PR via a fork.</param>
/// <param name="manifestRoot">The manifest root name.</param>
/// <param name="prTitle">Optional parameter specifying the title for the pull request.</param>
/// <param name="shouldReplace">Optional parameter specifying whether the new submission should replace an existing manifest.</param>
/// <param name="replaceVersion">Optional parameter specifying the version of the manifest to be replaced.</param>
/// <param name="manifestRoot">The manifest root name.</param>
/// <returns>Pull request object.</returns>
public Task<PullRequest> SubmitPullRequestAsync(Manifests manifests, bool submitToFork, string manifestRoot = Constants.WingetManifestRoot, string prTitle = null, bool shouldReplace = false, string replaceVersion = null)
public Task<PullRequest> SubmitPullRequestAsync(Manifests manifests, bool submitToFork, string prTitle = null, bool shouldReplace = false, string replaceVersion = null, string manifestRoot = Constants.WingetManifestRoot)
{
Dictionary<string, string> contents = new Dictionary<string, string>();
string id;
Expand Down Expand Up @@ -191,6 +191,16 @@ public async Task ClosePullRequest(int pullRequestId)
await this.DeletePullRequestBranch(pullRequestId);
}

/// <summary>
/// Retrieves a pull request based on the provided pull request id.
/// </summary>
/// <param name="pullRequestId">The pull request number.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public async Task<Octokit.PullRequest> GetPullRequest(int pullRequestId)
{
return await this.github.PullRequest.Get(this.wingetRepoOwner, this.wingetRepo, pullRequestId);
}

/// <summary>
/// Merges an open pull request.
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions src/WingetCreateTests/WingetCreateTests/E2ETests/E2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

Expand All @@ -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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public async Task GetLatestManifestAndSubmitPR()
manifests.SingletonManifest = Serialization.DeserializeFromString<SingletonManifest>(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);
Expand Down