Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions doc/submit.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The following arguments are available:
| Argument | Description |
|--------------|-------------|
| **-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.

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
22 changes: 17 additions & 5 deletions src/WingetCreateCLI/Commands/SubmitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,29 @@ public static IEnumerable<Example> Examples
public string Path { get; set; }

/// <summary>
/// Gets or sets the GitHub token used to submit a pull request on behalf of the user.
/// Gets or sets the previous version to replace from the Windows Package Manager repository.
/// </summary>
[Option('t', "token", Required = false, HelpText = "GitHubToken_HelpText", ResourceType = typeof(Resources))]
public override string GitHubToken { get => base.GitHubToken; set => base.GitHubToken = value; }
[Value(1, MetaName = "ReplaceVersion", Required = false, HelpText = "ReplaceVersion_HelpText", ResourceType = typeof(Resources))]
public string ReplaceVersion { get; set; }

/// <summary>
/// Gets or sets the title for the pull request.
/// </summary>
[Option('p', "prtitle", Required = false, HelpText = "PullRequestTitle_HelpText", ResourceType = typeof(Resources))]
public override string PRTitle { get => base.PRTitle; set => base.PRTitle = value; }

/// <summary>
/// Gets or sets a value indicating whether or not to replace a previous version of the manifest with the update.
/// </summary>
[Option('r', "replace", Required = false, HelpText = "ReplacePrevious_HelpText", ResourceType = typeof(Resources))]
public bool Replace { get; set; }

/// <summary>
/// Gets or sets the GitHub token used to submit a pull request on behalf of the user.
/// </summary>
[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 the unbound arguments that exist after the first positional parameter.
/// </summary>
Expand Down Expand Up @@ -101,13 +113,13 @@ private async Task<bool> SubmitManifest()
{
Manifests manifests = new Manifests();
manifests.SingletonManifest = Serialization.DeserializeFromPath<SingletonManifest>(this.Path);
return await this.GitHubSubmitManifests(manifests, this.PRTitle);
return await this.GitHubSubmitManifests(manifests, this.PRTitle, this.Replace, this.ReplaceVersion);
}
else if (Directory.Exists(this.Path) && ValidateManifest(this.Path))
{
List<string> manifestContents = Directory.GetFiles(this.Path).Select(f => File.ReadAllText(f)).ToList();
Manifests manifests = Serialization.DeserializeManifestContents(manifestContents);
return await this.GitHubSubmitManifests(manifests, this.PRTitle);
return await this.GitHubSubmitManifests(manifests, this.PRTitle, this.Replace, this.ReplaceVersion);
}
else
{
Expand Down
16 changes: 16 additions & 0 deletions src/WingetCreateCLI/Commands/UpdateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,22 @@ public override async Task<bool> Execute()
return false;
}

var argumentsRequiringSubmit = new List<string> { nameof(this.PRTitle), nameof(this.Replace) };
bool submissionArgumentsUsed = !string.IsNullOrEmpty(this.PRTitle) || this.Replace;

if (submissionArgumentsUsed && !this.SubmitToGitHub)
{
Logger.ErrorLocalized(nameof(Resources.SubmitFlagRequired_ErrorMessage));
Console.WriteLine();

foreach (string argument in argumentsRequiringSubmit)
{
Logger.Error($"--{argument.ToLower()}");
}

return false;
}
Comment thread
mdanish-kh marked this conversation as resolved.
Outdated

Logger.DebugLocalized(nameof(Resources.RetrievingManifest_Message), this.Id);

string exactId;
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.

4 changes: 4 additions & 0 deletions src/WingetCreateCLI/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1237,4 +1237,8 @@
<data name="DownloadCommandProhibited_KeywordDescription" xml:space="preserve">
<value>Indicates whether the installer is prohibited from being downloaded for offline installation</value>
</data>
<data name="SubmitFlagRequired_ErrorMessage" xml:space="preserve">
<value>Submission arguments used without submit flag. The following options require passing in '-s' / '--submit':</value>
<comment>'-s / --submit' refers to a command line switch argument</comment>
</data>
</root>
10 changes: 9 additions & 1 deletion src/WingetCreateCore/Common/GitHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,15 @@ await retryPolicy.ExecuteAsync(async () =>
// Remove a previous manifest
if (shouldReplace)
{
await this.DeletePackageManifest(repo.Id, packageId, replaceVersion, newBranchName);
try
{
await this.DeletePackageManifest(repo.Id, packageId, replaceVersion, newBranchName);
}
catch (NotFoundException)
{
// If the path to the manifest folder being replaced does not exist, do nothing.
// This can happen with submit command when user submits a new package and path to its version directory does not exist yet.
}
Comment thread
mdanish-kh marked this conversation as resolved.
Outdated
}

// Get latest description template from repo
Expand Down