From a71cf9a6210283432a81dbdc7e8eef3171a31e8a Mon Sep 17 00:00:00 2001 From: Muhammad Danish Date: Wed, 7 Aug 2024 23:33:30 +0500 Subject: [PATCH] Fix auto-fill message showing on non-GitHub URLs (#544) --- src/WingetCreateCLI/Commands/NewCommand.cs | 7 +++++-- src/WingetCreateCLI/Commands/UpdateCommand.cs | 15 ++++++++++----- src/WingetCreateCore/Common/GitHub.cs | 14 +++++++++----- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/WingetCreateCLI/Commands/NewCommand.cs b/src/WingetCreateCLI/Commands/NewCommand.cs index 876b023..7968567 100644 --- a/src/WingetCreateCLI/Commands/NewCommand.cs +++ b/src/WingetCreateCLI/Commands/NewCommand.cs @@ -237,10 +237,13 @@ namespace Microsoft.WingetCreateCLI.Commands 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) diff --git a/src/WingetCreateCLI/Commands/UpdateCommand.cs b/src/WingetCreateCLI/Commands/UpdateCommand.cs index d81bfbe..2aa2701 100644 --- a/src/WingetCreateCLI/Commands/UpdateCommand.cs +++ b/src/WingetCreateCLI/Commands/UpdateCommand.cs @@ -467,11 +467,13 @@ namespace Microsoft.WingetCreateCLI.Commands 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) @@ -934,10 +936,13 @@ namespace Microsoft.WingetCreateCLI.Commands 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) diff --git a/src/WingetCreateCore/Common/GitHub.cs b/src/WingetCreateCore/Common/GitHub.cs index 6aaad00..2518e6e 100644 --- a/src/WingetCreateCore/Common/GitHub.cs +++ b/src/WingetCreateCore/Common/GitHub.cs @@ -236,14 +236,16 @@ namespace Microsoft.WingetCreateCore.Common /// /// Wrapper object for manifest object models to be populated with GitHub metadata. /// The output format of the manifest serializer. - /// A representing the asynchronous operation. - public async Task PopulateGitHubMetadata(Manifests manifests, string serializerFormat) + /// A representing the asynchronous operation. The task result is a boolean indicating whether metadata was successfully populated. + public async Task 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; } /// @@ -499,7 +501,7 @@ namespace Microsoft.WingetCreateCore.Common private static class GitHubManifestMetadata { - public static async Task PopulateManifestMetadata(Manifests manifests, string serializerFormat, GitHubClient client) + public static async Task PopulateManifestMetadata(Manifests manifests, string serializerFormat, GitHubClient client) { // Get owner and repo from the installer manifest GitHubUrlMetadata? metadata = GetMetadataFromGitHubUrl(manifests.InstallerManifest); @@ -507,7 +509,7 @@ namespace Microsoft.WingetCreateCore.Common if (metadata == null) { // Could not populate GitHub metadata. - return; + return false; } string owner = metadata.Value.Owner; @@ -574,6 +576,8 @@ namespace Microsoft.WingetCreateCore.Common }, }; } + + return true; } private static void SetReleaseDate(Manifests manifests, string serializerFormat, Release githubRelease)