6
6
"net/url"
7
7
"strings"
8
8
9
+ "github.com/pkg/errors"
10
+ "github.com/samber/lo"
9
11
"go.jetpack.io/devbox/internal/boxcli/usererr"
10
12
"go.jetpack.io/devbox/internal/cuecfg"
11
13
)
@@ -15,13 +17,17 @@ type githubPlugin struct {
15
17
org string
16
18
repo string
17
19
revision string
20
+ fragment string
18
21
}
19
22
20
23
// newGithubPlugin returns a plugin that is hosted on github.
21
- // url is of the form org/repo
22
- // The repo must have a devbox.json file in the root of the repo.
24
+ // url is of the form org/repo#name
25
+ // The repo must have a [name].json in the root of the repo. If fragment is
26
+ // not set, it defaults to "default"
23
27
func newGithubPlugin (url string ) (* githubPlugin , error ) {
24
- parts := strings .Split (url , "/" )
28
+ path , fragment , _ := strings .Cut (url , "#" )
29
+
30
+ parts := strings .Split (path , "/" )
25
31
26
32
if len (parts ) < 2 || len (parts ) > 3 {
27
33
return nil , usererr .New (
@@ -35,6 +41,7 @@ func newGithubPlugin(url string) (*githubPlugin, error) {
35
41
org : parts [0 ],
36
42
repo : parts [1 ],
37
43
revision : "master" ,
44
+ fragment : fragment ,
38
45
}
39
46
40
47
if len (parts ) == 3 {
@@ -75,10 +82,19 @@ func (p *githubPlugin) FileContent(subpath string) ([]byte, error) {
75
82
if res .StatusCode != http .StatusOK {
76
83
return nil , usererr .New (
77
84
"failed to get plugin github:%s (Status code %d). \n Please make sure a " +
78
- "devbox .json file exists in the root of the repo." ,
85
+ "[name].json or default .json file exists in the root of the repo." ,
79
86
p .raw ,
80
87
res .StatusCode ,
81
88
)
82
89
}
83
90
return io .ReadAll (res .Body )
84
91
}
92
+
93
+ func (p * githubPlugin ) buildConfig (projectDir string ) (* config , error ) {
94
+ configName , _ := lo .Coalesce (p .fragment , "default" )
95
+ content , err := p .FileContent (configName + ".json" )
96
+ if err != nil {
97
+ return nil , errors .WithStack (err )
98
+ }
99
+ return buildConfig (p , projectDir , string (content ))
100
+ }
0 commit comments