Skip to content

Commit

Permalink
✨ Handle deprecated package id
Browse files Browse the repository at this point in the history
Update the GitHub Repository import.

Will pull the latest release and keep the manifest package id.

If any earlier package id has a different package id, the release will be ignored.
  • Loading branch information
Spokeek authored Oct 25, 2023
1 parent a9b5185 commit 2e2ab9c
Showing 1 changed file with 68 additions and 14 deletions.
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
},
};
}
}
}

0 comments on commit 2e2ab9c

Please sign in to comment.