Skip to content

Commit

Permalink
Deal with exception when we don't get any versions back
Browse files Browse the repository at this point in the history
  • Loading branch information
ermshiperete committed Jul 24, 2019
1 parent 4b025a9 commit 5d6b735
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [1.1.1] - 2019-07-24

### Fixed

- deal with exception when we don't get any versions back

## [1.1.0] - 2019-07-24

### Added
Expand Down
10 changes: 9 additions & 1 deletion SIL.NuGetCleaner/NuGetPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,24 @@ public async Task<List<SemanticVersion>> GetVersions()
var responseBody = await HttpClient.SendAsync(request);
var responseString = await responseBody.Content.ReadAsStringAsync();
_nugetPackageJson = JsonConvert.DeserializeObject(responseString);
CurrentVersion = SemanticVersion.Parse(_nugetPackageJson.data[0].version.ToString());
if (_nugetPackageJson.data.Count <= 0)
return null;

var versionString = _nugetPackageJson.data[0].version.ToString();
CurrentVersion = SemanticVersion.Parse(versionString);
var jsonVersions = _nugetPackageJson.data[0].versions as JArray;
_versions = jsonVersions.Select(versionInfo =>
SemanticVersion.Parse(versionInfo["version"].ToString())).ToList();
return _versions;

}

public async Task<List<SemanticVersion>> GetPrereleaseVersionsToDelete()
{
var versions = await GetVersions();
if (versions == null)
return null;

var prereleaseVersions = new List<SemanticVersion>();
foreach (var semVer in versions)
{
Expand Down
5 changes: 5 additions & 0 deletions SIL.NuGetCleaner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ private static async Task Execute(Options options)
var nugetPackage = new NuGetPackage(options.PackageId, options.ApiKey,
options.Minimum, options.Maximum);
var versionsToDelete = await nugetPackage.GetPrereleaseVersionsToDelete();
if (versionsToDelete == null)
{
Console.WriteLine($"ERROR: Can't find any versions for {options.PackageId}");
return;
}
if (versionsToDelete.Count == 0)
{
Console.WriteLine("No obsolete pre-release versions found.");
Expand Down

0 comments on commit 5d6b735

Please sign in to comment.