Skip to content

FEAT: add health-score-threshold option to cicheck command for CI/CD … - #67

Merged
siddharth7500 merged 3 commits into
developfrom
PD-2336
Jul 15, 2026
Merged

FEAT: add health-score-threshold option to cicheck command for CI/CD …#67
siddharth7500 merged 3 commits into
developfrom
PD-2336

Conversation

@siddharth7500

@siddharth7500 siddharth7500 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor
Title Value
Type Feature
Ticket/Issue https://appknox.atlassian.net/browse/PD-2336
Migrations No
Migration Scripts No
ENV vars change No
Frontend No
Local testing Done
Staging testing Pending
On premise notes NA
Documentation https://appknox.atlassian.net/wiki/spaces/~419311996/pages/3529015298/VAPT+Scan+Health+Score
Release notes
Version upgrade Minor

Changelog

  1. Add health score endpoint support in FilesService

    type HealthScore struct {
        HealthScore int `json:"health_score,omitempty"`
    }
    
    func (s *FilesService) GetHealthScore(ctx context.Context, fileID int) (*HealthScore, *Response, error)
  2. Add health score threshold mode to cicheck command

    • Added --health-score-threshold flag (0-100) as alternative to --risk-threshold
    • Validates mutual exclusivity (only one threshold mode allowed)
    • Validates range (0-100) for health score threshold
    if healthScoreChanged && riskChanged {
        err := errors.New("only one of risk-threshold or health-score-threshold can be provided")
        os.Exit(1)
    }
  3. Refactor cicheck helper to support both modes

    • Extracted waitForStaticScan function for code reuse
    • Added ProcessHealthScoreCiCheck function for health score validation
    • Build passes if health_score >= threshold, fails otherwise
  4. Add comprehensive test coverage

    • Created cmd/cicheck_test.go with 8 test cases:
      • Both parameters provided (mutual exclusivity check)
      • Only risk-threshold provided
      • Only health-score-threshold provided
      • No parameters (default behavior)
      • Health score validation (valid: 0, 50, 100; invalid: -1, 101)
      • Risk threshold values (low, medium, high, critical)
      • Timeout flag validation
      • Required file ID argument
  5. Update documentation

    • Updated README command descriptions for health score support
    • Added CI Check Options section with usage examples
    • Added Linux/macOS and Windows platform examples for both modes

Dependent PRs

@utkarshpandey12 utkarshpandey12 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

requested changes

Comment thread helper/cicheck.go
waitForStaticScan(fileID, staticScanTimeout)
ctx := context.Background()
client := getClient()
_, analysisResponse, err := client.Analyses.ListByFile(ctx, fileID, nil)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the error from the first Analyses.ListByFile call is never checked before calling analysisResponse.GetCount(). Add PrintError/exit path used elsewhere in the function in case of failure

Comment thread appknox/files.go Outdated
func (s *FilesService) GetHealthScore(ctx context.Context, fileID int, eventType string) (*HealthScore, *Response, error) {
u := fmt.Sprintf("api/v3/files/%v/health_score", fileID)
if eventType != "" {
u = fmt.Sprintf("%s?event_type=%s", u, eventType)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

use existing addOptions helper to builds the event_type query param

Comment thread helper/cicheck.go Outdated
ctx := context.Background()
client := getClient()

healthScoreResponse, _, err := client.Files.GetHealthScore(ctx, fileID, "sast_completed")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

consider defining and using event_type as a proper enum

Comment thread cmd/cicheck_test.go
return buf.String(), err
}

func TestCiCheckCommand_BothThresholdsProvided(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test just I guess never actually runs cicheckCmd. So if the real flag check in Run() breaks, this test would still pass.

Comment thread cmd/cicheck_test.go
resetCiCheckFlags()
}

func TestCiCheckCommand_RiskThresholdValues(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

validate via actual run cmd

Comment thread cmd/cicheck_test.go
resetCiCheckFlags()
}

func TestCiCheckCommand_HealthScoreValidation(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

validate via actual run cmd

@sonarqubecloud

sonarqubecloud Bot commented Jul 7, 2026

Copy link
Copy Markdown

@utkarshpandey12 utkarshpandey12 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm !!..

@siddharth7500
siddharth7500 marked this pull request as ready for review July 15, 2026 12:21
@siddharth7500
siddharth7500 merged commit 56dd08f into develop Jul 15, 2026
2 checks passed
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.

2 participants