Skip to content

Commit

Permalink
Merge branch 'main' into add-api-url
Browse files Browse the repository at this point in the history
  • Loading branch information
timbastin authored Feb 24, 2025
2 parents 0089d82 + e909028 commit accb4ef
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/devguard-scanner/commands/sca.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func printScaResults(scanResponse scan.ScanResponse, failOnRisk, assetName, webU

// order the flaws by their risk
slices.SortFunc(scanResponse.Flaws, func(a, b flaw.FlawDTO) int {
return int(*(a.RawRiskAssessment)*100) - int(*b.RawRiskAssessment*100)
return int(utils.OrDefault(a.RawRiskAssessment, 0)*100) - int(utils.OrDefault(b.RawRiskAssessment, 0)*100)
})

// get the max risk of open!!! flaws
Expand Down
5 changes: 5 additions & 0 deletions internal/utils/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ func GetAssetVersionInfoFromGit(path string) (GitVersionInfo, error) {
}

func getCurrentBranchName(path string) (string, error) {
// check if a CI variable is set - this provides a more stable way to get the branch name
if os.Getenv("CI_COMMIT_REF_NAME") != "" {
return os.Getenv("CI_COMMIT_REF_NAME"), nil
}

cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD")
var out bytes.Buffer
var errOut bytes.Buffer
Expand Down
18 changes: 18 additions & 0 deletions internal/utils/git_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package utils

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetCurrentBranchName(t *testing.T) {
t.Run("it should use the CI_COMMIT_REF_NAME variable if it is set", func(t *testing.T) {
// Test when CI_COMMIT_REF_NAME is set
os.Setenv("CI_COMMIT_REF_NAME", "test-branch")
branchName, err := getCurrentBranchName(".")
assert.NoError(t, err)
assert.Equal(t, "test-branch", branchName)
})
}

0 comments on commit accb4ef

Please sign in to comment.