Skip to content
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

feat(pkgbuild): use gitlab git repo for retrieving PKGBUILDs #2177

Merged
merged 1 commit into from
May 22, 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
50 changes: 11 additions & 39 deletions pkg/download/abs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,30 @@ import (

const (
MaxConcurrentFetch = 20
_urlPackagePath = "%s/raw/packages/%s/trunk/PKGBUILD"
_urlPackagePath = "https://gitlab.archlinux.org/archlinux/packaging/packages/0ad/-/raw/main/PKGBUILD"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't _urlPackagePath unused?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, curious it wasn't flagged by the linter. Opening a PR now

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

absPackageURL = "https://gitlab.archlinux.org/archlinux/packaging/packages"
)

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"
)

func getRepoURL(db string) (string, error) {
switch db {
case "core", "extra", "testing":
return ABSPackageURL, nil
case "community", "multilib", "community-testing", "multilib-testing":
return ABSCommunityURL, nil
}

return "", ErrInvalidRepository
}

// Return format for pkgbuild
// https://github.com/archlinux/svntogit-community/raw/packages/neovim/trunk/PKGBUILD
func getPackageURL(db, pkgName string) (string, error) {
repoURL, err := getRepoURL(db)
if err != nil {
return "", err
}

return fmt.Sprintf(_urlPackagePath, repoURL, pkgName), err
// https://gitlab.archlinux.org/archlinux/packaging/packages/0ad/-/raw/main/PKGBUILD
func getPackagePKGBUILDURL(pkgName string) string {
return fmt.Sprintf("%s/%s/-/raw/main/PKGBUILD", absPackageURL, pkgName)
}

// Return format for pkgbuild repo
// https://github.com/archlinux/svntogit-community.git
func getPackageRepoURL(db string) (string, error) {
repoURL, err := getRepoURL(db)
if err != nil {
return "", err
}

return repoURL + ".git", err
// https://gitlab.archlinux.org/archlinux/packaging/packages/0ad.git
func getPackageRepoURL(pkgName string) string {
return fmt.Sprintf("%s/%s.git", absPackageURL, pkgName)
}

// ABSPKGBUILD retrieves the PKGBUILD file to a dest directory.
func ABSPKGBUILD(httpClient httpRequestDoer, dbName, pkgName string) ([]byte, error) {
packageURL, err := getPackageURL(dbName, pkgName)
if err != nil {
return nil, err
}
packageURL := getPackagePKGBUILDURL(pkgName)

resp, err := httpClient.Get(packageURL)
if err != nil {
Expand All @@ -87,11 +62,8 @@ func ABSPKGBUILD(httpClient httpRequestDoer, dbName, pkgName string) ([]byte, er
func ABSPKGBUILDRepo(ctx context.Context, cmdBuilder exe.GitCmdBuilder,
dbName, pkgName, dest string, force bool,
) (bool, error) {
pkgURL, err := getPackageRepoURL(dbName)
if err != nil {
return false, err
}
pkgURL := getPackageRepoURL(pkgName)

return downloadGitRepo(ctx, cmdBuilder, pkgURL,
pkgName, dest, force, "--single-branch", "-b", "packages/"+pkgName)
pkgName, dest, force, "--single-branch")
}
50 changes: 22 additions & 28 deletions pkg/download/abs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ func Test_getPackageURL(t *testing.T) {
wantErr bool
}{
{
name: "community package",
name: "extra package",
args: args{
db: "community",
db: "extra",
pkgName: "kitty",
},
want: "https://github.com/archlinux/svntogit-community/raw/packages/kitty/trunk/PKGBUILD",
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/kitty/-/raw/main/PKGBUILD",
wantErr: false,
},
{
Expand All @@ -61,27 +61,24 @@ func Test_getPackageURL(t *testing.T) {
db: "core",
pkgName: "linux",
},
want: "https://github.com/archlinux/svntogit-packages/raw/packages/linux/trunk/PKGBUILD",
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/linux/-/raw/main/PKGBUILD",
wantErr: false,
},
{
name: "personal repo package",
args: args{
db: "sweswe",
pkgName: "linux",
pkgName: "zabix",
},
want: "",
wantErr: true,
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/zabix/-/raw/main/PKGBUILD",
wantErr: false,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, err := getPackageURL(tt.args.db, tt.args.pkgName)
if tt.wantErr {
assert.ErrorIs(t, err, ErrInvalidRepository)
}
got := getPackagePKGBUILDURL(tt.args.pkgName)
assert.Equal(t, tt.want, got)
})
}
Expand Down Expand Up @@ -110,7 +107,7 @@ func TestGetABSPkgbuild(t *testing.T) {
body: gitExtrasPKGBUILD,
status: 200,
pkgName: "git-extras",
wantURL: "https://github.com/archlinux/svntogit-packages/raw/packages/git-extras/trunk/PKGBUILD",
wantURL: "https://gitlab.archlinux.org/archlinux/packaging/packages/git-extras/-/raw/main/PKGBUILD",
},
want: gitExtrasPKGBUILD,
wantErr: false,
Expand All @@ -122,7 +119,7 @@ func TestGetABSPkgbuild(t *testing.T) {
body: "",
status: 404,
pkgName: "git-git",
wantURL: "https://github.com/archlinux/svntogit-packages/raw/packages/git-git/trunk/PKGBUILD",
wantURL: "https://gitlab.archlinux.org/archlinux/packaging/packages/git-git/-/raw/main/PKGBUILD",
},
want: "",
wantErr: true,
Expand Down Expand Up @@ -154,7 +151,7 @@ func Test_getPackageRepoURL(t *testing.T) {
t.Parallel()

type args struct {
db string
pkgName string
}
tests := []struct {
name string
Expand All @@ -163,32 +160,29 @@ func Test_getPackageRepoURL(t *testing.T) {
wantErr bool
}{
{
name: "community package",
args: args{db: "community"},
want: "https://github.com/archlinux/svntogit-community.git",
name: "extra package",
args: args{pkgName: "zoxide"},
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/zoxide.git",
wantErr: false,
},
{
name: "core package",
args: args{db: "core"},
want: "https://github.com/archlinux/svntogit-packages.git",
args: args{pkgName: "linux"},
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/linux.git",
wantErr: false,
},
{
name: "personal repo package",
args: args{db: "sweswe"},
want: "",
wantErr: true,
args: args{pkgName: "sweswe"},
want: "https://gitlab.archlinux.org/archlinux/packaging/packages/sweswe.git",
wantErr: false,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, err := getPackageRepoURL(tt.args.db)
if tt.wantErr {
assert.ErrorIs(t, err, ErrInvalidRepository)
}
got := getPackageRepoURL(tt.args.pkgName)
assert.Equal(t, tt.want, got)
})
}
Expand All @@ -200,13 +194,13 @@ func Test_getPackageRepoURL(t *testing.T) {
func TestABSPKGBUILDRepo(t *testing.T) {
t.Parallel()
cmdRunner := &testRunner{}
want := "/usr/local/bin/git --no-replace-objects -C /tmp/doesnt-exist clone --no-progress --single-branch -b packages/linux https://github.com/archlinux/svntogit-packages.git linux"
want := "/usr/local/bin/git --no-replace-objects -C /tmp/doesnt-exist clone --no-progress --single-branch https://gitlab.archlinux.org/archlinux/packaging/packages/linux.git linux"
if os.Getuid() == 0 {
ld := "systemd-run"
if path, _ := exec.LookPath(ld); path != "" {
ld = path
}
want = fmt.Sprintf("%s --service-type=oneshot --pipe --wait --pty --quiet -p DynamicUser=yes -p CacheDirectory=yay -E HOME=/tmp --no-replace-objects -C /tmp/doesnt-exist clone --no-progress --single-branch -b packages/linux https://github.com/archlinux/svntogit-packages.git linux", ld)
want = fmt.Sprintf("%s --service-type=oneshot --pipe --wait --pty --quiet -p DynamicUser=yes -p CacheDirectory=yay -E HOME=/tmp --no-replace-objects -C /tmp/doesnt-exist clone --no-progress --single-branch https://gitlab.archlinux.org/archlinux/packaging/packages/linux.git linux", ld)
}

cmdBuilder := &testGitBuilder{
Expand Down
4 changes: 2 additions & 2 deletions pkg/download/unified_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ func TestPKGBUILDFull(t *testing.T) {
Reply(200).
BodyString("example_yay-bin")

gock.New("https://github.com/").
Get("/archlinux/svntogit-packages/raw/packages/yay/trunk/PKGBUILD").
gock.New("https://gitlab.archlinux.org/").
Get("archlinux/packaging/packages/yay/-/raw/main/PKGBUILD").
Reply(200).
BodyString("example_yay")

Expand Down