Skip to content

Commit

Permalink
Nullcheck release expected asset (fixes #52)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchLeaders committed Aug 5, 2023
1 parent 2fe0274 commit 32c0e4a
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/NxEditor.Launcher/Helpers/GitHubRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ public static class GitHubRepo
public static async Task<(Stream stream, string tag)> GetRelease(long repoId, string assetName)
{
IReadOnlyList<Release> releases = await _githubClient.Repository.Release.GetAll(repoId);
Release latest = releases[0];

Release? latest = null;
ReleaseAsset? asset = null;

int index = -1;
while (asset == null || latest == null) {
index++;
latest = releases[index];
asset = latest.Assets.Where(x => x.Name == assetName).FirstOrDefault();
}

using HttpClient client = new();
return (await client.GetStreamAsync(latest.Assets
.Where(x => x.Name == assetName)
.First().BrowserDownloadUrl), latest.TagName);
return (await client.GetStreamAsync(asset.BrowserDownloadUrl), latest.TagName);
}

public static async Task<byte[]> GetAsset(string org, string repo, string assetPath)
Expand Down

0 comments on commit 32c0e4a

Please sign in to comment.