From 239ddcfe58be7cb42cd427f365afeb2f88470e5a Mon Sep 17 00:00:00 2001 From: Muhammad Danish <88161975+mdanish-kh@users.noreply.github.com> Date: Wed, 7 Aug 2024 20:38:05 +0500 Subject: [PATCH] Fix auto-fill message showing on non-GitHub URLs --- 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 876b023a..7968567b 100644 --- a/src/WingetCreateCLI/Commands/NewCommand.cs +++ b/src/WingetCreateCLI/Commands/NewCommand.cs @@ -237,10 +237,13 @@ public override async Task 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) diff --git a/src/WingetCreateCLI/Commands/UpdateCommand.cs b/src/WingetCreateCLI/Commands/UpdateCommand.cs index d81bfbe7..2aa27016 100644 --- a/src/WingetCreateCLI/Commands/UpdateCommand.cs +++ b/src/WingetCreateCLI/Commands/UpdateCommand.cs @@ -467,11 +467,13 @@ public async Task 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) @@ -934,10 +936,13 @@ private async Task 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) diff --git a/src/WingetCreateCore/Common/GitHub.cs b/src/WingetCreateCore/Common/GitHub.cs index 6aaad00e..2518e6e2 100644 --- a/src/WingetCreateCore/Common/GitHub.cs +++ b/src/WingetCreateCore/Common/GitHub.cs @@ -236,14 +236,16 @@ public async Task FindPackageId(string packageId) /// /// 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 @@ 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 PopulateManifestMetadata(Manifests manifests, string serializerFormat, GitHubClient client) { // Get owner and repo from the installer manifest GitHubUrlMetadata? metadata = GetMetadataFromGitHubUrl(manifests.InstallerManifest); @@ -507,7 +509,7 @@ public static async Task PopulateManifestMetadata(Manifests manifests, string se if (metadata == null) { // Could not populate GitHub metadata. - return; + return false; } string owner = metadata.Value.Owner; @@ -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)