Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix auto-fill message showing on non-GitHub URLs #544

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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