From 7bb40840022ed88ee574207612d464ce1fdd4651 Mon Sep 17 00:00:00 2001 From: Shawn Smith Date: Tue, 23 Nov 2021 19:24:08 +0900 Subject: [PATCH] remove git download functionality --- download/download.go | 99 --------------------------------------- download/download_test.go | 38 --------------- handlers/checks.go | 9 +--- 3 files changed, 1 insertion(+), 145 deletions(-) delete mode 100644 download/download_test.go diff --git a/download/download.go b/download/download.go index 46dd414..4226a23 100644 --- a/download/download.go +++ b/download/download.go @@ -2,97 +2,11 @@ package download import ( "errors" - "log" - "net/url" - "os" - "path/filepath" "strings" "golang.org/x/tools/go/vcs" ) -// Download takes a user-provided string that represents a remote -// Go repository, and attempts to download it in a way similar to go get. -// It is forgiving in terms of the exact path given: the path may have -// a scheme or username, which will be trimmed. -func Download(path, dest string) (root *vcs.RepoRoot, err error) { - return download(path, dest, true) -} - -func download(path, dest string, firstAttempt bool) (root *vcs.RepoRoot, err error) { - vcs.ShowCmd = true - - path, err = Clean(path) - if err != nil { - return root, err - } - - root, err = vcs.RepoRootForImportPath(path, true) - if err != nil { - return root, err - } - - localDirPath := filepath.Join(dest, root.Root, "..") - - err = os.MkdirAll(localDirPath, 0777) - if err != nil { - return root, err - } - - fullLocalPath := filepath.Join(dest, root.Root) - ex, err := exists(fullLocalPath) - if err != nil { - return root, err - } - if ex { - log.Println("Update", root.Repo) - err = root.VCS.Download(fullLocalPath) - if err != nil && firstAttempt { - // may have been rebased; we delete the directory, then try one more time: - log.Printf("Failed to download %q (%v), trying again...", root.Repo, err.Error()) - err = os.RemoveAll(fullLocalPath) - if err != nil { - log.Println("Failed to delete path:", fullLocalPath, err) - } - return download(path, dest, false) - } else if err != nil { - return root, err - } - } else { - log.Println("Create", root.Repo) - - if root.VCS.Name == "Git" { - root.VCS.CreateCmd = "clone --depth 1 {repo} {dir}" - root.VCS.TagSyncDefault = "" - } - var rootRepo = root.Repo - u, err := url.Parse(root.Repo) - if err != nil { - log.Printf("WARN: could not parse root.Repo: %v", err) - } else { - if u.Host == "github.com" { - u.User = url.UserPassword("gojp", "gojp") - rootRepo = u.String() - } - } - err = root.VCS.Create(fullLocalPath, rootRepo) - if err != nil { - return root, err - } - } - err = root.VCS.TagSync(fullLocalPath, "") - if err != nil && firstAttempt { - // may have been rebased; we delete the directory, then try one more time: - log.Printf("Failed to update %q (%v), trying again...", root.Repo, err.Error()) - err = os.RemoveAll(fullLocalPath) - if err != nil { - log.Printf("Failed to delete directory %s", fullLocalPath) - } - return download(path, dest, false) - } - return root, err -} - // Clean trims any URL parts, like the scheme or username, that might be present // in a user-submitted URL func Clean(path string) (string, error) { @@ -129,16 +43,3 @@ func trimUsername(repo string) string { return repo } - -// exists returns whether the given file or directory exists or not -// from http://stackoverflow.com/a/10510783 -func exists(path string) (bool, error) { - _, err := os.Stat(path) - if err == nil { - return true, nil - } - if os.IsNotExist(err) { - return false, nil - } - return true, err -} diff --git a/download/download_test.go b/download/download_test.go deleted file mode 100644 index 2cd4334..0000000 --- a/download/download_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package download - -/* -var testDownloadDir = "test_downloads" - -func TestRepoRootForImportPath(t *testing.T) { - cases := []struct { - giveURL string - wantPath string - wantVCS string - }{ - {"github.com/gojp/goreportcard", "github.com/gojp/goreportcard", "git"}, - {"https://github.com/boltdb/bolt", "github.com/boltdb/bolt", "git"}, - {"https://bitbucket.org/rickb777/go-talk", "bitbucket.org/rickb777/go-talk", "hg"}, - {"ssh://hg@bitbucket.org/rickb777/go-talk", "bitbucket.org/rickb777/go-talk", "hg"}, - } - - for _, tt := range cases { - root, err := Download(tt.giveURL, testDownloadDir) - if err != nil { - t.Fatalf("Error calling Download(%q): %v", tt.giveURL, err) - } - - if root.Root != tt.wantPath { - t.Errorf("Download(%q): root.Repo = %q, want %q", tt.giveURL, root.Repo, tt.wantPath) - } - - wantPath := filepath.Join(testDownloadDir, tt.wantPath) - ex, _ := exists(wantPath) - if !ex { - t.Errorf("Download(%q): %q was not created", tt.giveURL, wantPath) - } - } - - // clean up the test - os.RemoveAll(testDownloadDir) -} -*/ diff --git a/handlers/checks.go b/handlers/checks.go index aed4887..168a1df 100644 --- a/handlers/checks.go +++ b/handlers/checks.go @@ -92,19 +92,12 @@ func newChecksResp(db *badger.DB, repo string, forceRefresh bool) (checksResp, e } } - // fetch the repo and grade it - //repoRoot, err := download.Download(repo, "_repos/src") - //if err != nil { - // return checksResp{}, fmt.Errorf("could not clone repo: %v", err) - //} - ver, err := download.ProxyDownload(repo) if err != nil { log.Println("ERROR:", err) - // return checksResp{}, fmt.Errorf("could not download repo: %v", err) + return checksResp{}, fmt.Errorf("could not download repo: %v", err) } - // repo = repoRoot.Root checkResult, err := check.Run(dirName(repo)) if err != nil { return checksResp{}, err