yay/pkg/download/aur.go

44 lines
1009 B
Go
Raw Normal View History

2020-12-15 01:29:05 +01:00
package download
import (
"fmt"
2020-12-15 01:29:05 +01:00
"io/ioutil"
"net/http"
"net/url"
2021-01-30 12:52:50 +01:00
"github.com/Jguer/yay/v10/pkg/settings/exe"
2020-12-15 01:29:05 +01:00
)
2021-01-30 12:52:50 +01:00
var AURPackageURL = "https://aur.archlinux.org/cgit/aur.git"
2020-12-15 01:29:05 +01:00
func AURPKGBUILD(httpClient *http.Client, pkgName string) ([]byte, error) {
2020-12-15 01:29:05 +01:00
values := url.Values{}
values.Set("h", pkgName)
2021-01-30 12:52:50 +01:00
pkgURL := AURPackageURL + "/plain/PKGBUILD?" + values.Encode()
2020-12-15 01:29:05 +01:00
2021-01-30 12:52:50 +01:00
resp, err := httpClient.Get(pkgURL)
2020-12-15 01:29:05 +01:00
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, ErrAURPackageNotFound{pkgName: pkgName}
2020-12-15 01:29:05 +01:00
}
defer resp.Body.Close()
pkgBuild, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return pkgBuild, nil
}
// AURPkgbuildRepo retrieves the PKGBUILD repository to a dest directory.
func AURPKGBUILDRepo(cmdRunner exe.Runner, cmdBuilder exe.GitCmdBuilder, aurURL, pkgName, dest string, force bool) error {
pkgURL := fmt.Sprintf("%s/%s.git", aurURL, pkgName)
return downloadGitRepo(cmdRunner, cmdBuilder, pkgURL, pkgName, dest, force)
}