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