Skip to content
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

Allow control over PR auto-open behavior #574

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions doc/new-locale.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
7 changes: 4 additions & 3 deletions doc/new.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions doc/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 1 addition & 0 deletions doc/submit.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/).
Expand Down
5 changes: 3 additions & 2 deletions doc/update-locale.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
3 changes: 2 additions & 1 deletion doc/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/WingetCreateCLI/Commands/BaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public abstract class BaseCommand
/// <summary>
/// Gets or sets a value indicating whether or not to automatically open the PR webpage in the browser after creation.
/// </summary>
public bool OpenPRInBrowser { get; set; } = true;
public bool OpenPRInBrowser { get; set; } = UserSettings.OpenPRInBrowser;

/// <summary>
/// Gets the GitHubClient instance to use for interacting with GitHub from the CLI.
Expand Down Expand Up @@ -740,7 +740,7 @@ protected async Task<bool> 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);
Expand Down
6 changes: 6 additions & 0 deletions src/WingetCreateCLI/Commands/NewCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public static IEnumerable<Example> Examples
[Option('t', "token", Required = false, HelpText = "GitHubToken_HelpText", ResourceType = typeof(Resources))]
public override string GitHubToken { get => base.GitHubToken; set => base.GitHubToken = value; }

/// <summary>
/// Gets or sets a value indicating whether the PR should be opened automatically in the browser.
/// </summary>
[Option('n', "no-open", Required = false, HelpText = "NoOpenPRInBrowser_HelpText", ResourceType = typeof(Resources))]
public bool NoOpenPRInBrowser { get => !this.OpenPRInBrowser; set => this.OpenPRInBrowser = !value; }

/// <summary>
/// Executes the new command flow.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions src/WingetCreateCLI/Commands/NewLocaleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ public static IEnumerable<Example> Examples
[Option('t', "token", Required = false, HelpText = "GitHubToken_HelpText", ResourceType = typeof(Resources))]
public override string GitHubToken { get => base.GitHubToken; set => base.GitHubToken = value; }

/// <summary>
/// Gets or sets a value indicating whether the PR should be opened automatically in the browser.
/// </summary>
[Option('n', "no-open", Required = false, HelpText = "NoOpenPRInBrowser_HelpText", ResourceType = typeof(Resources))]
public bool NoOpenPRInBrowser { get => !this.OpenPRInBrowser; set => this.OpenPRInBrowser = !value; }

/// <summary>
/// Executes the new-locale command flow.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions src/WingetCreateCLI/Commands/SubmitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ public static IEnumerable<Example> Examples
[Option('t', "token", Required = false, HelpText = "GitHubToken_HelpText", ResourceType = typeof(Resources))]
public override string GitHubToken { get => base.GitHubToken; set => base.GitHubToken = value; }

/// <summary>
/// Gets or sets a value indicating whether the PR should be opened automatically in the browser.
/// </summary>
[Option('n', "no-open", Required = false, HelpText = "NoOpenPRInBrowser_HelpText", ResourceType = typeof(Resources))]
public bool NoOpenPRInBrowser { get => !this.OpenPRInBrowser; set => this.OpenPRInBrowser = !value; }

/// <summary>
/// Gets or sets the unbound arguments that exist after the first positional parameter.
/// </summary>
Expand Down
11 changes: 10 additions & 1 deletion src/WingetCreateCLI/Commands/UpdateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ public static IEnumerable<Example> Examples
[Option('t', "token", Required = false, HelpText = "GitHubToken_HelpText", ResourceType = typeof(Resources))]
public override string GitHubToken { get => base.GitHubToken; set => base.GitHubToken = value; }

/// <summary>
/// Gets or sets a value indicating whether the PR should be opened automatically in the browser.
/// </summary>
[Option('n', "no-open", Required = false, HelpText = "NoOpenPRInBrowser_HelpText", ResourceType = typeof(Resources))]
public bool NoOpenPRInBrowser { get => !this.OpenPRInBrowser; set => this.OpenPRInBrowser = !value; }

/// <summary>
/// Gets or sets the new value(s) used to update the manifest installer elements.
/// </summary>
Expand Down Expand Up @@ -163,7 +169,10 @@ public override async Task<bool> 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))
{
Expand Down
6 changes: 6 additions & 0 deletions src/WingetCreateCLI/Commands/UpdateLocaleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ public static IEnumerable<Example> Examples
[Option('t', "token", Required = false, HelpText = "GitHubToken_HelpText", ResourceType = typeof(Resources))]
public override string GitHubToken { get => base.GitHubToken; set => base.GitHubToken = value; }

/// <summary>
/// Gets or sets a value indicating whether the PR should be opened automatically in the browser.
/// </summary>
[Option('n', "no-open", Required = false, HelpText = "NoOpenPRInBrowser_HelpText", ResourceType = typeof(Resources))]
public bool NoOpenPRInBrowser { get => !this.OpenPRInBrowser; set => this.OpenPRInBrowser = !value; }

/// <summary>
/// Executes the update-locale command flow.
/// </summary>
Expand Down
19 changes: 19 additions & 0 deletions src/WingetCreateCLI/Models/SettingsModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ public partial class Visual
public bool AnonymizePaths { get; set; } = true;


}

/// <summary>
/// Pull request settings
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "11.0.0.0 (Newtonsoft.Json v13.0.0.0)")]
public partial class PullRequest
{
/// <summary>
/// Controls whether the pull request is opened in the browser on submission
/// </summary>
[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)")]
Expand Down Expand Up @@ -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();


}

Expand Down
9 changes: 9 additions & 0 deletions src/WingetCreateCLI/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/WingetCreateCLI/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1395,4 +1395,7 @@
<data name="ConfirmZippedBinary_Message" xml:space="preserve">
<value>Does this executable depend on DLLs or any other files present in the zip archive?</value>
</data>
<data name="NoOpenPRInBrowser_HelpText" xml:space="preserve">
<value>Boolean value that controls whether the pull request should not be open in the browser on submission. Default is false.</value>
</data>
</root>
18 changes: 16 additions & 2 deletions src/WingetCreateCLI/Schemas/settings.schema.0.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
}
14 changes: 14 additions & 0 deletions src/WingetCreateCLI/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,20 @@ public static bool AnonymizePaths
}
}

/// <summary>
/// Gets or sets a value indicating whether the pull request should be opened automatically in the browser on submission.
/// </summary>
public static bool OpenPRInBrowser
{
get => Settings.PullRequest.OpenInBrowser;

set
{
Settings.PullRequest.OpenInBrowser = value;
SaveSettings();
}
}

private static SettingsManifest Settings { get; set; }

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