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

✨ Handle deprecated package id #22

Closed
wants to merge 1 commit into from
Closed
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
82 changes: 68 additions & 14 deletions PackageBuilder/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,6 @@ ListingSource MakeListingSourceFromManifest(VRCPackageManifest manifest)
);
}

// Add GitHub repos if included
if (listSource.githubRepos != null && listSource.githubRepos.Count > 0)
{
foreach (string ownerSlashName in listSource.githubRepos)
{
possibleReleaseUrls.AddRange(await GetReleaseZipUrlsFromGitHubRepo(ownerSlashName));
}
}

// Add each release url to the packages collection if it's not already in the listing, and its zip is valid
foreach (string url in possibleReleaseUrls)
{
Expand All @@ -189,6 +180,18 @@ ListingSource MakeListingSourceFromManifest(VRCPackageManifest manifest)
packages.Add(manifest);
}

// Add GitHub repos if included
// We handle them differently has they have a some verifications
if (listSource.githubRepos != null && listSource.githubRepos.Count > 0)
{
foreach (string ownerSlashName in listSource.githubRepos)
{
List<VRCPackageManifest> repoManifests = await GetReleaseManifestsFromGitHubRepo(ownerSlashName);
packages.AddRange(repoManifests);
}
}


// Copy listing-source.json to new Json Object
Serilog.Log.Information($"All packages prepared, generating Listing.");
var repoList = new VRCRepoList(packages)
Expand Down Expand Up @@ -293,7 +296,12 @@ GitHubClient Client
}
}

async Task<List<string>> GetReleaseZipUrlsFromGitHubRepo(string ownerSlashName)
/**
* Fetch the Github Releases Assets from Github
* We base our list on the latest package id
* If one of the releases id is different from the latest id, we will ignore the release
*/
async Task<List<VRCPackageManifest>> GetReleaseManifestsFromGitHubRepo(string ownerSlashName)
{
// Split string into owner and repo, or skip if invalid.
var parts = ownerSlashName.Split('/');
Expand All @@ -311,6 +319,32 @@ async Task<List<string>> GetReleaseZipUrlsFromGitHubRepo(string ownerSlashName)
Assert.Fail($"Could not get remote repo {owner}/{name}.");
return null;
}

Serilog.Log.Information($"Analyzing repo {owner}/{name}");

// Fetch the latest release id
var latestRelease = await Client.Repository.Release.GetLatest(owner, name);
if (latestRelease == null)
{
Serilog.Log.Information("Found no releases");
return null;
}

var latestReleaseAssetUrl = latestRelease.Assets.Where(asset => asset.Name.EndsWith(".zip")).Select(asset => asset.BrowserDownloadUrl).First();
if (latestReleaseAssetUrl == null)
{
Serilog.Log.Information("Found no valid asset in latest release");
return null;
}

var latestReleaseManifest = await HashZipAndReturnManifest(latestReleaseAssetUrl);
if (latestReleaseManifest == null)
{
Serilog.Log.Information("Found no valid manifest in latest release");
return null;
}
string latestReleasePackageId = latestReleaseManifest.Id;


// Go through each release
var releases = await Client.Repository.Release.GetAll(owner, name);
Expand All @@ -320,14 +354,34 @@ async Task<List<string>> GetReleaseZipUrlsFromGitHubRepo(string ownerSlashName)
return null;
}

var result = new List<string>();
var releaseUrlList = new List<string>();

foreach (Octokit.Release release in releases)
{
result.AddRange(release.Assets.Where(asset => asset.Name.EndsWith(".zip")).Select(asset => asset.BrowserDownloadUrl));
releaseUrlList.AddRange(release.Assets.Where(asset => asset.Name.EndsWith(".zip")).Select(asset => asset.BrowserDownloadUrl));
}

return result;
var manifestList = new List<VRCPackageManifest>();

foreach (string releaseUrl in releaseUrlList)
{
var manifest = await HashZipAndReturnManifest(releaseUrl);
if (manifest == null) {
Serilog.Log.Information($"Release package has no manifest. Ignoring. {releaseUrl}");
continue;
}

if (manifest.Id != latestReleasePackageId)
{
Serilog.Log.Information($"Release ({manifest.name} - {manifest.Version}) package id different from latest package id. Ignoring.");
continue;
}

Serilog.Log.Information($"Found {manifest.Id} ({manifest.name}) {manifest.Version}, adding to listing.");
manifestList.Add(manifest);
}

return manifestList;
}

// Keeping this for now to ensure existing listings are not broken
Expand Down Expand Up @@ -466,4 +520,4 @@ static HttpClient Http
},
};
}
}
}
Loading