Pārlūkot izejas kodu

fix(download): fix -Gp for repository packages

jguer 3 gadi atpakaļ
vecāks
revīzija
20d5fd406f
3 mainītis faili ar 24 papildinājumiem un 16 dzēšanām
  1. 20 14
      pkg/download/abs.go
  2. 2 2
      pkg/download/abs_test.go
  3. 2 0
      pkg/download/unified.go

+ 20 - 14
pkg/download/abs.go

@@ -2,33 +2,39 @@ package download
 
 import (
 	"errors"
+	"fmt"
 	"io/ioutil"
 	"net/http"
-	"net/url"
 
 	"github.com/leonelquinteros/gotext"
 )
 
-var ErrInvalidRepository = errors.New(gotext.Get("invalid repository"))
-var ErrABSPackageNotFound = errors.New(gotext.Get("package not found in repos"))
-
-const MaxConcurrentFetch = 20
-const urlPackagePath = "/plain/trunk/PKGBUILD?"
+const (
+	MaxConcurrentFetch = 20
+	_urlPackagePath    = "%s/raw/packages/%s/trunk/PKGBUILD"
+)
 
-var ABSPackageURL = "https://github.com/archlinux/svntogit-packages.git"
-var ABSCommunityURL = "https://github.com/archlinux/svntogit-community.git"
+var (
+	ErrInvalidRepository  = errors.New(gotext.Get("invalid repository"))
+	ErrABSPackageNotFound = errors.New(gotext.Get("package not found in repos"))
+	ABSPackageURL         = "https://github.com/archlinux/svntogit-packages"
+	ABSCommunityURL       = "https://github.com/archlinux/svntogit-community"
+)
 
+// Return format for pkgbuild
+// https://github.com/archlinux/svntogit-community/raw/packages/neovim/trunk/PKGBUILD
 func getPackageURL(db, pkgName string) (string, error) {
-	values := url.Values{}
-	values.Set("h", "packages/"+pkgName)
-	nameEncoded := values.Encode()
+	repoURL := ""
 	switch db {
 	case "core", "extra", "testing":
-		return ABSPackageURL + urlPackagePath + nameEncoded, nil
+		repoURL = ABSPackageURL
 	case "community", "multilib", "community-testing", "multilib-testing":
-		return ABSCommunityURL + urlPackagePath + nameEncoded, nil
+		repoURL = ABSCommunityURL
+	default:
+		return "", ErrInvalidRepository
 	}
-	return "", ErrInvalidRepository
+
+	return fmt.Sprintf(_urlPackagePath, repoURL, pkgName), nil
 }
 
 func GetABSPkgbuild(httpClient *http.Client, dbName, pkgName string) ([]byte, error) {

+ 2 - 2
pkg/download/abs_test.go

@@ -46,7 +46,7 @@ func Test_getPackageURL(t *testing.T) {
 				db:      "community",
 				pkgName: "kitty",
 			},
-			want:    "https://github.com/archlinux/svntogit-community.git/plain/trunk/PKGBUILD?h=packages%2Fkitty",
+			want:    "https://github.com/archlinux/svntogit-community/raw/packages/kitty/trunk/PKGBUILD",
 			wantErr: false,
 		},
 		{
@@ -55,7 +55,7 @@ func Test_getPackageURL(t *testing.T) {
 				db:      "core",
 				pkgName: "linux",
 			},
-			want:    "https://github.com/archlinux/svntogit-packages.git/plain/trunk/PKGBUILD?h=packages%2Flinux",
+			want:    "https://github.com/archlinux/svntogit-packages/raw/packages/linux/trunk/PKGBUILD",
 			wantErr: false,
 		},
 		{

+ 2 - 0
pkg/download/unified.go

@@ -15,6 +15,7 @@ func getURLName(pkg db.IPackage) string {
 	if name == "" {
 		name = pkg.Name()
 	}
+
 	return name
 }
 
@@ -68,5 +69,6 @@ func GetPkgbuilds(dbExecutor db.Executor, httpClient *http.Client, targets []str
 	}
 
 	wg.Wait()
+
 	return pkgbuilds, errs.Return()
 }