Skip to content

Commit

Permalink
feat: enable empty owner repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
b4nst committed Aug 2, 2021
1 parent 8dc3a67 commit 5cc011c
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
4 changes: 4 additions & 0 deletions lib/mod/cache/util.go
Expand Up @@ -13,6 +13,10 @@ func parseModURL(mod string) (remote, owner, repo string) {
flds = strings.Split(mod, "/")
}

if len(flds) < 3 {
return flds[0], "", flds[1]
}

return flds[0], flds[1], flds[2]
}

Expand Down
8 changes: 5 additions & 3 deletions lib/mod/cache/util_test.go
@@ -1,7 +1,7 @@
package cache

import (
"fmt"
"path"
"testing"
)

Expand All @@ -15,13 +15,15 @@ func TestSplitMod(t *testing.T) {
"complex": {mod: "gitlab.com/owner/repo.git/submodule", expected: "gitlab.com/owner/repo"},
"subgroup": {mod: "gitlab.com/owner/subgroup/repo.git", expected: "gitlab.com/owner/subgroup/repo"},
"subgroup+submodule": {mod: "gitlab.com/owner/subgroup/repo.git/submodule", expected: "gitlab.com/owner/subgroup/repo"},
"small": {mod: "cuelang.org/go", expected: "cuelang.org/go"},
}

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
rm, o, rp := parseModURL(tc.mod)
if fmt.Sprintf("%s/%s/%s", rm, o, rp) != tc.expected {
t.Fatalf("expected: %v, got: %s/%s/%s", tc.expected, rm, o, rp)
got := path.Join(rm, o, rp)
if got != tc.expected {
t.Fatalf("expected: %v, got: %s", tc.expected, got)
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion lib/mod/langs/cue.go
@@ -1,7 +1,7 @@
package langs

const CuelangModder = `
cue: {
langs: cue: {
Name: "cue"
Version: "v0.4.0"
ModFile: "cue.mods"
Expand Down
1 change: 1 addition & 0 deletions lib/mod/langs/spec.go
Expand Up @@ -10,6 +10,7 @@ langs: #Spec
SumFile: string,
ModsDir: string,
MappingFile: string,
PrivateEnvVar?: string,
NoLoad?: bool,
CommandInit?: [...[...string]],
Expand Down
8 changes: 5 additions & 3 deletions lib/yagu/repos/git/fetch.go
Expand Up @@ -3,6 +3,7 @@ package git
import (
"fmt"
"os"
"path"
"strings"

"github.com/go-git/go-billy/v5"
Expand Down Expand Up @@ -93,8 +94,9 @@ func CloneRepoRef(srcUrl string, ref *plumbing.Reference) (*GitRepo, error) {
// FetchGit clone the repository inside FS.
// If private flag is set, it will look for netrc credentials, fallbacking to SSH
func FetchGit(FS billy.Filesystem, remote, owner, repo, tag string, private bool) error {
srcRepo := path.Join(owner, repo)
gco := &gogit.CloneOptions{
URL: fmt.Sprintf("https://%s/%s/%s", remote, owner, repo),
URL: fmt.Sprintf("https://%s/%s", remote, srcRepo),
Depth: 1,
}

Expand All @@ -111,9 +113,9 @@ func FetchGit(FS billy.Filesystem, remote, owner, repo, tag string, private bool
}
} else if ssh, err := SSHCredentials(remote); err == nil {
gco.Auth = ssh.Keys
gco.URL = fmt.Sprintf("%s@%s:%s/%s", ssh.User, remote, owner, repo)
gco.URL = fmt.Sprintf("%s@%s:%s", ssh.User, remote, srcRepo)
} else {
gco.URL = fmt.Sprintf("%s@%s:%s/%s", "git", remote, owner, repo)
gco.URL = fmt.Sprintf("%s@%s:%s", "git", remote, srcRepo)
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/yagu/repos/gitlab/fetch.go
Expand Up @@ -4,6 +4,7 @@ import (
"archive/zip"
"bytes"
"fmt"
"path"

"github.com/xanzy/go-gitlab"
)
Expand All @@ -24,7 +25,7 @@ func fetchShaZip(client *gitlab.Client, pid interface{}, sha string) (*zip.Reade
}

func FetchZip(client *gitlab.Client, owner, repo, tag string) (*zip.Reader, error) {
pid := fmt.Sprintf("%s/%s", owner, repo)
pid := path.Join(owner, repo)

var sha string

Expand Down

0 comments on commit 5cc011c

Please sign in to comment.