Skip to content

Commit

Permalink
Add isOrg to the property wrapper signature
Browse files Browse the repository at this point in the history
The wrapper for artifacts will call a different github provider call
depending on whether we need to fetch an property for a user artifact or
an organizational artifact. Let's extend the wrapper with a bool to
allow that.

Related: mindersec#4339
  • Loading branch information
jhrozek committed Sep 3, 2024
1 parent f6bff2f commit bef7e0e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions internal/providers/github/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (c *GitHub) FetchProperty(
return nil, fmt.Errorf("property %s not supported for entity %s", key, entType)
}

props, err := wrapper(ctx, c.client, getByProps)
props, err := wrapper(ctx, c.client, c.IsOrg(), getByProps)
if err != nil {
return nil, fmt.Errorf("error fetching property %s for entity %s: %w", key, entType, err)
}
Expand All @@ -66,7 +66,7 @@ func (c *GitHub) FetchAllProperties(
fetcher := c.propertyFetchers.EntityPropertyFetcher(entType)
result := make(map[string]any)
for _, wrapper := range fetcher.AllPropertyWrappers() {
props, err := wrapper(ctx, c.client, getByProps)
props, err := wrapper(ctx, c.client, c.IsOrg(), getByProps)
if err != nil {
return nil, fmt.Errorf("error fetching properties for entity %s: %w", entType, err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/providers/github/properties/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

// GhPropertyWrapper is a function that fetches a property from the GitHub API
type GhPropertyWrapper func(
ctx context.Context, ghCli *go_github.Client, lookupProperties *properties.Properties,
ctx context.Context, ghCli *go_github.Client, isOrg bool, lookupProperties *properties.Properties,
) (map[string]any, error)

// GhPropertyFetcher is an interface for fetching properties from the GitHub API
Expand Down
4 changes: 3 additions & 1 deletion internal/providers/github/properties/pull_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ func parsePrName(input string) (string, string, int64, error) {
}

func getPrWrapper(
ctx context.Context, ghCli *go_github.Client, getByProps *properties.Properties,
ctx context.Context, ghCli *go_github.Client, isOrg bool, getByProps *properties.Properties,
) (map[string]any, error) {
_ = isOrg

owner, name, id, err := getPrWrapperAttrsFromProps(getByProps)
if err != nil {
return nil, fmt.Errorf("error getting pr wrapper attributes: %w", err)
Expand Down
3 changes: 2 additions & 1 deletion internal/providers/github/properties/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ var repoPropertyDefinitions = []propertyOrigin{
}

func getRepoWrapper(
ctx context.Context, ghCli *go_github.Client, getByProps *properties.Properties,
ctx context.Context, ghCli *go_github.Client, isOrg bool, getByProps *properties.Properties,
) (map[string]any, error) {
_ = isOrg

name, owner, err := getNameOwnerFromProps(getByProps)
if err != nil {
Expand Down

0 comments on commit bef7e0e

Please sign in to comment.