Skip to content

[plugins] New github repo structure #1290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cli-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ jobs:
DEVBOX_DEBUG: ${{ (!matrix.run-example-tests || inputs.example-debug) && '1' || '0' }}
DEVBOX_EXAMPLE_TESTS: ${{ matrix.run-example-tests }}
# Used in `go test -timeout` flag. Needs a value that time.ParseDuration can parse.
DEVBOX_GOLANG_TEST_TIMEOUT: "${{ (github.ref == 'refs/heads/main' || inputs.run-mac-tests) && '35m' || '15m' }}"
DEVBOX_GOLANG_TEST_TIMEOUT: "${{ (github.ref == 'refs/heads/main' || inputs.run-mac-tests) && '35m' || '20m' }}"
run: |
go test -v -timeout $DEVBOX_GOLANG_TEST_TIMEOUT ./...

Expand Down
2 changes: 1 addition & 1 deletion examples/plugins/github-with-revision/devbox.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
}
},
"include": [
"github:jetpack-io/devbox-plugin-example/6ea0ef9e12ab58dbbb145ca8f3a465611cb603a9#devbox"
"github:jetpack-io/devbox-plugin-example/d9c00334353c9b1294c7bd5dbea128c149b2eb3a"
]
}
2 changes: 1 addition & 1 deletion examples/plugins/github/devbox.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
},
"include": [
"github:jetpack-io/devbox-plugin-example",
"github:jetpack-io/devbox-plugin-example#custom-name"
"github:jetpack-io/devbox-plugin-example?dir=custom-dir"
]
}
29 changes: 15 additions & 14 deletions internal/plugin/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"

"github.com/pkg/errors"
"github.com/samber/lo"
"go.jetpack.io/devbox/internal/boxcli/usererr"
"go.jetpack.io/devbox/internal/cuecfg"
)
Expand All @@ -17,31 +16,33 @@ type githubPlugin struct {
org string
repo string
revision string
fragment string
dir string
}

// newGithubPlugin returns a plugin that is hosted on github.
// url is of the form org/repo#name
// The repo must have a [name].json in the root of the repo. If fragment is
// not set, it defaults to "default"
func newGithubPlugin(url string) (*githubPlugin, error) {
path, fragment, _ := strings.Cut(url, "#")
// url is of the form org/repo?dir=<dir>
// The (optional) dir must have a plugin.json"
func newGithubPlugin(rawURL string) (*githubPlugin, error) {
pluginURL, err := url.Parse(rawURL)
if err != nil {
return nil, err
}

parts := strings.Split(path, "/")
parts := strings.Split(pluginURL.Path, "/")

if len(parts) < 2 || len(parts) > 3 {
return nil, usererr.New(
"invalid github plugin url %q. Must be of the form org/repo/[revision]",
url,
rawURL,
)
}

plugin := &githubPlugin{
raw: url,
raw: rawURL,
org: parts[0],
repo: parts[1],
revision: "master",
fragment: fragment,
dir: pluginURL.Query().Get("dir"),
}

if len(parts) == 3 {
Expand All @@ -68,6 +69,7 @@ func (p *githubPlugin) FileContent(subpath string) ([]byte, error) {
p.org,
p.repo,
p.revision,
p.dir,
subpath,
)
if err != nil {
Expand All @@ -82,7 +84,7 @@ func (p *githubPlugin) FileContent(subpath string) ([]byte, error) {
if res.StatusCode != http.StatusOK {
return nil, usererr.New(
"failed to get plugin github:%s (Status code %d). \nPlease make sure a "+
"[name].json or default.json file exists in the root of the repo.",
"plugin.json file exists in plugin directory.",
p.raw,
res.StatusCode,
)
Expand All @@ -91,8 +93,7 @@ func (p *githubPlugin) FileContent(subpath string) ([]byte, error) {
}

func (p *githubPlugin) buildConfig(projectDir string) (*config, error) {
configName, _ := lo.Coalesce(p.fragment, "default")
content, err := p.FileContent(configName + ".json")
content, err := p.FileContent("plugin.json")
if err != nil {
return nil, errors.WithStack(err)
}
Expand Down