Skip to content

Commit

Permalink
Use common pull request titles (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdanish-kh authored Jun 23, 2023
1 parent aac1dbf commit cfe5f71
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 10 deletions.
2 changes: 1 addition & 1 deletion doc/submit.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The following arguments are available:

| Argument | Description |
|--------------|-------------|
| **-p, --prtitle** | The title of the pull request submitted to GitHub. Default is "{PackageId} version {Version}"
| **-p, --prtitle** | The title of the pull request submitted to GitHub.
| **-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
2 changes: 1 addition & 1 deletion doc/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ The following arguments are available:
| **-v, --version** | Version to be used when updating the package version field.
| **-o, --out** | The output directory where the newly created manifests will be saved locally
| **-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
| **-p, --prtitle** | The title of the pull request submitted to GitHub. Default is "{PackageId} version {Version}"
| **-p, --prtitle** | The title of the pull request submitted to GitHub.
| **-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.
| **-?, --help** | Gets additional help on this command. |

Expand Down
40 changes: 39 additions & 1 deletion src/WingetCreateCLI/Commands/BaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public abstract class BaseCommand
/// Gets or sets the most recent pull request id associated with the command.
/// </summary>
public int PullRequestNumber { get; set; }

/// <summary>
/// Gets or sets the title for the pull request.
/// </summary>
public virtual string PRTitle { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not to submit the PR via a fork. Should be true when submitting as a user, false when submitting as an app.
Expand Down Expand Up @@ -578,7 +583,40 @@ protected async Task<bool> GitHubSubmitManifests(Manifests manifests, string prT
}

return true;
}
}

/// <summary>
/// Returns the title to be used for the pull request.
/// </summary>
/// <param name="currentManifest">Manifest object containing metadata of new manifest to be submitted.</param>
/// <param name="repositoryManifest">Manifest object representing an already exisitng manifest in the repository.</param>
/// <returns>A string representing the pull request title.</returns>
protected string GetPRTitle(Manifests currentManifest, Manifests repositoryManifest = null)
{
// Use custom PR title if provided by the user.
if (!string.IsNullOrEmpty(this.PRTitle))
{
return this.PRTitle;
}

string packageId = currentManifest.VersionManifest != null ? currentManifest.VersionManifest.PackageIdentifier : currentManifest.SingletonManifest.PackageIdentifier;
string currentVersion = currentManifest.VersionManifest != null ? currentManifest.VersionManifest.PackageVersion : currentManifest.SingletonManifest.PackageVersion;

// If no manifest exists in the repository, this is a new package.
if (repositoryManifest == null)
{
return $"New package: {packageId} version {currentVersion}";
}

string repositoryVersion = repositoryManifest.VersionManifest != null ? repositoryManifest.VersionManifest.PackageVersion : repositoryManifest.SingletonManifest.PackageVersion;

return WinGetUtil.CompareVersions(currentVersion, repositoryVersion) switch
{
> 0 => $"New version: {packageId} version {currentVersion}",
< 0 => $"Add version: {packageId} version {currentVersion}",
_ => $"Update version: {packageId} version {currentVersion}",
};
}

/// <summary>
/// Removes fields with empty string values from a given object.
Expand Down
4 changes: 3 additions & 1 deletion src/WingetCreateCLI/Commands/NewCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ public override async Task<bool> Execute()
{
if (await this.LoadGitHubClient(true))
{
return commandEvent.IsSuccessful = await this.GitHubSubmitManifests(manifests);
return commandEvent.IsSuccessful = await this.GitHubSubmitManifests(
manifests,
this.GetPRTitle(manifests));
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion src/WingetCreateCLI/Commands/SubmitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static IEnumerable<Example> Examples
/// Gets or sets the title for the pull request.
/// </summary>
[Option('p', "prtitle", Required = false, HelpText = "PullRequestTitle_HelpText", ResourceType = typeof(Resources))]
public string PRTitle { get; set; }
public override string PRTitle { get => base.PRTitle; set => base.PRTitle = value; }

/// <summary>
/// Gets or sets the unbound arguments that exist after the first positional parameter.
Expand Down
6 changes: 4 additions & 2 deletions src/WingetCreateCLI/Commands/UpdateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static IEnumerable<Example> Examples
/// Gets or sets the title for the pull request.
/// </summary>
[Option('p', "prtitle", Required = false, HelpText = "PullRequestTitle_HelpText", ResourceType = typeof(Resources))]
public string PRTitle { get; set; }
public override string PRTitle { get => base.PRTitle; set => base.PRTitle = value; }

/// <summary>
/// Gets or sets a value indicating whether or not the updated manifest should be submitted to Github.
Expand Down Expand Up @@ -206,7 +206,9 @@ await this.UpdateManifestsInteractively(initialManifests) :
}

return await this.LoadGitHubClient(true)
? (commandEvent.IsSuccessful = await this.GitHubSubmitManifests(updatedManifests, this.PRTitle))
? (commandEvent.IsSuccessful = await this.GitHubSubmitManifests(
updatedManifests,
this.GetPRTitle(updatedManifests, originalManifests)))
: false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/WingetCreateCLI/Properties/Resources.Designer.cs

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

2 changes: 1 addition & 1 deletion src/WingetCreateCLI/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@
<value>The publisher name |e.g. Microsoft|</value>
</data>
<data name="PullRequestTitle_HelpText" xml:space="preserve">
<value>The title of the pull request submitted to GitHub. Default is "{PackageId} version {Version}"</value>
<value>The title of the pull request submitted to GitHub.</value>
</data>
<data name="PullRequestURI_Message" xml:space="preserve">
<value>Pull request can be found here: {0}</value>
Expand Down
2 changes: 1 addition & 1 deletion src/WingetCreateCore/Common/GitHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private async Task<PullRequest> SubmitPRAsync(string packageId, string version,
repo = await this.github.Repository.Get(this.wingetRepoOwner, this.wingetRepo);
}

string newBranchName = $"autogenerated/{packageId}/{Guid.NewGuid()}";
string newBranchName = $"{packageId}-{version}-{Guid.NewGuid()}";
string newBranchNameHeads = $"heads/{newBranchName}";

if (string.IsNullOrEmpty(prTitle))
Expand Down

0 comments on commit cfe5f71

Please sign in to comment.