@@ -51,6 +51,16 @@ type PullRequestConfig struct {
51
51
Filter string `json:"filter" yaml:"filter" mapstructure:"filter"`
52
52
}
53
53
54
+ const (
55
+ // PullRequestIngestTypeNew is a filter that exposes only new dependencies in the pull request
56
+ PullRequestIngestTypeNew = "new"
57
+ // PullRequestIngestTypeNewAndUpdated is a filter that exposes new and updated
58
+ // dependencies in the pull request
59
+ PullRequestIngestTypeNewAndUpdated = "new_and_updated"
60
+ // PullRequestIngestTypeAll is a filter that exposes all dependencies in the pull request
61
+ PullRequestIngestTypeAll = "all"
62
+ )
63
+
54
64
// NewDepsIngester creates a new deps rule data ingest engine
55
65
func NewDepsIngester (cfg * pb.DepsType , gitprov provifv1.Git ) (* Deps , error ) {
56
66
if gitprov == nil {
@@ -151,13 +161,13 @@ func (gi *Deps) getBranch(repo *pb.Repository, userConfigBranch string) string {
151
161
// ingestTypes returns a sorter function for the given filter type.
152
162
// items which compare equal are skipped in output.
153
163
var ingestTypes = map [string ]func (* sbom.Node , * sbom.Node ) int {
154
- "new" : func (base * sbom.Node , updated * sbom.Node ) int {
164
+ PullRequestIngestTypeNew : func (base * sbom.Node , updated * sbom.Node ) int {
155
165
return cmp .Compare (base .GetName (), updated .GetName ())
156
166
},
157
- "new_and_updated" : func (base * sbom.Node , updated * sbom.Node ) int {
167
+ PullRequestIngestTypeNewAndUpdated : func (base * sbom.Node , updated * sbom.Node ) int {
158
168
return nodeSorter (base , updated )
159
169
},
160
- "all" : func (_ * sbom.Node , _ * sbom.Node ) int {
170
+ PullRequestIngestTypeAll : func (_ * sbom.Node , _ * sbom.Node ) int {
161
171
return - 1
162
172
},
163
173
}
@@ -223,10 +233,20 @@ func filterNodes(base []*sbom.Node, updated []*sbom.Node, compare func(*sbom.Nod
223
233
224
234
func (gi * Deps ) ingestPullRequest (
225
235
ctx context.Context , pr * pbinternal.PullRequest , params map [string ]any ) (* interfaces.Result , error ) {
226
- userCfg := & PullRequestConfig {}
236
+ userCfg := & PullRequestConfig {
237
+ // We default to new_and_updated for user convenience.
238
+ Filter : PullRequestIngestTypeNewAndUpdated ,
239
+ }
227
240
if err := mapstructure .Decode (params , userCfg ); err != nil {
228
241
return nil , fmt .Errorf ("failed to read dependency ingester configuration from params: %w" , err )
229
242
}
243
+
244
+ // Enforce that the filter is valid if left empty.
245
+ if userCfg .Filter == "" {
246
+ userCfg .Filter = PullRequestIngestTypeNewAndUpdated
247
+ }
248
+
249
+ // At this point the user really set a wrong configuration. So, let's error out.
230
250
if _ , ok := ingestTypes [userCfg .Filter ]; ! ok {
231
251
return nil , fmt .Errorf ("invalid filter type: %s" , userCfg .Filter )
232
252
}
0 commit comments