Skip to content

Commit 6e93416

Browse files
fix: allow github plugins with slash in rev name (#1650)
## Summary You can't currently reference a plugin on a rev if that rev has a `/` character in it. This seems like a bug, here's a simple fix that I don't believe will cause any other issues (but I'm new to the codebase, so could be wrong). ## How was it tested? 1. Unit tests in this PR 2. Manual verification: **verify current build breaks:** ```sh devbox run build ./dist/devbox run echo "success" # works fine # add plugin with branch with slash -> `"include": ["github:jetpack-io/devbox-plugins/jl/add-readmes?dir=mongodb"]` ./dist/devbox run echo "success" # Error: invalid github plugin url "jetpack-io/devbox-plugins/jl/add-readmes?dir=mongodb". Must be of the form org/repo/[revision] ``` **checkout this branch and verify it works again:** ```sh git reset --hard git checkout jdr/allow-github-plugins-with-slash-in-rev-name devbox run build # add plugin with branch with slash -> `"include": ["github:jetpack-io/devbox-plugins/jl/add-readmes?dir=mongodb"]` ./dist/devbox run echo "success" # works fine ```
1 parent 8d7912a commit 6e93416

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

internal/plugin/github.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ func newGithubPlugin(rawURL string) (*githubPlugin, error) {
2828
return nil, err
2929
}
3030

31-
parts := strings.Split(pluginURL.Path, "/")
31+
parts := strings.SplitN(pluginURL.Path, "/", 3)
3232

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

internal/plugin/github_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package plugin
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestNewGithubPlugin(t *testing.T) {
10+
testCases := []struct {
11+
name string
12+
expected githubPlugin
13+
}{
14+
{
15+
name: "parse basic github plugin",
16+
expected: githubPlugin{
17+
raw: "jetpack-io/devbox-plugins",
18+
org: "jetpack-io",
19+
repo: "devbox-plugins",
20+
revision: "master",
21+
},
22+
},
23+
{
24+
name: "parse github plugin with dir param",
25+
expected: githubPlugin{
26+
raw: "jetpack-io/devbox-plugins?dir=mongodb",
27+
org: "jetpack-io",
28+
repo: "devbox-plugins",
29+
revision: "master",
30+
dir: "mongodb",
31+
},
32+
},
33+
{
34+
name: "parse github plugin with dir param and rev",
35+
expected: githubPlugin{
36+
raw: "jetpack-io/devbox-plugins/my-branch?dir=mongodb",
37+
org: "jetpack-io",
38+
repo: "devbox-plugins",
39+
revision: "my-branch",
40+
dir: "mongodb",
41+
},
42+
},
43+
{
44+
name: "parse github plugin with dir param and rev",
45+
expected: githubPlugin{
46+
raw: "jetpack-io/devbox-plugins/initials/my-branch?dir=mongodb",
47+
org: "jetpack-io",
48+
repo: "devbox-plugins",
49+
revision: "initials/my-branch",
50+
dir: "mongodb",
51+
},
52+
},
53+
}
54+
55+
for _, testCase := range testCases {
56+
t.Run(testCase.name, func(t *testing.T) {
57+
actual, _ := newGithubPlugin(testCase.expected.raw)
58+
assert.Equal(t, actual, &testCase.expected)
59+
})
60+
}
61+
}

0 commit comments

Comments
 (0)