diff --git a/doc/new-locale.md b/doc/new-locale.md index e6d09e6..ac4e933 100644 --- a/doc/new-locale.md +++ b/doc/new-locale.md @@ -27,8 +27,9 @@ The following arguments are available: | **-l, --locale** | The package locale to create a new manifest for. If not provided, the tool will prompt you for this value. | **-r, --reference-locale** | Existing locale manifest to be used as reference for default values. If not provided, the default locale manifest will be used. | **-o, --out** | The output directory where the newly created manifests will be saved locally. -| **-f,--format** | Output format of the manifest. Default is "yaml". | -| **-t,--token** | GitHub personal access token used for direct submission to the Windows Package Manager repo | +| **-f, --format** | Output format of the manifest. Default is "yaml". | +| **-t, --token** | GitHub personal access token used for direct submission to the Windows Package Manager repo | +| **-n, --no-open** | Boolean value that controls whether the pull request should not be open in the browser on submission. Default is false, meaning the PR will be opened in the browser. | | **-?, --help** | Gets additional help on this command | Instructions on setting up GitHub Token for Winget-Create can be found [here](../README.md#github-personal-access-token-classic-permissions). diff --git a/doc/new.md b/doc/new.md index b368780..b473034 100644 --- a/doc/new.md +++ b/doc/new.md @@ -26,9 +26,10 @@ The following arguments are available: | Argument | Description | |--------------|-------------| -| **-o,--out** | The output directory where the newly created manifests will be saved locally | -| **-f,--format** | Output format of the manifest. Default is "yaml". | -| **-t,--token** | GitHub personal access token used for direct submission to the Windows Package Manager repo | +| **-o, --out** | The output directory where the newly created manifests will be saved locally | +| **-f, --format** | Output format of the manifest. Default is "yaml". | +| **-t, --token** | GitHub personal access token used for direct submission to the Windows Package Manager repo | +| **-n, --no-open** | Boolean value that controls whether the pull request should not be open in the browser on submission. Default is false, meaning the PR will be opened in the browser. | | **-?, --help** | Gets additional help on this command | ## Winget-Create New Command flow diff --git a/doc/settings.md b/doc/settings.md index b819f1f..77f7fc9 100644 --- a/doc/settings.md +++ b/doc/settings.md @@ -74,3 +74,31 @@ The `anonymizePaths` setting controls whether the paths of files and directories "anonymizePaths": true } ``` + +## Manifest + +The `Manifest` settings control the behavior of the Winget-Create CLI when creating a manifest. + +### format + +The `format` setting specifies the format of the manifest file that will be created. By default, this is set to `yaml`. The other supported format is `json`. The `--format` argument provided inline with the command will take precedence over this setting. + +```json + "Manifest": { + "format": "yaml" + } +``` + +## PullRequest + +The `PullRequest` settings control the behavior of the Winget-Create CLI when creating a pull request on the Windows Package Manager repository. + +### openInBrowser + +```json + "PullRequest": { + "openInBrowser": false + }, +``` + +If set to false, the `PullRequest.openInBrowser` setting will prevent the Winget-Create CLI from opening the pull request in the default browser after creating it. By default, this is set to true. The `--no-open` argument provided inline with the command will take precedence over this setting. diff --git a/doc/submit.md b/doc/submit.md index 6d70f56..c6115d8 100644 --- a/doc/submit.md +++ b/doc/submit.md @@ -18,6 +18,7 @@ The following arguments are available: | **-p, --prtitle** | The title of the pull request submitted to GitHub. | **-r, --replace** | Boolean value for replacing an existing manifest from the Windows Package Manager repo. Optionally provide a version or else the latest version will be replaced. Default is false. | **-t, --token** | GitHub personal access token used for direct submission to the Windows Package Manager repo. If no token is provided, tool will prompt for GitHub login credentials. +| **-n, --no-open** | Boolean value that controls whether the pull request should not be open in the browser on submission. Default is false, meaning the PR will be opened in the browser. | | **-?, --help** | Gets additional help on this command. | If you have provided your [GitHub token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) on the command line with the **submit** command and the device is registered with GitHub, **Winget-Create** will submit your PR to [Windows Package Manager repo](https://docs.microsoft.com/windows/package-manager/). diff --git a/doc/update-locale.md b/doc/update-locale.md index 3fc3311..25113e7 100644 --- a/doc/update-locale.md +++ b/doc/update-locale.md @@ -26,8 +26,9 @@ The following arguments are available: | **-v, --version** | The version of the package to update the locale for. Default is the latest version. | **-l, --locale** | The package locale to update the manifest for. If not provided, the tool will prompt you a list of existing locales to choose from. | **-o, --out** | The output directory where the newly created manifests will be saved locally. -| **-f,--format** | Output format of the manifest. Default is "yaml". | -| **-t,--token** | GitHub personal access token used for direct submission to the Windows Package Manager repo | +| **-f, --format** | Output format of the manifest. Default is "yaml". | +| **-t, --token** | GitHub personal access token used for direct submission to the Windows Package Manager repo | +| **-n, --no-open** | Boolean value that controls whether the pull request should not be open in the browser on submission. Default is false, meaning the PR will be opened in the browser. | | **-?, --help** | Gets additional help on this command | Instructions on setting up GitHub Token for Winget-Create can be found [here](../README.md#github-personal-access-token-classic-permissions). diff --git a/doc/update.md b/doc/update.md index 457a750..2458454 100644 --- a/doc/update.md +++ b/doc/update.md @@ -118,8 +118,9 @@ The following arguments are available: | **-s, --submit** | Boolean value for submitting to the Windows Package Manager repo. If true, updated manifest will be submitted directly using the provided GitHub Token | | **-r, --replace** | Boolean value for replacing an existing manifest from the Windows Package Manager repo. Optionally provide a version or else the latest version will be replaced. Default is false. | | **-i, --interactive** | Boolean value for making the update command interactive. If true, the tool will prompt the user for input. Default is false. | -| **-f,--format** | Output format of the manifest. Default is "yaml". | +| **-f, --format** | Output format of the manifest. Default is "yaml". | | **-t, --token** | GitHub personal access token used for direct submission to the Windows Package Manager repo. If no token is provided, tool will prompt for GitHub login credentials. | +| **-n, --no-open** | Boolean value that controls whether the pull request should not be open in the browser on submission. Default is false, meaning the PR will be opened in the browser. | | **-?, --help** | Gets additional help on this command. | ## Submit diff --git a/src/WingetCreateCLI/Commands/BaseCommand.cs b/src/WingetCreateCLI/Commands/BaseCommand.cs index c7e6ac1..9f261c4 100644 --- a/src/WingetCreateCLI/Commands/BaseCommand.cs +++ b/src/WingetCreateCLI/Commands/BaseCommand.cs @@ -99,7 +99,7 @@ public abstract class BaseCommand /// /// Gets or sets a value indicating whether or not to automatically open the PR webpage in the browser after creation. /// - public bool OpenPRInBrowser { get; set; } = true; + public bool OpenPRInBrowser { get; set; } = UserSettings.OpenPRInBrowser; /// /// Gets the GitHubClient instance to use for interacting with GitHub from the CLI. @@ -740,7 +740,7 @@ protected async Task GitHubSubmitManifests(Manifests manifests, string prT try { - PullRequest pullRequest = await this.GitHubClient.SubmitPullRequestAsync(manifests, this.SubmitPRToFork, prTitle, shouldReplace, replaceVersion); + Octokit.PullRequest pullRequest = await this.GitHubClient.SubmitPullRequestAsync(manifests, this.SubmitPRToFork, prTitle, shouldReplace, replaceVersion); this.PullRequestNumber = pullRequest.Number; PullRequestEvent pullRequestEvent = new PullRequestEvent { IsSuccessful = true, PullRequestNumber = pullRequest.Number }; TelemetryManager.Log.WriteEvent(pullRequestEvent); diff --git a/src/WingetCreateCLI/Commands/NewCommand.cs b/src/WingetCreateCLI/Commands/NewCommand.cs index 0a0b12b..629500d 100644 --- a/src/WingetCreateCLI/Commands/NewCommand.cs +++ b/src/WingetCreateCLI/Commands/NewCommand.cs @@ -86,6 +86,12 @@ public static IEnumerable Examples [Option('t', "token", Required = false, HelpText = "GitHubToken_HelpText", ResourceType = typeof(Resources))] public override string GitHubToken { get => base.GitHubToken; set => base.GitHubToken = value; } + /// + /// Gets or sets a value indicating whether the PR should be opened automatically in the browser. + /// + [Option('n', "no-open", Required = false, HelpText = "NoOpenPRInBrowser_HelpText", ResourceType = typeof(Resources))] + public bool NoOpenPRInBrowser { get => !this.OpenPRInBrowser; set => this.OpenPRInBrowser = !value; } + /// /// Executes the new command flow. /// diff --git a/src/WingetCreateCLI/Commands/NewLocaleCommand.cs b/src/WingetCreateCLI/Commands/NewLocaleCommand.cs index 6a25119..e7ef4be 100644 --- a/src/WingetCreateCLI/Commands/NewLocaleCommand.cs +++ b/src/WingetCreateCLI/Commands/NewLocaleCommand.cs @@ -98,6 +98,12 @@ public static IEnumerable Examples [Option('t', "token", Required = false, HelpText = "GitHubToken_HelpText", ResourceType = typeof(Resources))] public override string GitHubToken { get => base.GitHubToken; set => base.GitHubToken = value; } + /// + /// Gets or sets a value indicating whether the PR should be opened automatically in the browser. + /// + [Option('n', "no-open", Required = false, HelpText = "NoOpenPRInBrowser_HelpText", ResourceType = typeof(Resources))] + public bool NoOpenPRInBrowser { get => !this.OpenPRInBrowser; set => this.OpenPRInBrowser = !value; } + /// /// Executes the new-locale command flow. /// diff --git a/src/WingetCreateCLI/Commands/SubmitCommand.cs b/src/WingetCreateCLI/Commands/SubmitCommand.cs index 58dc331..292335f 100644 --- a/src/WingetCreateCLI/Commands/SubmitCommand.cs +++ b/src/WingetCreateCLI/Commands/SubmitCommand.cs @@ -67,6 +67,12 @@ public static IEnumerable Examples [Option('t', "token", Required = false, HelpText = "GitHubToken_HelpText", ResourceType = typeof(Resources))] public override string GitHubToken { get => base.GitHubToken; set => base.GitHubToken = value; } + /// + /// Gets or sets a value indicating whether the PR should be opened automatically in the browser. + /// + [Option('n', "no-open", Required = false, HelpText = "NoOpenPRInBrowser_HelpText", ResourceType = typeof(Resources))] + public bool NoOpenPRInBrowser { get => !this.OpenPRInBrowser; set => this.OpenPRInBrowser = !value; } + /// /// Gets or sets the unbound arguments that exist after the first positional parameter. /// diff --git a/src/WingetCreateCLI/Commands/UpdateCommand.cs b/src/WingetCreateCLI/Commands/UpdateCommand.cs index 1c4926d..aaeffbf 100644 --- a/src/WingetCreateCLI/Commands/UpdateCommand.cs +++ b/src/WingetCreateCLI/Commands/UpdateCommand.cs @@ -127,6 +127,12 @@ public static IEnumerable Examples [Option('t', "token", Required = false, HelpText = "GitHubToken_HelpText", ResourceType = typeof(Resources))] public override string GitHubToken { get => base.GitHubToken; set => base.GitHubToken = value; } + /// + /// Gets or sets a value indicating whether the PR should be opened automatically in the browser. + /// + [Option('n', "no-open", Required = false, HelpText = "NoOpenPRInBrowser_HelpText", ResourceType = typeof(Resources))] + public bool NoOpenPRInBrowser { get => !this.OpenPRInBrowser; set => this.OpenPRInBrowser = !value; } + /// /// Gets or sets the new value(s) used to update the manifest installer elements. /// @@ -163,7 +169,10 @@ public override async Task Execute() return false; } - bool submitFlagMissing = !this.SubmitToGitHub && (!string.IsNullOrEmpty(this.PRTitle) || this.Replace); + bool submitFlagMissing = !this.SubmitToGitHub && ( + !string.IsNullOrEmpty(this.PRTitle) || + this.Replace || + this.NoOpenPRInBrowser); if (!string.IsNullOrEmpty(this.ReleaseNotesUrl)) { diff --git a/src/WingetCreateCLI/Commands/UpdateLocaleCommand.cs b/src/WingetCreateCLI/Commands/UpdateLocaleCommand.cs index 4d9a0e8..e6f6e0e 100644 --- a/src/WingetCreateCLI/Commands/UpdateLocaleCommand.cs +++ b/src/WingetCreateCLI/Commands/UpdateLocaleCommand.cs @@ -78,6 +78,12 @@ public static IEnumerable Examples [Option('t', "token", Required = false, HelpText = "GitHubToken_HelpText", ResourceType = typeof(Resources))] public override string GitHubToken { get => base.GitHubToken; set => base.GitHubToken = value; } + /// + /// Gets or sets a value indicating whether the PR should be opened automatically in the browser. + /// + [Option('n', "no-open", Required = false, HelpText = "NoOpenPRInBrowser_HelpText", ResourceType = typeof(Resources))] + public bool NoOpenPRInBrowser { get => !this.OpenPRInBrowser; set => this.OpenPRInBrowser = !value; } + /// /// Executes the update-locale command flow. /// diff --git a/src/WingetCreateCLI/Models/SettingsModel.cs b/src/WingetCreateCLI/Models/SettingsModel.cs index 47f7f25..c6db8e5 100644 --- a/src/WingetCreateCLI/Models/SettingsModel.cs +++ b/src/WingetCreateCLI/Models/SettingsModel.cs @@ -96,6 +96,21 @@ public partial class Visual public bool AnonymizePaths { get; set; } = true; + } + + /// + /// Pull request settings + /// + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "11.0.0.0 (Newtonsoft.Json v13.0.0.0)")] + public partial class PullRequest + { + /// + /// Controls whether the pull request is opened in the browser on submission + /// + [Newtonsoft.Json.JsonProperty("openInBrowser", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public bool OpenInBrowser { get; set; } = true; + + } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "11.0.0.0 (Newtonsoft.Json v13.0.0.0)")] @@ -127,6 +142,10 @@ public partial class SettingsManifest [System.ComponentModel.DataAnnotations.Required] public Visual Visual { get; set; } = new Visual(); + [Newtonsoft.Json.JsonProperty("PullRequest", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + [System.ComponentModel.DataAnnotations.Required] + public PullRequest PullRequest { get; set; } = new PullRequest(); + } diff --git a/src/WingetCreateCLI/Properties/Resources.Designer.cs b/src/WingetCreateCLI/Properties/Resources.Designer.cs index 5e7fb4b..73e2bfd 100644 --- a/src/WingetCreateCLI/Properties/Resources.Designer.cs +++ b/src/WingetCreateCLI/Properties/Resources.Designer.cs @@ -2121,6 +2121,15 @@ public static string None_MenuItem { } } + /// + /// Looks up a localized string similar to Boolean value that controls whether the pull request should not be open in the browser on submission. Default is false.. + /// + public static string NoOpenPRInBrowser_HelpText { + get { + return ResourceManager.GetString("NoOpenPRInBrowser_HelpText", resourceCulture); + } + } + /// /// Looks up a localized string similar to No token provided, submission to GitHub skipped.. /// diff --git a/src/WingetCreateCLI/Properties/Resources.resx b/src/WingetCreateCLI/Properties/Resources.resx index c1faa83..1e84647 100644 --- a/src/WingetCreateCLI/Properties/Resources.resx +++ b/src/WingetCreateCLI/Properties/Resources.resx @@ -1395,4 +1395,7 @@ Does this executable depend on DLLs or any other files present in the zip archive? + + Boolean value that controls whether the pull request should not be open in the browser on submission. Default is false. + \ No newline at end of file diff --git a/src/WingetCreateCLI/Schemas/settings.schema.0.1.json b/src/WingetCreateCLI/Schemas/settings.schema.0.1.json index 3349f5b..6d42d9b 100644 --- a/src/WingetCreateCLI/Schemas/settings.schema.0.1.json +++ b/src/WingetCreateCLI/Schemas/settings.schema.0.1.json @@ -77,6 +77,18 @@ } }, "additionalProperties": false + }, + "PullRequest": { + "description": "Pull request settings", + "type": "object", + "properties": { + "openInBrowser": { + "description": "Controls whether the pull request is opened in the browser on submission", + "type": "boolean", + "default": true + } + }, + "additionalProperties": false } }, "type": "object", @@ -90,14 +102,16 @@ "CleanUp": { "$ref": "#/definitions/CleanUp" }, "WindowsPackageManagerRepository": { "$ref": "#/definitions/WindowsPackageManagerRepository" }, "Manifest": { "$ref": "#/definitions/Manifest" }, - "Visual": { "$ref": "#/definitions/Visual" } + "Visual": { "$ref": "#/definitions/Visual" }, + "PullRequest": { "$ref": "#/definitions/PullRequest" } }, "required": [ "Telemetry", "CleanUp", "WindowsPackageManagerRepository", "Manifest", - "Visual" + "Visual", + "PullRequest" ], "additionalProperties": false } \ No newline at end of file diff --git a/src/WingetCreateCLI/UserSettings.cs b/src/WingetCreateCLI/UserSettings.cs index 0ff3797..e70f4e4 100644 --- a/src/WingetCreateCLI/UserSettings.cs +++ b/src/WingetCreateCLI/UserSettings.cs @@ -133,6 +133,20 @@ public static bool AnonymizePaths } } + /// + /// Gets or sets a value indicating whether the pull request should be opened automatically in the browser on submission. + /// + public static bool OpenPRInBrowser + { + get => Settings.PullRequest.OpenInBrowser; + + set + { + Settings.PullRequest.OpenInBrowser = value; + SaveSettings(); + } + } + private static SettingsManifest Settings { get; set; } /// diff --git a/src/WingetCreateTests/WingetCreateTests/UnitTests/GitHubTests.cs b/src/WingetCreateTests/WingetCreateTests/UnitTests/GitHubTests.cs index c31a72e..96c91d2 100644 --- a/src/WingetCreateTests/WingetCreateTests/UnitTests/GitHubTests.cs +++ b/src/WingetCreateTests/WingetCreateTests/UnitTests/GitHubTests.cs @@ -103,7 +103,7 @@ public async Task GetLatestManifestAndSubmitPR() manifests.SingletonManifest = Serialization.DeserializeFromString(latestManifest.First()); Assert.That(manifests.SingletonManifest.PackageIdentifier, Is.EqualTo(TestConstants.TestPackageIdentifier), FailedToRetrieveManifestFromId); - PullRequest pullRequest = await this.gitHub.SubmitPullRequestAsync(manifests, this.SubmitPRToFork, TestConstants.TestPRTitle); + Octokit.PullRequest pullRequest = await this.gitHub.SubmitPullRequestAsync(manifests, this.SubmitPRToFork, TestConstants.TestPRTitle); 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); @@ -121,7 +121,7 @@ public async Task RemoveWhitespaceFromBranchName() Manifests manifests = Serialization.DeserializeManifestContents(manifestContents); Assert.That(manifests.SingletonManifest.PackageIdentifier, Is.EqualTo(packageId), FailedToRetrieveManifestFromId); - PullRequest pullRequest = new(); + Octokit.PullRequest pullRequest = new(); try { pullRequest = await this.gitHub.SubmitPullRequestAsync(manifests, this.SubmitPRToFork); diff --git a/src/WingetCreateTests/WingetCreateTests/UnitTests/SettingsCommandTests.cs b/src/WingetCreateTests/WingetCreateTests/UnitTests/SettingsCommandTests.cs index 174ddbc..9a9b08f 100644 --- a/src/WingetCreateTests/WingetCreateTests/UnitTests/SettingsCommandTests.cs +++ b/src/WingetCreateTests/WingetCreateTests/UnitTests/SettingsCommandTests.cs @@ -98,6 +98,7 @@ public void VerifySavingSettings() bool isTelemetryDisabled = UserSettings.TelemetryDisabled; bool isCleanUpDisabled = UserSettings.CleanUpDisabled; bool arePathsAnonymized = UserSettings.AnonymizePaths; + bool shouldPROpenInBrowser = UserSettings.OpenPRInBrowser; int cleanUpDays = 30; string testRepoOwner = "testRepoOwner"; string testRepoName = "testRepoName"; @@ -105,6 +106,7 @@ public void VerifySavingSettings() UserSettings.TelemetryDisabled = !isTelemetryDisabled; UserSettings.CleanUpDisabled = !isCleanUpDisabled; UserSettings.AnonymizePaths = !arePathsAnonymized; + UserSettings.OpenPRInBrowser = !shouldPROpenInBrowser; UserSettings.CleanUpDays = cleanUpDays; UserSettings.WindowsPackageManagerRepositoryOwner = testRepoOwner; UserSettings.WindowsPackageManagerRepositoryName = testRepoName; @@ -113,6 +115,7 @@ public void VerifySavingSettings() ClassicAssert.IsTrue(manifest.Telemetry.Disable == !isTelemetryDisabled, "Changed Telemetry setting was not reflected in the settings file."); ClassicAssert.IsTrue(manifest.CleanUp.Disable == !isCleanUpDisabled, "Changed CleanUp.Disable setting was not reflected in the settings file."); ClassicAssert.IsTrue(manifest.Visual.AnonymizePaths == !arePathsAnonymized, "Changed Visual.AnonymizePaths setting was not reflected in the settings file."); + ClassicAssert.IsTrue(manifest.PullRequest.OpenInBrowser == !shouldPROpenInBrowser, "Changed PullRequest.OpenPRInBrowser setting was not reflected in the settings file."); ClassicAssert.IsTrue(manifest.CleanUp.IntervalInDays == cleanUpDays, "Changed CleanUp.IntervalInDays setting was not reflected in the settings file."); ClassicAssert.IsTrue(manifest.WindowsPackageManagerRepository.Owner == testRepoOwner, "Changed WindowsPackageManagerRepository.Owner setting was not reflected in the settings file."); ClassicAssert.IsTrue(manifest.WindowsPackageManagerRepository.Name == testRepoName, "Changed WindowsPackageManagerRepository.Name setting was not reflected in the settings file."); diff --git a/src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs b/src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs index 9f516cf..9f484e1 100644 --- a/src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs +++ b/src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs @@ -317,6 +317,38 @@ public async Task UpdateChecksMissingSubmitFlagWithPRTitle() Assert.That(result, Does.Contain(Resources.SubmitFlagMissing_Warning), "Submit flag missing warning should be shown"); } + /// + /// Verify that update command warns if submit arguments are provided without submit flag being set. + /// + /// A representing the asynchronous unit test. + [Test] + public async Task UpdateChecksMissingSubmitFlagWithNoOpenPR() + { + string packageId = "TestPublisher.TestPackageId"; + string version = "1.2.3.4"; + + UpdateCommand command = new UpdateCommand + { + Id = packageId, + Version = version, + InstallerUrls = new[] { "https://fakedomain.com/fakeinstaller.exe" }, + SubmitToGitHub = false, + NoOpenPRInBrowser = true, + }; + + try + { + await command.Execute(); + } + catch (Exception) + { + // Expected exception + } + + string result = this.sw.ToString(); + Assert.That(result, Does.Contain(Resources.SubmitFlagMissing_Warning), "Submit flag missing warning should be shown"); + } + /// /// Since some installers are incorrectly labeled on the manifest, resort to using the installer URL to find matches. /// This unit test uses a msi installer that is not an arm64 installer, but because the installer URL includes "arm64", it should find a match.