• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mindersec / minder / 14376078638

10 Apr 2025 08:39AM UTC coverage: 56.857%. First build
14376078638

Pull #5515

github

web-flow
Merge ea220ae51 into 0f5ecd80e
Pull Request #5515: Don't return errors when getting properties

27 of 49 new or added lines in 22 files covered. (55.1%)

18305 of 32195 relevant lines covered (56.86%)

37.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/internal/providers/github/properties.go
1
// SPDX-FileCopyrightText: Copyright 2024 The Minder Authors
2
// SPDX-License-Identifier: Apache-2.0
3

4
package github
5

6
import (
7
        "context"
8
        "errors"
9
        "fmt"
10
        "slices"
11

12
        "github.com/rs/zerolog"
13

14
        properties2 "github.com/mindersec/minder/internal/providers/github/properties"
15
        minderv1 "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1"
16
        "github.com/mindersec/minder/pkg/entities/properties"
17
)
18

19
// FetchProperty fetches a single property for the given entity
20
func (c *GitHub) FetchProperty(
21
        ctx context.Context, getByProps *properties.Properties, entType minderv1.Entity, key string,
22
) (*properties.Property, error) {
×
23
        if c.propertyFetchers == nil {
×
24
                return nil, errors.New("property fetchers not initialized")
×
25
        }
×
26

27
        fetcher := c.propertyFetchers.EntityPropertyFetcher(entType)
×
28
        if fetcher == nil {
×
29
                return nil, fmt.Errorf("entity %s not supported", entType)
×
30
        }
×
31

32
        wrapper := fetcher.WrapperForProperty(key)
×
33
        if wrapper == nil {
×
34
                return nil, fmt.Errorf("property %s not supported for entity %s", key, entType)
×
35
        }
×
36

37
        props, err := wrapper(ctx, c.client, c.IsOrg(), getByProps)
×
38
        if err != nil {
×
39
                return nil, fmt.Errorf("error fetching property %s for entity %s: %w", key, entType, err)
×
40
        }
×
41
        value, ok := props[key]
×
42
        if !ok {
×
43
                return nil, errors.New("requested property not found in result")
×
44
        }
×
45
        return properties.NewProperty(value)
×
46
}
47

48
// FetchAllProperties fetches all properties for the given entity
49
func (c *GitHub) FetchAllProperties(
50
        ctx context.Context, getByProps *properties.Properties, entType minderv1.Entity, cachedProps *properties.Properties,
51
) (*properties.Properties, error) {
×
52
        if c.propertyFetchers == nil {
×
53
                return nil, errors.New("property fetchers not initialized")
×
54
        }
×
55

56
        zerolog.Ctx(ctx).Debug().
×
57
                Str("entity", entType.String()).
×
58
                Dict("getByProps", getByProps.ToLogDict()).
×
59
                Msg("Fetching all properties")
×
60

×
61
        fetcher := c.propertyFetchers.EntityPropertyFetcher(entType)
×
62
        result := make(map[string]any)
×
63
        for _, wrapper := range fetcher.AllPropertyWrappers() {
×
64
                props, err := wrapper(ctx, c.client, c.IsOrg(), getByProps)
×
65
                if err != nil {
×
66
                        return nil, fmt.Errorf("error fetching properties for entity %s: %w", entType, err)
×
67
                }
×
68

69
                for k, v := range props {
×
70
                        result[k] = v
×
71
                }
×
72
        }
73

NEW
74
        upstreamProps := properties.NewProperties(result)
×
75

×
76
        operational := filterOperational(cachedProps, fetcher)
×
77
        return upstreamProps.Merge(operational), nil
×
78
}
79

80
func filterOperational(cachedProperties *properties.Properties, fetcher properties2.GhPropertyFetcher) *properties.Properties {
×
81
        if cachedProperties == nil {
×
82
                // Nothing to filter
×
83
                return nil
×
84
        }
×
85

86
        operational := fetcher.OperationalProperties()
×
87
        if len(operational) == 0 {
×
88
                return cachedProperties
×
89
        }
×
90

91
        filter := func(key string, _ *properties.Property) bool {
×
92
                return slices.Contains(operational, key)
×
93
        }
×
94

95
        return cachedProperties.FilteredCopy(filter)
×
96
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc