Skip to content

Commit 3023e1c

Browse files
authored
fix: Improve logging when an error is encontered in SI (#184)
* fix: Improve logging when an error is encontered in SI Signed-off-by: Eddie Knight <knight@linux.com> * Fixed failing test Signed-off-by: Eddie Knight <knight@linux.com> --------- Signed-off-by: Eddie Knight <knight@linux.com>
1 parent 2d35824 commit 3023e1c

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

data/rest-data.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"io"
8+
"log"
89
"net/http"
910
"strings"
1011

@@ -27,6 +28,7 @@ type RestData struct {
2728
WorkflowsEnabled bool
2829
WorkflowPermissions WorkflowPermissions
2930
Insights si.SecurityInsights
31+
InsightsError bool
3032
Releases []ReleaseData
3133
Rulesets []Ruleset
3234
contents RepoContent
@@ -129,7 +131,12 @@ func (r *RestData) checkFile(filename string) (filepath string) {
129131
if filepath != "" {
130132
return filepath
131133
}
132-
for _, dirContents := range r.contents.SubContent[".github"].Content {
134+
135+
forgeDir, err := r.getSubdirContents(".github")
136+
if err != nil {
137+
log.Printf("Failed to retrieve forge dir contents: %s", err.Error())
138+
}
139+
for _, dirContents := range forgeDir.Content {
133140
// forge directory contents
134141
if dirContents.GetType() != "file" {
135142
continue
@@ -230,6 +237,7 @@ func (r *RestData) loadSecurityInsights() {
230237
r.Insights = insights
231238
if err != nil {
232239
r.Config.Logger.Error(fmt.Sprintf("failed to read security insights file: %s", err.Error()))
240+
r.InsightsError = true
233241
}
234242
return
235243
}
@@ -308,6 +316,9 @@ func (c *RepoContent) GetSubdirContentByPath(r *RestData, path string) (RepoCont
308316

309317
// getSubdirContents fetches contents of a directory
310318
func (r *RestData) getSubdirContents(path string) (RepoContent, error) {
319+
if len(r.contents.SubContent[path].Content) > 0 {
320+
return r.contents.SubContent[path], nil
321+
}
311322
_, content, _, err := r.ghClient.Repositories.GetContents(context.Background(), r.owner, r.repo, path, nil)
312323
if err != nil {
313324
return RepoContent{}, err

evaluation_plans/reusable_steps/steps.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ func HasSecurityInsightsFile(payloadData any) (result layer4.Result, message str
3838
if message != "" {
3939
return layer4.Unknown, message
4040
}
41-
41+
if payload.InsightsError {
42+
return layer4.NeedsReview, "An error was encountered while parsing Security Insights content"
43+
}
4244
if payload.Insights.Header.URL == "" {
4345
return layer4.NeedsReview, "Security insights required for this assessment, but file not found"
4446
}

go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/revanite-io/pvtr-github-rep
1+
module github.com/revanite-io/pvtr-github-repo
22

33
go 1.25.1
44

@@ -8,10 +8,8 @@ require (
88
github.com/ossf/gemara v0.12.1
99
github.com/ossf/si-tooling/v2 v2.0.5-0.20250508212737-7ddcc8c43db9
1010
github.com/privateerproj/privateer-sdk v1.10.0
11-
github.com/revanite-io/pvtr-github-repo v0.12.0
1211
github.com/rhysd/actionlint v1.7.8
1312
github.com/shurcooL/githubv4 v0.0.0-20240727222349-48295856cce7
14-
golang.org/x/oauth2 v0.32.0
1513
)
1614

1715
require (
@@ -28,6 +26,7 @@ require (
2826
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 // indirect
2927
go.yaml.in/yaml/v3 v3.0.4 // indirect
3028
go.yaml.in/yaml/v4 v4.0.0-rc.2 // indirect
29+
golang.org/x/oauth2 v0.32.0 // indirect
3130
golang.org/x/time v0.11.0 // indirect
3231
)
3332

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI
8686
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
8787
github.com/privateerproj/privateer-sdk v1.10.0 h1:LlD8TxozQmx20N9jkuixTQIPSgSfxFrFbP38FivhADM=
8888
github.com/privateerproj/privateer-sdk v1.10.0/go.mod h1:eDst4232KyZd98dduG534GLxBfN1VtIZR6w5lUOiigY=
89-
github.com/revanite-io/pvtr-github-repo v0.12.0 h1:+Xae4WXDnc//wgClCLNawxj8J7tic5u9Zyqb9wu0/zg=
90-
github.com/revanite-io/pvtr-github-repo v0.12.0/go.mod h1:hi1Xyinxqk6wfC/DsqA+OWFmr5bwLSBuvlsbEzcTeaY=
9189
github.com/rhysd/actionlint v1.7.8 h1:3d+N9ourgAxVYG4z2IFxFIk/YiT6V+VnKASfXGwT60E=
9290
github.com/rhysd/actionlint v1.7.8/go.mod h1:3kiS6egcbXG+vQsJIhFxTz+UKaF1JprsE0SKrpCZKvU=
9391
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=

0 commit comments

Comments
 (0)