Skip to content

Commit

Permalink
Fix auto-fill message showing on non-GitHub URLs (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdanish-kh authored Aug 7, 2024
1 parent a9411fd commit a71cf9a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
7 changes: 5 additions & 2 deletions src/WingetCreateCLI/Commands/NewCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,13 @@ public override async Task<bool> Execute()
ShiftRootFieldsToInstallerLevel(manifests.InstallerManifest);
try
{
Logger.InfoLocalized(nameof(Resources.PopulatingGitHubMetadata_Message));
if (this.GitHubClient != null)
{
await this.GitHubClient.PopulateGitHubMetadata(manifests, this.Format.ToString());
bool populated = await this.GitHubClient.PopulateGitHubMetadata(manifests, this.Format.ToString());
if (populated)
{
Logger.InfoLocalized(nameof(Resources.PopulatingGitHubMetadata_Message));
}
}
}
catch (Octokit.ApiException)
Expand Down
15 changes: 10 additions & 5 deletions src/WingetCreateCLI/Commands/UpdateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,13 @@ public async Task<Manifests> UpdateManifestsAutonomously(Manifests manifests)
ResetVersionSpecificFields(manifests);
try
{
Logger.InfoLocalized(nameof(Resources.PopulatingGitHubMetadata_Message));

if (this.GitHubClient != null)
{
await this.GitHubClient.PopulateGitHubMetadata(manifests, this.Format.ToString());
bool populated = await this.GitHubClient.PopulateGitHubMetadata(manifests, this.Format.ToString());
if (populated)
{
Logger.InfoLocalized(nameof(Resources.PopulatingGitHubMetadata_Message));
}
}
}
catch (Octokit.ApiException)
Expand Down Expand Up @@ -934,10 +936,13 @@ private async Task<Manifests> UpdateManifestsInteractively(Manifests manifests)
ResetVersionSpecificFields(manifests);
try
{
Logger.InfoLocalized(nameof(Resources.PopulatingGitHubMetadata_Message));
if (this.GitHubClient != null)
{
await this.GitHubClient.PopulateGitHubMetadata(manifests, this.Format.ToString());
bool populated = await this.GitHubClient.PopulateGitHubMetadata(manifests, this.Format.ToString());
if (populated)
{
Logger.InfoLocalized(nameof(Resources.PopulatingGitHubMetadata_Message));
}
}
}
catch (Octokit.ApiException)
Expand Down
14 changes: 9 additions & 5 deletions src/WingetCreateCore/Common/GitHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,16 @@ public async Task<string> FindPackageId(string packageId)
/// </summary>
/// <param name="manifests">Wrapper object for manifest object models to be populated with GitHub metadata.</param>
/// <param name="serializerFormat">The output format of the manifest serializer.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public async Task PopulateGitHubMetadata(Manifests manifests, string serializerFormat)
/// <returns>A <see cref="Task"/> representing the asynchronous operation. The task result is a boolean indicating whether metadata was successfully populated.</returns>
public async Task<bool> PopulateGitHubMetadata(Manifests manifests, string serializerFormat)
{
// Only populate metadata if we have a valid GitHub token.
if (this.github.Credentials.AuthenticationType != AuthenticationType.Anonymous)
{
await GitHubManifestMetadata.PopulateManifestMetadata(manifests, serializerFormat, this.github);
return await GitHubManifestMetadata.PopulateManifestMetadata(manifests, serializerFormat, this.github);
}

return false;
}

/// <summary>
Expand Down Expand Up @@ -499,15 +501,15 @@ private async Task DeletePullRequestBranch(int pullRequestId)

private static class GitHubManifestMetadata
{
public static async Task PopulateManifestMetadata(Manifests manifests, string serializerFormat, GitHubClient client)
public static async Task<bool> PopulateManifestMetadata(Manifests manifests, string serializerFormat, GitHubClient client)
{
// Get owner and repo from the installer manifest
GitHubUrlMetadata? metadata = GetMetadataFromGitHubUrl(manifests.InstallerManifest);

if (metadata == null)
{
// Could not populate GitHub metadata.
return;
return false;
}

string owner = metadata.Value.Owner;
Expand Down Expand Up @@ -574,6 +576,8 @@ public static async Task PopulateManifestMetadata(Manifests manifests, string se
},
};
}

return true;
}

private static void SetReleaseDate(Manifests manifests, string serializerFormat, Release githubRelease)
Expand Down

0 comments on commit a71cf9a

Please sign in to comment.