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

feat: Generate html report for single scan mode #358

Merged
merged 8 commits into from
Dec 18, 2023

Conversation

m-rudyk
Copy link
Collaborator

@m-rudyk m-rudyk commented Dec 13, 2023

Pull Request

Description

added option for signle scan operation to generate html report with conflict files.

Fixes #359

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code cleanup/refactoring
  • Documentation update
  • This change requires a documentation update
  • CI system update
  • Test Coverage update

Testing

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

Test Configuration:

  • Java: v11
  • LPVS Release: v1.x.x

Checklist:

  • My code follows the style guidelines of this project
  • My code meets the required code coverage for lines (90% and above)
  • My code meets the required code coverage for branches (80% and above)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@codecov-commenter
Copy link

codecov-commenter commented Dec 13, 2023

Codecov Report

Attention: 21 lines in your changes are missing coverage. Please review.

Comparison is base (6298473) 91.34% compared to head (22dce35) 91.01%.

Files Patch % Lines
src/main/java/com/lpvs/util/LPVSCommentUtil.java 85.54% 6 Missing and 6 partials ⚠️
.../main/java/com/lpvs/service/LPVSDetectService.java 59.09% 7 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #358      +/-   ##
============================================
- Coverage     91.34%   91.01%   -0.33%     
- Complexity      475      486      +11     
============================================
  Files            48       48              
  Lines          1606     1703      +97     
  Branches        194      206      +12     
============================================
+ Hits           1467     1550      +83     
- Misses           82       89       +7     
- Partials         57       64       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Mykola Rudyk <m.rudyk@samsung.com>
Signed-off-by: Mykola Rudyk <m.rudyk@samsung.com>
Signed-off-by: Mykola Rudyk <m.rudyk@samsung.com>
@m-rudyk
Copy link
Collaborator Author

m-rudyk commented Dec 13, 2023

Example of generated report file:
image

@m-rudyk m-rudyk marked this pull request as ready for review December 13, 2023 15:14
@o-kopysov o-kopysov changed the title M.rudyk/generate html report feat: Generate html report for single scan mode Dec 13, 2023
README.md Outdated
@@ -271,7 +271,7 @@ Alternatively, you can perform a one-time scan on a specific pull request using
4.b.2. Execute the single scan with the following command:

```bash
java -jar -Dgithub.token=<my-token> lpvs-*.jar --github.pull.request=<PR URL>
java -jar -Dgithub.token=<my-token> lpvs-*.jar --github.pull.request=<PR URL> --build.html.report=<Path to report folder>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to specify Path to report folder or Path + Filename?
It's not clear from the description. Pease add more words into Readme.

log.info(jsonTxt);
log.info("\n\n\n Single scan finished successfully \n\n\n");

scanossDetectService.runScan(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I can't entirely agree with this line.
The previous logic was to use this.runScan() for the case when several scanners can be used. Current change has hardcoded scanossDetectService.runScan() option which blocks the flexibility of the implementation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

String report =
LPVSCommentUtil.buildHTMLComment(
webhookConfig, scanResult, detectedConflicts);
LPVSCommentUtil.saveHTMLToFile(report, buildReport + "/LPVSreport.html");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe it's better to define filename via CLI parameter?

String report =
LPVSCommentUtil.reportCommentBuilder(
webhookConfig, scanResult, detectedConflicts);
log.info(report);
}
} catch (Exception ex) {
log.info("\n\n\n Single scan finished with errors \n\n\n");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe log.error is a better choise?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

next message is error with reporting. But we may change this as well.

@o-kopysov
Copy link
Collaborator

@m-rudyk

  1. Rebase your PR
  2. Check my comments
  3. Improve code coverage:
JaCoCo Test Coverage Summary
Coverage: 89.940%
Branches: 77.586%

@o-kopysov o-kopysov self-requested a review December 13, 2023 16:41
Copy link
Collaborator

@o-kopysov o-kopysov left a comment

Choose a reason for hiding this comment

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

Please check my comments

@o-kopysov o-kopysov added this to the v1.3.0 milestone Dec 13, 2023
Signed-off-by: Mykola Rudyk <m.rudyk@samsung.com>
@m-rudyk m-rudyk force-pushed the m.rudyk/generate_html_report branch 2 times, most recently from 45c36f7 to 478a7d8 Compare December 13, 2023 18:51
@o-kopysov
Copy link
Collaborator

@m-rudyk

JaCoCo Test Coverage Summary
Coverage: 91.371%
Branches: 78.007%

@m-rudyk m-rudyk force-pushed the m.rudyk/generate_html_report branch 4 times, most recently from 8bc02c0 to a889502 Compare December 13, 2023 22:38
Signed-off-by: Mykola Rudyk <m.rudyk@samsung.com>
Copy link
Member

@tiokim tiokim left a comment

Choose a reason for hiding this comment

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

PTAL

// ToDo: form html report and console output
log.info(jsonTxt);
log.info("\n\n\n Single scan finished successfully \n\n\n");
List<LPVSFile> scanResult = scanossDetectService.checkLicenses(webhookConfig);
Copy link
Member

Choose a reason for hiding this comment

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

I think the code can be revised like below.

List<LPVSFile> scanResult = this.runScan(webhookConfig, LPVSDetectService.getPathByPullRequest(webhookConfig));

@Autowired private ApplicationEventPublisher eventPublisher;

@Value("${github.pull.request:}")
private String trigger;

@Value("${build.html.report:}")
private String buildReport;
Copy link
Member

Choose a reason for hiding this comment

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

What about changing the name to htmlReport?

List<LPVSLicenseService.Conflict<String, String>> detectedConflicts =
licenseService.findConflicts(webhookConfig, scanResult);

if (buildReport != null && !HtmlUtils.htmlEscape(buildReport).equals("")) {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to run HtmlUtils.htmlEscape(buildReport)?

@@ -66,4 +74,122 @@ public static String getMatchedLinesAsLink(
log.debug("MatchedLines: " + matchedLines);
return matchedLines;
}

public static String reportCommentBuilder(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add Javadoc comments for all new functions.

Copy link
Collaborator

@o-kopysov o-kopysov left a comment

Choose a reason for hiding this comment

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

LGTM

@o-kopysov
Copy link
Collaborator

@m-rudyk Please resolve merge conflicts.

@m-rudyk m-rudyk force-pushed the m.rudyk/generate_html_report branch 2 times, most recently from d1279ea to 6b261c7 Compare December 18, 2023 11:25
Signed-off-by: m-rudyk <121865672+m-rudyk@users.noreply.github.com>
@m-rudyk m-rudyk merged commit 2cfc37e into Samsung:main Dec 18, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to generate report to HTML file in single scan operation
5 participants