Skip to content

Conversation

@rrama
Copy link
Contributor

@rrama rrama commented Dec 4, 2025

Description

The threshold value is stored in the global config. When the risk score FF is set, only issues matching or exceeding this value are displayed.
Also removed some logging, which was causing excessive spam in our logs as it was per issue.
The logging has been replaced with a summary of issues filtered and why.
Added a test which checks for this logging, and this required some changes to config.go so an additional log output can be attached and checked in the test.

Checklist

  • Tests added and all succeed
  • Regenerated mocks, etc. (make generate)
  • N/A
  • Linted (make lint-fix)
  • README.md updated, if user-facing
  • License file updated, if new 3rd-party dependency is introduced
  • N/A

The threshold value is stored in the folder config.
When the risk score FF is set, only issues matching or exceeding this value are displayed.
@snyk-io
Copy link

snyk-io bot commented Dec 4, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @rrama, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant enhancement by enabling risk score-based filtering for issues, allowing users to focus on the most critical findings. It centralizes and streamlines the issue visibility determination process, making the codebase more robust and easier to extend. Additionally, it addresses a performance concern by reducing verbose logging, contributing to a more efficient system.

Highlights

  • Risk Score Filtering: Implemented a new feature to filter issues based on their risk score, using a configurable threshold stored in the folder configuration. Only issues with a risk score meeting or exceeding this threshold will be displayed.
  • Refactored Issue Visibility Logic: Consolidated issue visibility checks into a new isIssueVisible method within the Folder struct, improving modularity and maintainability of filtering logic.
  • Logging Optimization: Removed excessive per-issue logging that was causing spam in the logs, leading to cleaner and more efficient logging.
  • Configuration Update: Added a RiskScoreThreshold field to the FolderConfig struct to persist the risk score filtering setting.
  • New Test Cases: Introduced comprehensive test cases for the new risk score filtering functionality, ensuring its correctness under various threshold conditions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces filtering for OSS issues based on a risk score threshold, which is a valuable addition. The implementation is clean, with the new logic well-encapsulated. I appreciate the refactoring of existing filter functions into methods, which improves code organization, and the removal of spammy logs. The tests are thorough, covering the new configuration mechanism and the risk score filtering feature. Overall, this is a solid contribution. I have one minor suggestion to improve code conciseness.

@rrama rrama requested a review from a team as a code owner December 5, 2025 15:53
@rrama rrama mentioned this pull request Dec 5, 2025
5 tasks
@bastiandoetsch
Copy link
Collaborator

Why is it global, and not per folder config / org?

enableSnykLearnCodeActions bool
enableSnykOSSQuickFixCodeActions bool
enableDeltaFindings bool
writer *zerolog.ConsoleWriter
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we introduce this?

Comment on lines +1137 to +1145
// AddLoggerOutputForTesting allows tests to capture log output by adding an additional writer.
// Note: This updates c.logger but not c.writer, as the new logger still outputs through c.writer's formatting.
func (c *Config) AddLoggerOutputForTesting(writer io.Writer) {
c.m.Lock()
defer c.m.Unlock()
newLogger := c.logger.Output(io.MultiWriter(c.writer, writer))
c.logger = &newLogger
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm. Why do we need to do this in production code instead of our test setup? This code, should probably live in a _test.go file or in our test helpers.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, I'm not sure we need (or should) verify log output to test business logic.

Copy link
Contributor Author

@rrama rrama Dec 8, 2025

Choose a reason for hiding this comment

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

I come from a background where if a customer has an issue, you can't ask them to upgrade to a version where we add more logging, you need to get all the information you need from the first set of logs. So we would always add tests to ensure the log lines we cared about were displayed correctly, mostly so that if another developer removed it in the future, they were made aware that it was important because a test would fail (just adding comments did not work, as people deleted or skipped calling functions that did the logging inside of them sometimes).
I am happy to not have this sort of testing if we don't think it necessary.

I do agree that I probably should have made a testhelper in the config package for it.

logger := c.Logger().With().Str("method", "isVisibleForIssueViewOptions").Logger()
func (f *Folder) isVisibleRiskScore(issue types.Issue) bool {
riskScoreThreshold := f.c.RiskScoreThreshold()
if riskScoreThreshold == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

could be a switch, I guess, instead of an if - elseif - else

})
}

func Test_FilterIssues_LogsCorrectFilterReasons(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Lots of (test) code to check if a log message is correct. Do we really need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was also more of a check all the filters work together test, as we have tests for them individually, but never together. Not that I would ever expect it to cause issues when you have multiple issues that are filtered for different reasons.

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.

4 participants