-
Notifications
You must be signed in to change notification settings - Fork 13
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
Adding support for json output #191
base: main
Are you sure you want to change the base?
Conversation
Bump xunit from 2.7.0 to 2.7.1 Bumps [xunit](https://github.com/xunit/xunit) from 2.7.0 to 2.7.1. - [Commits](xunit/xunit@2.7.0...2.7.1) --- updated-dependencies: - dependency-name: xunit dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Bump xunit.runner.visualstudio from 2.5.7 to 2.5.8 Bumps [xunit.runner.visualstudio](https://github.com/xunit/visualstudio.xunit) from 2.5.7 to 2.5.8. - [Release notes](https://github.com/xunit/visualstudio.xunit/releases) - [Commits](xunit/visualstudio.xunit@2.5.7...2.5.8) --- updated-dependencies: - dependency-name: xunit.runner.visualstudio dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Bump Spectre.Console.Testing and Spectre.Console.Cli Bumps [Spectre.Console.Testing](https://github.com/spectreconsole/spectre.console) and [Spectre.Console.Cli](https://github.com/spectreconsole/spectre.console). These dependencies needed to be updated together. Updates `Spectre.Console.Testing` from 0.48.0 to 0.49.0 - [Release notes](https://github.com/spectreconsole/spectre.console/releases) - [Commits](spectreconsole/spectre.console@0.48.0...0.49.0) Updates `Spectre.Console.Cli` from 0.48.0 to 0.49.0 - [Release notes](https://github.com/spectreconsole/spectre.console/releases) - [Commits](spectreconsole/spectre.console@0.48.0...0.49.0) --- updated-dependencies: - dependency-name: Spectre.Console.Testing dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: Spectre.Console.Cli dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Bump Spectre.Console.Cli from 0.48.0 to 0.49.0 Bumps [Spectre.Console.Cli](https://github.com/spectreconsole/spectre.console) from 0.48.0 to 0.49.0. - [Release notes](https://github.com/spectreconsole/spectre.console/releases) - [Commits](spectreconsole/spectre.console@0.48.0...0.49.0) --- updated-dependencies: - dependency-name: Spectre.Console.Cli dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Bump Spectre.Console.Cli from 0.49.0 to 0.49.1 Bumps [Spectre.Console.Cli](https://github.com/spectreconsole/spectre.console) from 0.49.0 to 0.49.1. - [Release notes](https://github.com/spectreconsole/spectre.console/releases) - [Commits](spectreconsole/spectre.console@0.49.0...0.49.1) --- updated-dependencies: - dependency-name: Spectre.Console.Cli dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Bump Spectre.Console.Testing from 0.49.0 to 0.49.1 Bumps [Spectre.Console.Testing](https://github.com/spectreconsole/spectre.console) from 0.49.0 to 0.49.1. - [Release notes](https://github.com/spectreconsole/spectre.console/releases) - [Commits](spectreconsole/spectre.console@0.49.0...0.49.1) --- updated-dependencies: - dependency-name: Spectre.Console.Testing dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Bump xunit from 2.7.1 to 2.8.0 Bumps [xunit](https://github.com/xunit/xunit) from 2.7.1 to 2.8.0. - [Commits](xunit/xunit@2.7.1...2.8.0) --- updated-dependencies: - dependency-name: xunit dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Bump xunit.runner.visualstudio from 2.5.8 to 2.8.0 Bumps [xunit.runner.visualstudio](https://github.com/xunit/visualstudio.xunit) from 2.5.8 to 2.8.0. - [Release notes](https://github.com/xunit/visualstudio.xunit/releases) - [Commits](xunit/visualstudio.xunit@2.5.8...2.8.0) --- updated-dependencies: - dependency-name: xunit.runner.visualstudio dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]>
At the moment this project only supports output to a table. While fantastic for human readability, it leads something to be desired when it comes to machine readability. Use: `dotnet libyear` > Prints using table output in console `dotnet libyear -o console` > Prints using table output in console `dotnet run -o json` > Prints indented json `dotnet libyear -o json -q` > Prints non-indented json This is currently useful to me as I would like to be able to run this project against several code bases in a single parse and easily collate the results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Doug, thanks for taking the time to submit this PR!
Something of this size will likely have multiple iterations of review, just letting you know up front so there is a mutual understanding of commitment.
The big note to start off with is test coverage: can you please ensure that all new code branches have a unit test showing their intended correctness?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for these changes, we're getting there! I resolved a bunch of conversations and left the outstanding ones open.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, almost there!
CurrentVersion = result.Installed is null ? null : new DisplayVersion(result.Installed); | ||
LatestVersion = result.Latest is null ? null : new DisplayVersion(result.Latest); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we invert these ternaries (... is not null
) to keep them in line with the others?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(this one might be moot now if the whole class disappears)
|
||
namespace LibYear.Output.Json; | ||
|
||
internal sealed class DoubleFormatter : JsonConverter<double> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add some tests for this bad boy as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we also name it DoubleConverter
to match the convention of the base class and DateTimeConverter
?
public string VersionNumber { get; init; } = string.Empty; | ||
[JsonPropertyName("releaseDate")] | ||
public DateTime ReleaseDate { get; init; } | ||
public DisplayVersion(Release release) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just use the underlying Release
here? Might require a JsonConverter<PackageVersion>
that returns its ToString()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to put full release there, but given everything is currently public
, everything would get included
That would currently look like
{
"YearsBehind": 0,
"DaysBehind": 0,
"Projects": [
{
"Project": "test project 1",
"YearsBehind": 0,
"Packages": [
{
"PackageName": "test1",
"CurrentVersion": {
"versionNumber": "1.2.3",
"releaseDate": "2024-05-30",
"Release": {
"Version": {
"WildcardType": 0,
"Version": "1.2.3.0",
"IsLegacyVersion": false,
"Revision": 0,
"IsSemVer2": false,
"OriginalVersion": null,
"Major": 1,
"Minor": 2,
"Patch": 3,
"ReleaseLabels": [],
"Release": "",
"IsPrerelease": false,
"HasMetadata": false,
"Metadata": null
},
"Date": "2024-05-30",
"IsPublished": true
}
}
}
]
}
]
}
Is there anything that would to be removed/hidden/etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, should have been clearer here. Can we just use more of the existing model objects/classes in the JSON above?
Packages
becomes an array ofResult
Release
(of whichResult
has 2,Installed
andLatest
) contains aPackageVersion
- Could that
PackageVersion
use aJsonConverter<PackageVersion>
that returns just theToString()
interpretation of the version? (I may not have a proper understanding ofJsonConverter<T>
)
So the JSON from above would look like:
{
"YearsBehind": 0,
"Projects": [
{
"Project": "test project 1",
"YearsBehind": 0,
"Packages": [
{
"Name": "test1",
"Installed": {
"Version": "1.2.3",
"Date": "2024-05-30",
"IsPublished": true
},
"Latest": {
"Version": "1.2.3",
"Date": "2024-05-30",
"IsPublished": true
}
}
]
}
]
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So close, a big potential cleanup if my understanding is correct 🤞🏻
Test = new DateTime(2020, 01, 01) | ||
}; | ||
private static string ExpectedJson = @"{""Test"":""2020-01-01""}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make sure the month and day are different numbers, just to ensure that a change to yyyy-dd-MM
should fail the tests
|
||
namespace LibYear.Tests.Output.Json; | ||
|
||
public class DoubleConverterTests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this has a bunch of copypasta leftovers from DateTimeConverterTests
😅
Can we also make sure the test object contains a number with more than one decimal, so that we're testing the rounding properly?
CurrentVersion = result.Installed is null ? null : new DisplayVersion(result.Installed); | ||
LatestVersion = result.Latest is null ? null : new DisplayVersion(result.Latest); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(this one might be moot now if the whole class disappears)
7265994
to
ef5b6e1
Compare
418fc5f
to
2aef06b
Compare
74c80f4
to
b8d9278
Compare
565f89c
to
5fd8905
Compare
46bc9bd
to
cbe40e9
Compare
At the moment this project only supports output to a table. While fantastic for human readability, it leads something to be desired when it comes to machine readability.
Use:
dotnet libyear
> Prints using table output in consoledotnet libyear -o console
> Prints using table output in consoledotnet run -o json
> Prints indented jsondotnet libyear -o json -q
> Prints non-indented jsonThis is currently useful to me as I would like to be able to run this project against several code bases in a single parse and easily collate the results.
Ideal state may also include hiding the progress bar when searching for results, but I was unsure if that would be valuable/helpful at all.