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

supabase / cli / 13918644911

18 Mar 2025 08:29AM UTC coverage: 51.06% (-6.7%) from 57.735%
13918644911

push

github

sweatybridge
chore(deps): bump supabase/studio in /pkg/config/templates

Bumps supabase/studio from 20250224-d10db0f to 20250317-6955350.

---
updated-dependencies:
- dependency-name: supabase/studio
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

6959 of 13629 relevant lines covered (51.06%)

186.36 hits per line

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

0.0
/pkg/fetcher/http.go
1
package fetcher
2

3
import (
4
        "bytes"
5
        "context"
6
        "encoding/json"
7
        "io"
8
        "net/http"
9

10
        "github.com/go-errors/errors"
11
)
12

13
type Fetcher struct {
14
        server  string
15
        client  *http.Client
16
        editors []RequestEditor
17
        status  []int
18
}
19

20
type FetcherOption func(*Fetcher)
21

22
func NewFetcher(server string, opts ...FetcherOption) *Fetcher {
×
23
        api := &Fetcher{
×
24
                server: server,
×
25
                client: http.DefaultClient,
×
26
        }
×
27
        for _, apply := range opts {
×
28
                apply(api)
×
29
        }
×
30
        return api
×
31
}
32

33
func WithHTTPClient(client *http.Client) FetcherOption {
×
34
        return func(s *Fetcher) {
×
35
                s.client = client
×
36
        }
×
37
}
38

39
func WithExpectedStatus(statusCode ...int) FetcherOption {
×
40
        return func(s *Fetcher) {
×
41
                s.status = statusCode
×
42
        }
×
43
}
44

45
func WithBearerToken(token string) FetcherOption {
×
46
        addHeader := func(req *http.Request) {
×
47
                req.Header.Add("Authorization", "Bearer "+token)
×
48
        }
×
49
        return WithRequestEditor(addHeader)
×
50
}
51

52
func WithUserAgent(agent string) FetcherOption {
×
53
        addHeader := func(req *http.Request) {
×
54
                req.Header.Add("User-Agent", agent)
×
55
        }
×
56
        return WithRequestEditor(addHeader)
×
57
}
58

59
func WithRequestEditor(fn RequestEditor) FetcherOption {
×
60
        return func(s *Fetcher) {
×
61
                s.editors = append(s.editors, fn)
×
62
        }
×
63
}
64

65
type RequestEditor func(req *http.Request)
66

67
func (s *Fetcher) Send(ctx context.Context, method, path string, reqBody any, reqEditors ...RequestEditor) (*http.Response, error) {
×
68
        body, ok := reqBody.(io.Reader)
×
69
        if !ok && reqBody != nil {
×
70
                var buf bytes.Buffer
×
71
                enc := json.NewEncoder(&buf)
×
72
                if err := enc.Encode(reqBody); err != nil {
×
73
                        return nil, errors.Errorf("failed to encode request body: %w", err)
×
74
                }
×
75
                reqEditors = append(reqEditors, func(req *http.Request) {
×
76
                        req.Header.Set("Content-Type", "application/json")
×
77
                })
×
78
                body = &buf
×
79
        }
80
        // Creates request
81
        req, err := http.NewRequestWithContext(ctx, method, s.server+path, body)
×
82
        if err != nil {
×
83
                return nil, errors.Errorf("failed to initialise http request: %w", err)
×
84
        }
×
85
        for _, apply := range s.editors {
×
86
                apply(req)
×
87
        }
×
88
        for _, apply := range reqEditors {
×
89
                apply(req)
×
90
        }
×
91
        // Sends request
92
        resp, err := s.client.Do(req)
×
93
        if err != nil {
×
94
                return nil, errors.Errorf("failed to execute http request: %w", err)
×
95
        }
×
96
        for _, expected := range s.status {
×
97
                if resp.StatusCode == expected {
×
98
                        return resp, nil
×
99
                }
×
100
        }
101
        // Reject unexpected status codes as error
102
        if len(s.status) > 0 || resp.StatusCode >= http.StatusBadRequest {
×
103
                defer resp.Body.Close()
×
104
                data, err := io.ReadAll(resp.Body)
×
105
                if err != nil {
×
106
                        return resp, errors.Errorf("Error status %d: %w", resp.StatusCode, err)
×
107
                }
×
108
                return resp, errors.Errorf("Error status %d: %s", resp.StatusCode, data)
×
109
        }
110
        return resp, nil
×
111
}
112

113
func ParseJSON[T any](r io.ReadCloser) (T, error) {
×
114
        defer r.Close()
×
115
        var data T
×
116
        dec := json.NewDecoder(r)
×
117
        if err := dec.Decode(&data); err != nil {
×
118
                return data, errors.Errorf("failed to parse response body: %w", err)
×
119
        }
×
120
        return data, nil
×
121
}
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

© 2026 Coveralls, Inc