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

GitHub warning annotations #432

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

timkrins
Copy link

@timkrins timkrins commented Jan 12, 2025

I don't think this is the perfect PR, but more created it as a point of discussion (and for my own use, as it solves my immediate use-case).

Adds a report generator that prints GitHub style annotations to stdout.

Right now, only warning is supported - I couldn't immediately determine how to pass a command line switch to the generator without changing the base class.

Screenshot of diff-cover coverage.lcov --github-warning-annotations running in GitHub actions
Screenshot 2025-01-12 at 10 36 30
Screenshot 2025-01-12 at 11 15 53

@timkrins timkrins mentioned this pull request Jan 12, 2025
@@ -92,6 +94,13 @@ def parse_coverage_args(argv):
help=MARKDOWN_REPORT_HELP,
)

parser.add_argument(
"--github-warning-annotations",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given the idea of moving to a plugin type framework, maybe this should be implemented as a top level --format flag, similar to some other programs, so that it's possible to do --format github-native or --format xyz?

There would have to be discussion then about whether multiple formats are allowed (and if so, how)... for example, would it allow --format json,markdown,github-native or multiple instances of the same flag, something like --format github-native --format markdown:foo.md (the latter case allowing specifying the format and filename together)? If it's too invasive to take over the markdown / json / etc. reports, could at least have a single flag to control all stdout / stderr reporting.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I like this

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will say if we move to this style then we should have it support the existing formats as well as the new one.

We kinda have to keep the existing flags to avoid breaking compatibility, but if we are going to be adding more then moving to something like this makes sense

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually started down the path of attempting to pass something like --github-annotations=warning or --github-annotations=error.
But I saw that customizing the context that is passed to jinja template for specific template generators wasn't so easy to adapt.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timkrins if you wanted to have that context could that be achieved by adding some kind of context parameter to the init of BaseReportGenerator?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe - I'll try have a go later in the week

@Bachmann1234
Copy link
Owner

So at a high level this seems like a useful feature. I have a hard time thinking about new diff-cover/diff-quality features since I dont really use these tools anymore. I just maintain the project.

But it looks like Github annotations introduce some level of customizability (whats a warning, whats an error, whats a message). My gut is the approach taken here "Everything is a warning" seems reasonable. However, if others start using it I suspect the desire for customization will come up shortly after.

I think im happy to merge in a "everything is a warning" pr. Do yall think there will be much demand for further customization? Do you think we could get away with "look, the flag will do the basics but if you have more complex demands that config needs to be defined in some config file"?

@wyardley
Copy link

For the use case like sqlfluff, both errors and warnings would be ideal.

Being able to add code suggestions is also useful, though I suspect most people will use a tool like reviewdog instead for that.

@timkrins timkrins marked this pull request as ready for review January 21, 2025 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants