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

supabase / cli / 12212288177

07 Dec 2024 10:53AM UTC coverage: 59.644% (-0.003%) from 59.647%
12212288177

Pull #2952

github

sweatybridge
fix: account for remote config when pushing
Pull Request #2952: fix: account for remote config when pushing

38 of 58 new or added lines in 10 files covered. (65.52%)

8 existing lines in 3 files now uncovered.

6404 of 10737 relevant lines covered (59.64%)

6.07 hits per line

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

84.78
/internal/utils/flags/project_ref.go
1
package flags
2

3
import (
4
        "bytes"
5
        "context"
6
        "fmt"
7
        "os"
8

9
        "github.com/go-errors/errors"
10
        "github.com/spf13/afero"
11
        "github.com/spf13/viper"
12
        "github.com/supabase/cli/internal/utils"
13
        "golang.org/x/term"
14
)
15

16
var ProjectRef string
17

18
func ParseProjectRef(ctx context.Context, fsys afero.Fs) error {
4✔
19
        if err := LoadProjectRef(fsys); !errors.Is(err, utils.ErrNotLinked) {
7✔
20
                return err
3✔
21
        }
3✔
22
        // Prompt as the last resort
23
        if term.IsTerminal(int(os.Stdin.Fd())) {
1✔
24
                return PromptProjectRef(ctx, "Select a project:")
×
25
        }
×
26
        return errors.New(utils.ErrNotLinked)
1✔
27
}
28

29
func PromptProjectRef(ctx context.Context, title string) error {
3✔
30
        resp, err := utils.GetSupabase().V1ListAllProjectsWithResponse(ctx)
3✔
31
        if err != nil {
4✔
32
                return errors.Errorf("failed to retrieve projects: %w", err)
1✔
33
        }
1✔
34
        if resp.JSON200 == nil {
3✔
35
                return errors.New("Unexpected error retrieving projects: " + string(resp.Body))
1✔
36
        }
1✔
37
        items := make([]utils.PromptItem, len(*resp.JSON200))
1✔
38
        for i, project := range *resp.JSON200 {
2✔
39
                items[i] = utils.PromptItem{
1✔
40
                        Summary: project.Id,
1✔
41
                        Details: fmt.Sprintf("name: %s, org: %s, region: %s", project.Name, project.OrganizationId, project.Region),
1✔
42
                }
1✔
43
        }
1✔
44
        choice, err := utils.PromptChoice(ctx, title, items)
1✔
45
        if err != nil {
2✔
46
                return err
1✔
47
        }
1✔
48
        ProjectRef = choice.Summary
×
49
        fmt.Fprintln(os.Stderr, "Selected project:", ProjectRef)
×
50
        return nil
×
51
}
52

53
func LoadProjectRef(fsys afero.Fs) error {
5✔
54
        // Flag takes highest precedence
5✔
55
        if len(ProjectRef) > 0 {
6✔
56
                return utils.AssertProjectRefIsValid(ProjectRef)
1✔
57
        }
1✔
58
        // Env var takes precedence over ref file
59
        if ProjectRef = viper.GetString("PROJECT_ID"); len(ProjectRef) > 0 {
4✔
NEW
60
                return utils.AssertProjectRefIsValid(ProjectRef)
×
UNCOV
61
        }
×
62
        // Load from local file last
63
        projectRefBytes, err := afero.ReadFile(fsys, utils.ProjectRefPath)
4✔
64
        if errors.Is(err, os.ErrNotExist) {
6✔
65
                return errors.New(utils.ErrNotLinked)
2✔
66
        } else if err != nil {
5✔
67
                return errors.Errorf("failed to load project ref: %w", err)
1✔
68
        }
1✔
69
        ProjectRef = string(bytes.TrimSpace(projectRefBytes))
1✔
70
        return utils.AssertProjectRefIsValid(ProjectRef)
1✔
71
}
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