3 Commits
1.0.1 ... 1.0.3

Author SHA1 Message Date
8be1c59065 handle api return codes 2025-03-23 22:13:01 +01:00
dde049fb75 Update README.md 2025-03-23 16:01:01 +01:00
f0e02ba38f use packages instead of pkgbases for output 2025-03-23 15:58:29 +01:00
4 changed files with 17 additions and 15 deletions

View File

@@ -1,3 +1,3 @@
# ALHP.NOGO # ALHP.utils
Utility to check if one of your packages is building Utility to check if one of your packages is building

1
go.mod
View File

@@ -4,7 +4,6 @@ go 1.24
require ( require (
github.com/Jguer/go-alpm/v2 v2.2.2 github.com/Jguer/go-alpm/v2 v2.2.2
github.com/deckarep/golang-set/v2 v2.8.0
github.com/sirupsen/logrus v1.9.3 github.com/sirupsen/logrus v1.9.3
somegit.dev/ALHP/ALHP.GO v0.0.0-20250322224907-01404adad53a somegit.dev/ALHP/ALHP.GO v0.0.0-20250322224907-01404adad53a
) )

2
go.sum
View File

@@ -9,8 +9,6 @@ github.com/Morganamilo/go-pacmanconf v0.0.0-20210502114700-cff030e927a5/go.mod h
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deckarep/golang-set/v2 v2.8.0 h1:swm0rlPCmdWn9mESxKOjWk8hXSqoxOp+ZlfuyaAdFlQ=
github.com/deckarep/golang-set/v2 v2.8.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

27
main.go
View File

@@ -5,7 +5,6 @@ import (
"flag" "flag"
"fmt" "fmt"
"github.com/Jguer/go-alpm/v2" "github.com/Jguer/go-alpm/v2"
"github.com/deckarep/golang-set/v2"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"io" "io"
"net/http" "net/http"
@@ -25,8 +24,8 @@ var (
) )
type JSONOut struct { type JSONOut struct {
InQueue int `json:"in_queue"` Total int `json:"total"`
PackageBases []string `json:"package_base"` Packages []string `json:"packages"`
} }
func main() { func main() {
@@ -61,27 +60,27 @@ func main() {
} }
log.Debugf("alhp build queue length: %d", len(alhpQueue)) log.Debugf("alhp build queue length: %d", len(alhpQueue))
packagesInQueue := mapset.NewSet[string]() var packagesInQueue []string
for _, pkg := range db.PkgCache().Slice() { for _, pkg := range db.PkgCache().Slice() {
if Find(alhpQueue, pkg.Base()) != -1 { if Find(alhpQueue, pkg.Base()) != -1 {
log.Debugf("found package in queue: %s", pkg.Base()) log.Debugf("found package in queue: %s", pkg.Name())
packagesInQueue.Add(pkg.Base()) packagesInQueue = append(packagesInQueue, pkg.Name())
} }
} }
if !packagesInQueue.IsEmpty() { if len(packagesInQueue) > 0 {
log.Debugf("found %d of your local packages in queue", packagesInQueue.Cardinality()) log.Debugf("found %d of your local packages in queue", len(packagesInQueue))
if *jsonFlag { if *jsonFlag {
err = json.NewEncoder(os.Stdout).Encode(JSONOut{ err = json.NewEncoder(os.Stdout).Encode(JSONOut{
InQueue: packagesInQueue.Cardinality(), Total: len(packagesInQueue),
PackageBases: packagesInQueue.ToSlice(), Packages: packagesInQueue,
}) })
if err != nil { if err != nil {
log.Errorf("error encoding JSON: %v", err) log.Errorf("error encoding JSON: %v", err)
os.Exit(1) os.Exit(1)
} }
} else { } else {
fmt.Println(strings.Join(packagesInQueue.ToSlice(), "\n")) fmt.Println(strings.Join(packagesInQueue, "\n"))
} }
if *exitCodeFlag { if *exitCodeFlag {
@@ -128,6 +127,12 @@ func ALHPBuildQueuePkgbase() ([]string, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("ALHP api returned HTTP %d", resp.StatusCode)
} else if resp.StatusCode == http.StatusNotFound {
return nil, nil
}
bResp, err := io.ReadAll(resp.Body) bResp, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err