diff options
author | Max Magorsch <arzano@gentoo.org> | 2020-06-01 20:51:10 +0200 |
---|---|---|
committer | Max Magorsch <arzano@gentoo.org> | 2020-06-01 20:51:10 +0200 |
commit | a1e34d7af9ca5e382b3fbdd53ea828f47f46fd70 (patch) | |
tree | 3d9e75e1851bc22e006a814dff2bfa71f0357c39 | |
parent | Add the outdated packages to the graphql api (diff) | |
download | soko-a1e34d7af9ca5e382b3fbdd53ea828f47f46fd70.tar.gz soko-a1e34d7af9ca5e382b3fbdd53ea828f47f46fd70.tar.bz2 soko-a1e34d7af9ca5e382b3fbdd53ea828f47f46fd70.zip |
Add pkgcheck results
qa-reports.gentoo.org will be used for now to
fetch the pkgcheck results.
All results will be stored in a database table
so that they might be retrieved via the api or
displayed in the UI in future.
Signed-off-by: Max Magorsch <arzano@gentoo.org>
-rw-r--r-- | pkg/database/connection.go | 1 | ||||
-rw-r--r-- | pkg/models/pkgcheckresult.go | 13 | ||||
-rw-r--r-- | pkg/portage/pkgcheck/parse.go | 87 | ||||
-rw-r--r-- | soko.go | 4 |
4 files changed, 105 insertions, 0 deletions
diff --git a/pkg/database/connection.go b/pkg/database/connection.go index 4aa5226..cd6d218 100644 --- a/pkg/database/connection.go +++ b/pkg/database/connection.go @@ -32,6 +32,7 @@ func CreateSchema() error { (*models.Mask)(nil), (*models.MaskToVersion)(nil), (*models.OutdatedPackages)(nil), + (*models.PkgCheckResult)(nil), (*models.Application)(nil)} { err := DBCon.CreateTable(model, &orm.CreateTableOptions{ diff --git a/pkg/models/pkgcheckresult.go b/pkg/models/pkgcheckresult.go new file mode 100644 index 0000000..b105000 --- /dev/null +++ b/pkg/models/pkgcheckresult.go @@ -0,0 +1,13 @@ +// Contains the model of a pkgcheckresults + +package models + +type PkgCheckResult struct { + Atom string + Category string + Package string + Version string + CPV string + Class string + Message string +} diff --git a/pkg/portage/pkgcheck/parse.go b/pkg/portage/pkgcheck/parse.go new file mode 100644 index 0000000..e678a1b --- /dev/null +++ b/pkg/portage/pkgcheck/parse.go @@ -0,0 +1,87 @@ +package pkgcheck + +import ( + "encoding/xml" + "io/ioutil" + "log" + "net/http" + "soko/pkg/config" + "soko/pkg/database" + "soko/pkg/logger" + "soko/pkg/models" +) + +// Descriptions of the xml format of the pkgcheck reports + +type PkgCheckResults struct { + XMLName xml.Name `xml:"checks"` + Results []PkgCheckResult `xml:"result"` +} + +type PkgCheckResult struct { + XMLName xml.Name `xml:"result"` + Category string `xml:"category"` + Package string `xml:"package"` + Version string `xml:"version"` + Class string `xml:"class"` + Message string `xml:"msg"` +} + +// UpdatePkgCheckResults will update the database table that contains all pkgcheck results +func UpdatePkgCheckResults() { + + database.Connect() + defer database.DBCon.Close() + + if config.Quiet() == "true" { + log.SetOutput(ioutil.Discard) + } + + // get the pkg check results from qa-reports.gentoo.org + pkgCheckResults, err := parseQAReport() + if err != nil { + logger.Error.Println("Error while parsing qa-reports data. Aborting...") + } + + // clean up the database + deleteAllPkgCheckResults() + + // update the database with the new results + for _, pkgCheckResult := range pkgCheckResults.Results { + database.DBCon.Insert(&models.PkgCheckResult{ + Atom: pkgCheckResult.Category + "/" + pkgCheckResult.Package, + Category: pkgCheckResult.Category, + Package: pkgCheckResult.Package, + Version: pkgCheckResult.Version, + CPV: pkgCheckResult.Category + "/" + pkgCheckResult.Package + "-" + pkgCheckResult.Version, + Class: pkgCheckResult.Class, + Message: pkgCheckResult.Message, + }) + } + +} + +// parseQAReport gets the xml from qa-reports.gentoo.org and parses it +func parseQAReport() (PkgCheckResults, error) { + resp, err := http.Get("https://qa-reports.gentoo.org/output/gentoo-ci/output.xml") + if err != nil { + return PkgCheckResults{}, err + } + defer resp.Body.Close() + xmlData, err := ioutil.ReadAll(resp.Body) + if err != nil { + return PkgCheckResults{}, err + } + var pkgCheckResults PkgCheckResults + xml.Unmarshal(xmlData, &pkgCheckResults) + return pkgCheckResults, err +} + +// deleteAllOutdated deletes all entries in the outdated table +func deleteAllPkgCheckResults() { + var allPkgCheckResults []*models.PkgCheckResult + database.DBCon.Model(&allPkgCheckResults).Select() + for _, pkgCheckResult := range allPkgCheckResults { + database.DBCon.Model(pkgCheckResult).WherePK().Delete() + } +} @@ -9,6 +9,7 @@ import ( "soko/pkg/config" "soko/pkg/logger" "soko/pkg/portage" + "soko/pkg/portage/pkgcheck" "soko/pkg/portage/repology" "time" ) @@ -18,6 +19,7 @@ func printHelp() { fmt.Println(" soko update -- incrementally update the database") fmt.Println(" soko fullupdate -- update the database ") fmt.Println(" soko update-outdated-packages -- update the database containing all outdated gentoo packages") + fmt.Println(" soko update-pgkcheck-results -- update the database containing all pkgcheck results") fmt.Println(" soko serve -- serve the application") } @@ -41,6 +43,8 @@ func main() { portage.FullUpdate() } else if isCommand("update-outdated-packages") { repology.UpdateOutdated() + } else if isCommand("update-pgkcheck-results") { + pkgcheck.UpdatePkgCheckResults() } else { printHelp() } |