Skip to content

Commit

Permalink
Switch to known error codes constants in sync command
Browse files Browse the repository at this point in the history
  • Loading branch information
kzu committed Jun 8, 2024
1 parent 56d9493 commit e45c265
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
26 changes: 13 additions & 13 deletions src/Commands/SyncCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ public override async Task<int> ExecuteAsync(CommandContext context, SyncSetting
if (await client.QueryAsync(GraphQueries.ViewerSponsored) is not { } sponsored)
{
MarkupLine(Sync.QueryingUserSponsorshipsFailed);
return -2;
return ErrorCodes.GraphDiscoveryFailure;
}
sponsorables.AddRange(sponsored);
return 0;
}) == -2)
}) == ErrorCodes.GraphDiscoveryFailure)
{
return -2;
return ErrorCodes.GraphDiscoveryFailure;
}

sponsorables.AddRange((await client.GetUserContributionsAsync()).Keys);
Expand All @@ -100,13 +100,13 @@ public override async Task<int> ExecuteAsync(CommandContext context, SyncSetting
if (await client.QueryAsync(GraphQueries.ViewerOrganizations) is not { } viewerorgs)
{
MarkupLine(Sync.QueryingUserOrgsFailed);
return -2;
return ErrorCodes.GraphDiscoveryFailure;
}
orgs = viewerorgs;
return 0;
}) == -2)
}) == ErrorCodes.GraphDiscoveryFailure)
{
return -2;
return ErrorCodes.GraphDiscoveryFailure;
}

// Collect org-sponsored accounts. NOTE: we'll typically only get public sponsorships
Expand Down Expand Up @@ -141,11 +141,11 @@ await Status().StartAsync(Sync.FetchingManifests(sponsorables.Count), async ctx
manifests.Add(manifest);
break;
case SponsorableManifest.Status.NotFound:
result = -3;
result = ErrorCodes.SponsorableManifestNotFound;
break;
default:
MarkupLine(Sync.InvalidManifest(sponsorable, status));
result = -4;
result = ErrorCodes.SponsorableManifestInvalid;
break;
}
}
Expand All @@ -164,7 +164,7 @@ await Status().StartAsync(Sync.FetchingManifests(sponsorables.Count), async ctx
if (settings.Unattended)
{
MarkupLine(Sync.UnattendedWithInteractiveAuth(manifest.Sponsorable.PadRight(maxlength)));
result = -5;
result = ErrorCodes.InteractiveAuthRequired;
}
continue;
}
Expand All @@ -174,7 +174,7 @@ await Status().StartAsync(Sync.FetchingManifests(sponsorables.Count), async ctx
{
var links = string.Join(", ", manifest.Audience.Select(x => $"[link]{x}[/]"));
MarkupLine(Sync.ConsiderSponsoring(manifest.Sponsorable.PadRight(maxlength), links));
result = -6;
result = ErrorCodes.NotSponsoring;
continue;
}

Expand All @@ -186,7 +186,7 @@ await Status().StartAsync(Sync.FetchingManifests(sponsorables.Count), async ctx
else
{
MarkupLine(Sync.Failed(manifest.Sponsorable.PadRight(maxlength)));
result = -7;
result = ErrorCodes.SyncFailure;
continue;
}
}
Expand All @@ -210,7 +210,7 @@ await Status().StartAsync(Sync.Synchronizing(manifest.Sponsorable), async ctx =>
{
var links = string.Join(", ", manifest.Audience.Select(x => $"[link]{x}[/]"));
MarkupLine(Sync.ConsiderSponsoring(manifest.Sponsorable.PadRight(maxlength), links));
result = -6;
result = ErrorCodes.NotSponsoring;
}
else if (status == SponsorManifest.Status.Success)
{
Expand All @@ -220,7 +220,7 @@ await Status().StartAsync(Sync.Synchronizing(manifest.Sponsorable), async ctx =>
else
{
MarkupLine(Sync.Failed(manifest.Sponsorable.PadRight(maxlength)));
result = -7;
result = ErrorCodes.SyncFailure;
}
});
}
Expand Down
10 changes: 5 additions & 5 deletions src/Tests/SyncCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public async Task NoSponsorableOrLocalDiscoveryRunsGraphDiscoveryViewerSponsored

var result = await command.ExecuteAsync(new CommandContext(["sync"], Mock.Of<IRemainingArguments>(), "sync", null), settings);

Assert.Equal(-2, result);
Assert.Equal(SyncCommand.ErrorCodes.GraphDiscoveryFailure, result);
}

[LocalFact("GitHub:Token")]
Expand All @@ -103,7 +103,7 @@ public async Task NoSponsorableOrLocalDiscoveryRunsGraphDiscoveryViewerOrgs()

var result = await command.ExecuteAsync(new CommandContext(["sync"], Mock.Of<IRemainingArguments>(), "sync", null), settings);

Assert.Equal(-2, result);
Assert.Equal(SyncCommand.ErrorCodes.GraphDiscoveryFailure, result);
}

[LocalFact("GitHub:Token")]
Expand All @@ -130,7 +130,7 @@ public async Task ExplicitSponsorableSync_NoSponsorableManifest()

var result = await command.ExecuteAsync(new CommandContext(["sync"], Mock.Of<IRemainingArguments>(), "sync", null), settings);

Assert.Equal(-3, result);
Assert.Equal(SyncCommand.ErrorCodes.SponsorableManifestNotFound, result);
}

[LocalFact("GitHub:Token")]
Expand All @@ -157,7 +157,7 @@ public async Task ExplicitSponsorableSync_InvalidSponsorableManifest()

var result = await command.ExecuteAsync(new CommandContext(["sync"], Mock.Of<IRemainingArguments>(), "sync", null), settings);

Assert.Equal(-4, result);
Assert.Equal(SyncCommand.ErrorCodes.SponsorableManifestInvalid, result);
}

[SecretsFact("GitHub:NonSponsoring")]
Expand Down Expand Up @@ -186,7 +186,7 @@ public async Task ExplicitSponsorableSync_NonSponsoringUser()

var result = await command.ExecuteAsync(new CommandContext(["sync"], Mock.Of<IRemainingArguments>(), "sync", null), settings);

Assert.Equal(-6, result);
Assert.Equal(SyncCommand.ErrorCodes.NotSponsoring, result);
}

void EnsureAuthenticated(string secret = "GitHub:Token")
Expand Down

0 comments on commit e45c265

Please sign in to comment.