-
Notifications
You must be signed in to change notification settings - Fork 2
Add sarif support to Invert using sarif4k #60
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
Conversation
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.
Pull Request Overview
This pull request adds SARIF report support to Invert using the sarif4k library. Key changes include the introduction of InvertSarifReportWriter to generate SARIF files, integration of SARIF reporting in existing report writers and stat aggregation, and updating related file utils and build files to support SARIF output.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/report/sarif/InvertSarifReportWriter.kt | New writer for SARIF reports using sarif4k |
| invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/report/InvertReportWriter.kt | Integration of SARIF report generation alongside JS/HTML reports |
| invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/models/InvertPluginFileKey.kt | Addition of a new STATS_SARIF file key |
| invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/InvertFileUtils.kt | New constant for SARIF folder */ |
| invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/CollectedStatAggregator.kt | Added static SARIF report generation for stat data |
| invert-gradle-plugin/build.gradle.kts | Added dependency on sarif4k |
...-plugin/src/main/kotlin/com/squareup/invert/internal/report/sarif/InvertSarifReportWriter.kt
Outdated
Show resolved
Hide resolved
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.
Pull Request Overview
This PR adds SARIF report support to the invert-gradle-plugin by integrating the sarif4k library and providing utilities and writers to generate SARIF-compliant output alongside existing reports.
- Introduces
InvertSarifReportWriterandInvertSarifUtilsto convert statistics into SARIF format. - Integrates SARIF generation in
InvertReportWriterandCollectedStatAggregator. - Updates build and file utilities to support SARIF files.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| InvertSarifReportWriterTest.kt | Adds tests for SARIF report writer functionality |
| InvertSarifUtils.kt | Defines extension functions to map stats to SARIF structures |
| InvertSarifReportWriter.kt | Implements writing SARIF files using sarif4k serializer |
| InvertReportWriter.kt | Calls SARIF writer as part of overall report generation |
| InvertPluginFileKey.kt | Adds new enum key for SARIF report files |
| InvertFileUtils.kt | Introduces folder constant for SARIF reports |
| CollectedStatAggregator.kt | Emits individual SARIF files for code references |
| build.gradle.kts | Adds sarif4k dependency |
Comments suppressed due to low confidence (5)
invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/models/InvertPluginFileKey.kt:18
- [nitpick] The display name for
STATS_SARIFis generic ("Stats"); consider renaming it to something like"Stats SARIF"for clarity.
STATS_SARIF("stats.sarif", "Stats"),
invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/report/sarif/InvertSarifUtils.kt:30
- There are no unit tests covering the
asSarifResultanddetermineSourceLanguageextension functions. Consider adding tests for these to ensure correct mapping for various file extensions and stat types.
fun Stat.asSarifResult(
invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/CollectedStatAggregator.kt:104
- The call to
InvertFileUtils.outputFilebelow referencesInvertFileUtils, but there is no import forcom.squareup.invert.internal.InvertFileUtilsin this file. Add the import to resolve the reference.
InvertSarifReportWriter.writeToSarifReport(
invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/report/sarif/InvertSarifReportWriter.kt:69
- The constant
SARIF_FILE_NAMEis declared but never used; consider removing it or using it inwriteToSarifReportto avoid dead code.
private const val SARIF_FILE_NAME = "invert-report.sarif"
invert-gradle-plugin/src/test/kotlin/com/squareup/invert/internal/report/sarif/InvertSarifReportWriterTest.kt:10
- [nitpick] Mixing TestNG assertions with Kotlin test assertions may confuse test consistency. Consider using
kotlin.test.assertEqualsinstead of importing TestNG.
import org.gradle.internal.impldep.org.testng.Assert.assertEquals
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.
- Please consider the comments. Nothing is a blocker from merging and doing follow ups, but if it is straightforward enough please update some in PR. Leaving this task to acknowledge but approving
| const val INVERT_FOLDER_NAME = "invert" | ||
| const val JS_FOLDER_NAME = "js" | ||
| const val JSON_FOLDER_NAME = "json" | ||
| const val SARIF_FOLDER_NAME = "sarif" |
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.
❤️
| OWNERS("owners.json", "Owners"), | ||
| METADATA("metadata.json", "Metadata"), | ||
| STATS("stats.json", "Stats"), | ||
| STATS_SARIF("stats.sarif", "Stats"), |
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.
Hmmm, i thought i deleted stats.json, but maybe that was only stats.js. This is fine but the concern is that the single file holds all data and that doesn't scale well. For the js/web we were forced to do that to collect things like all kotlin files. This can merge, but we should discuss how to get rid of those mega files eventually
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.
Yeah we are splitting it up as well, but I saw that json was doing one whole file so I followed suit
if we don’t need this then I can remove for sure
...-plugin/src/main/kotlin/com/squareup/invert/internal/report/sarif/InvertSarifReportWriter.kt
Outdated
Show resolved
Hide resolved
...-plugin/src/main/kotlin/com/squareup/invert/internal/report/sarif/InvertSarifReportWriter.kt
Show resolved
Hide resolved
| ), | ||
| properties = PropertyBag( | ||
| extras + mapOf( | ||
| "fileType" to filePath.split(".").last() |
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.
Is fileType required?
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.
I thought this was a nice to have but not required no we can remove
...-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/report/sarif/InvertSarifUtils.kt
Outdated
Show resolved
Hide resolved
...-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/report/sarif/InvertSarifUtils.kt
Outdated
Show resolved
Hide resolved
| /** | ||
| * Simple function to determine the source language based on the file path. | ||
| */ | ||
| private fun determineSourceLanguage(filePath: String): String { |
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.
Is this a sarif standard? Is that part of the library or do we need our own manual table?
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 is another one of those nice to haves but can be removed, sourceLanguage isnt something thats necessary to build the sarif schema but it is an optional item.
as far as if this is part of the Library, its not unfortunately it would have been so nice not having to manually maintain this part.
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.
but can be removed if we deem its not necessary
| import kotlin.test.assertTrue | ||
| import java.io.File | ||
|
|
||
| class InvertSarifReportWriterTest { |
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.
Tests 🥳
This pull request introduces support for generating SARIF (Static Analysis Results Interchange Format) reports in the
invert-gradle-plugin. The changes include adding a newInvertSarifReportWriterclass, updating existing components to integrate SARIF report generation, and modifying configurations to support SARIF output.SARIF Report Generation
InvertSarifReportWriterclass to handle the creation of SARIF reports, including methods for converting statistics data into SARIF-compliant rules and results, and writing these reports to files. (invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/report/sarif/InvertSarifReportWriter.kt)StatandStatMetadatawith helper methods to convert statistics and metadata into SARIF-compatible formats. (invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/report/sarif/InvertSarifReportWriter.kt)Integration with Existing Reporting
CollectedStatAggregatorto generate SARIF reports for code references using the newInvertSarifReportWriter.writeToSarifReportmethod. (invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/CollectedStatAggregator.kt)InvertReportWriterto include all project statistics in a single SARIF report by callingInvertSarifReportWriter.createInvertSarifReport. (invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/report/InvertReportWriter.kt)Configuration Updates
sarif4klibrary for SARIF serialization. (invert-gradle-plugin/build.gradle.kts)SARIF_FOLDER_NAMEinInvertFileUtilsfor organizing SARIF report files. (invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/InvertFileUtils.kt)STATS_SARIFtoInvertPluginFileKeyfor identifying SARIF report files. (invert-gradle-plugin/src/main/kotlin/com/squareup/invert/internal/models/InvertPluginFileKey.kt)Attached is an example of the output from the Sarif writer.
sarif.zip