This commit is contained in:
Adam Majer 2024-07-21 22:15:11 +02:00
parent bce3b68b76
commit 54e418acaf
4 changed files with 513 additions and 54 deletions

View File

@ -11926,13 +11926,13 @@ paths:
title: test 1 title: test 1
who: Administrator who: Administrator
state: new state: new
when: 2021-09-30 09:12:02.000000000 +02:00 when: 2021-09-30 07:12:02.000000000 +00:00
event_type: review_wanted event_type: review_wanted
- id: 25 - id: 25
title: test 2 title: test 2
who: User 2 who: User 2
event_type: comment_for_package event_type: comment_for_package
when: 2021-09-27 09:16:19.000000000 +02:00 when: 2021-09-27 07:16:19.000000000 +00:00
'401': '401':
description: | description: |
Unauthorized. Unauthorized.
@ -31231,6 +31231,13 @@ paths:
required: true required: true
description: Package name description: Package name
example: ctris example: ctris
- in: query
name: deleted
schema:
type: string
enum:
-
description: Set to retrieve the package metadata of a deleted package.
- in: query - in: query
name: meta name: meta
schema: schema:

183
bots-common/obs_utils.go Normal file
View File

@ -0,0 +1,183 @@
package common
import (
"encoding/xml"
"fmt"
"io"
"log"
"net/http"
"net/url"
)
type ObsClient struct {
baseUrl *url.URL
client *http.Client
user, password string
cookie string
}
func NewObsClient(host, username, password string) (*ObsClient, error) {
baseUrl, err := url.Parse("https://" + host)
if err != nil {
return nil, err
}
return &ObsClient{
baseUrl: baseUrl,
client: &http.Client{},
user: username,
password: password,
}, nil
}
type RepositoryMeta struct {
Name string `xml:"name,attr"`
Arch []string `xml:"arch"`
Path []struct {
XMLName xml.Name `xml:"path"`
Project string `xml:"project,attr"`
Repository string `xml:"repository,attr"`
}
}
type ProjectMeta struct {
XMLName xml.Name `xml:"project"`
Name string `xml:"name,attr"`
Title string `xml:"title"`
Description string `xml:"description"`
ScmSync string `xml:"xmlsync"`
Repositories []Repository `xml:"repository"`
}
func parseProjectMeta(data []byte) (*ProjectMeta, error) {
var meta ProjectMeta
err := xml.Unmarshal(data, &meta)
if err != nil {
return nil, err
}
return &meta, nil
}
func (c *ObsClient) GetProjectMeta(project string) (*ProjectMeta, error) {
req, err := http.NewRequest("GET", c.baseUrl.JoinPath("source", project, "_meta").String(), nil)
if err != nil {
return nil, err
}
req.SetBasicAuth(c.user, c.password)
res, err := c.client.Do(req)
if err != nil {
return nil, err
}
switch res.StatusCode {
case 200:
break
case 404:
return nil, nil
default:
return nil, fmt.Errorf("Unexpected return code: %d", res.StatusCode)
}
data, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}
return parseProjectMeta(data)
}
func (c *ObsClient) DeleteProject(project string) error {
req, err := http.NewRequest("DELETE", c.baseUrl.JoinPath("source", project).String(), nil)
if err != nil {
return err
}
req.SetBasicAuth(c.user, c.password)
res, err := c.client.Do(req)
if err != nil {
return err
}
if res.StatusCode != 200 {
return fmt.Errorf("Unexpected return code: %d", res.StatusCode)
}
return nil
}
type BuildStatus struct {
Package string `xml:"package,attr"`
Code string `xml:"code,attr"`
Details string `xml:"details"`
}
type BuildResult struct {
Project string `xml:"project,attr"`
Repository string `xml:"repository,attr"`
Arch string `xml:"arch,attr"`
Code string `xml:"code,attr"`
Status []BuildStatus `xml:"status"`
Binaries []BinaryList `xml:"binarylist"`
}
type Binary struct {
Size uint64 `xml:"size,attr"`
Filename string `xml:"filename,attr"`
Mtime uint64 `xml:"mtime,attr"`
}
type BinaryList struct {
Package string `xml:"package,attr"`
Binary []Binary `xml:"binary"`
}
type BuildResultList struct {
XMLName xml.Name `xml:"resultlist"`
Result []BuildResult `xml:"result"`
}
func parseBuildResults(data []byte) (*BuildResultList, error) {
result := BuildResultList{}
err := xml.Unmarshal(data, &result)
if err != nil {
return nil, err
}
return &result, nil
}
func (c *ObsClient) BuildStatus(project string) (*BuildResultList, error) {
u := c.baseUrl.JoinPath("build", project, "_result")
query := u.Query()
query.Add("view", "status")
query.Add("view", "binarylist")
query.Add("multibuild", "1")
u.RawQuery = query.Encode()
req, err := http.NewRequest("GET", u.String(), nil)
log.Print(u.String())
if err != nil {
return nil, err
}
req.SetBasicAuth(c.user, c.password)
res, err := c.client.Do(req)
if err != nil {
return nil, err
}
if res.StatusCode != 200 {
return nil, fmt.Errorf("Unexpected return code: %d", res.StatusCode)
}
data, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}
return parseBuildResults(data)
}

View File

@ -0,0 +1,266 @@
package common
import (
"testing"
)
func TestParseProjectMeta(t *testing.T) {
res, err := parseProjectMeta([]byte(metaPrjData))
if err != nil {
return t.Fatal(err)
}
if res.
}
func TestParsingOfBuildResults(t *testing.T) {
res, err := parseBuildResults([]byte(buildResultData))
if err != nil {
t.Fatal(err)
}
if res.Result[0].Project != "home:adamm" ||
res.Result[0].Status[1].Details != "nothing provides libBox2D-devel" ||
res.Result[0].Status[0].Code != "excluded" {
t.Fatal(res.Result)
}
if res.Result[0].Binaries[0].Package != "Nudoku" ||
len(res.Result[0].Binaries[0].Binary) != 0 {
t.Fatal(res.Result[0].Binaries[0])
}
}
const metaPrjData = `
<project name="home:adamm">
<title>Adam's Home Projects</title>
<description/>
<person userid="adamm" role="maintainer"/>
<build>
<enable/>
</build>
<publish>
<enable/>
</publish>
<repository name="openSUSE_Tumbleweed">
<path project="openSUSE:Tumbleweed" repository="standard"/>
<arch>x86_64</arch>
<arch>aarch64</arch>
</repository>
<repository name="containerfile">
<path project="openSUSE:Containers:Tumbleweed" repository="containers"/>
<path project="openSUSE:Factory:ARM" repository="standard"/>
<arch>aarch64</arch>
</repository>
<repository name="container">
<path project="openSUSE:Containers:Tumbleweed" repository="containers"/>
<path project="openSUSE:Factory:ARM" repository="standard"/>
<arch>aarch64</arch>
</repository>
</project>
`
const buildResultData = `
<resultlist state="4c058c53835d10cbbfc6f0ee546a921f">
<result project="home:adamm" repository="openSUSE_Tumbleweed" arch="x86_64" code="published" state="published">
<status package="Nudoku" code="excluded"/>
<status package="geekofall" code="unresolvable">
<details>nothing provides libBox2D-devel</details>
</status>
<status package="geekofall.1" code="unresolvable">
<details>nothing provides libBox2D-devel</details>
</status>
<status package="http-parser" code="failed"/>
<status package="minicoredumper" code="failed"/>
<status package="opensuse-dovecot-image" code="broken">
<details>conflict in file _service</details>
</status>
<status package="opensuse-nsd-image" code="disabled"/>
<status package="opensuse-opendkim-image" code="excluded"/>
<status package="test" code="broken">
<details>no source uploaded</details>
</status>
<status package="visual-studio-rpi-pico-sshd-image" code="excluded"/>
<binarylist package="Nudoku"/>
<binarylist package="geekofall">
<binary filename="_buildenv" size="162675" mtime="1613557547"/>
<binary filename="_statistics" size="955" mtime="1613557547"/>
<binary filename="geekofall-1536436213.a078a60-13.37.src.rpm" size="30213" mtime="1613557547"/>
<binary filename="geekofall-1536436213.a078a60-13.37.x86_64.rpm" size="87666" mtime="1613557547"/>
<binary filename="geekofall-debuginfo-1536436213.a078a60-13.37.x86_64.rpm" size="43740" mtime="1613557547"/>
<binary filename="rpmlint.log" size="990" mtime="1613557546"/>
</binarylist>
<binarylist package="geekofall.1">
<binary filename="_buildenv" size="161411" mtime="1613557546"/>
<binary filename="_statistics" size="955" mtime="1613557546"/>
<binary filename="geekofall-1.0-1.36.src.rpm" size="39526" mtime="1613557547"/>
<binary filename="geekofall-1.0-1.36.x86_64.rpm" size="87583" mtime="1613557547"/>
<binary filename="geekofall-debuginfo-1.0-1.36.x86_64.rpm" size="43907" mtime="1613557547"/>
<binary filename="rpmlint.log" size="308" mtime="1613557546"/>
</binarylist>
<binarylist package="http-parser">
<binary filename="_buildenv" size="13162" mtime="1490341842"/>
<binary filename="_statistics" size="702" mtime="1490341842"/>
<binary filename="http-parser-2.7.1-1.7.src.rpm" size="58213" mtime="1490341842"/>
<binary filename="libhttp_parser-devel-2.7.1-1.7.x86_64.rpm" size="11596" mtime="1490341843"/>
<binary filename="libhttp_parser2-2.7.1-1.7.x86_64.rpm" size="24523" mtime="1490341843"/>
<binary filename="rpmlint.log" size="322" mtime="1490341842"/>
</binarylist>
<binarylist package="minicoredumper">
<binary filename="_buildenv" size="160856" mtime="1631825754"/>
<binary filename="_statistics" size="952" mtime="1631825754"/>
<binary filename="libminicoredumper2-2.0.1-2.41.x86_64.rpm" size="11789" mtime="1631825754"/>
<binary filename="libminicoredumper2-debuginfo-2.0.1-2.41.x86_64.rpm" size="17071" mtime="1631825755"/>
<binary filename="minicoredumper-2.0.1-2.41.src.rpm" size="303867" mtime="1631825755"/>
<binary filename="minicoredumper-2.0.1-2.41.x86_64.rpm" size="41509" mtime="1631825755"/>
<binary filename="minicoredumper-debuginfo-2.0.1-2.41.x86_64.rpm" size="83137" mtime="1631825755"/>
<binary filename="minicoredumper-debugsource-2.0.1-2.41.x86_64.rpm" size="40197" mtime="1631825755"/>
<binary filename="minicoredumper-devel-2.0.1-2.41.x86_64.rpm" size="14717" mtime="1631825755"/>
<binary filename="minicoredumper-utils-2.0.1-2.41.x86_64.rpm" size="21336" mtime="1631825755"/>
<binary filename="minicoredumper-utils-debuginfo-2.0.1-2.41.x86_64.rpm" size="32338" mtime="1631825755"/>
<binary filename="rpmlint.log" size="1466" mtime="1631825754"/>
</binarylist>
<binarylist package="opensuse-dovecot-image"/>
<binarylist package="opensuse-nsd-image"/>
<binarylist package="opensuse-opendkim-image"/>
<binarylist package="test"/>
<binarylist package="visual-studio-rpi-pico-sshd-image"/>
</result>
<result project="home:adamm" repository="openSUSE_Tumbleweed" arch="aarch64" code="published" state="published">
<status package="Nudoku" code="excluded"/>
<status package="geekofall" code="unresolvable">
<details>nothing provides libBox2D-devel</details>
</status>
<status package="geekofall.1" code="unresolvable">
<details>nothing provides libBox2D-devel</details>
</status>
<status package="http-parser" code="failed"/>
<status package="minicoredumper" code="failed"/>
<status package="opensuse-dovecot-image" code="broken">
<details>conflict in file _service</details>
</status>
<status package="opensuse-nsd-image" code="disabled"/>
<status package="opensuse-opendkim-image" code="excluded"/>
<status package="test" code="broken">
<details>no source uploaded</details>
</status>
<status package="visual-studio-rpi-pico-sshd-image" code="excluded"/>
<binarylist package="Nudoku"/>
<binarylist package="geekofall"/>
<binarylist package="geekofall.1"/>
<binarylist package="http-parser"/>
<binarylist package="minicoredumper"/>
<binarylist package="opensuse-dovecot-image"/>
<binarylist package="opensuse-nsd-image"/>
<binarylist package="opensuse-opendkim-image"/>
<binarylist package="test"/>
<binarylist package="visual-studio-rpi-pico-sshd-image"/>
</result>
<result project="home:adamm" repository="containerfile" arch="aarch64" code="published" state="published">
<status package="Nudoku" code="excluded"/>
<status package="geekofall" code="excluded"/>
<status package="geekofall.1" code="excluded"/>
<status package="http-parser" code="excluded"/>
<status package="minicoredumper" code="excluded"/>
<status package="opensuse-dovecot-image" code="broken">
<details>conflict in file _service</details>
</status>
<status package="opensuse-nsd-image" code="disabled"/>
<status package="opensuse-opendkim-image" code="excluded"/>
<status package="test" code="broken">
<details>no source uploaded</details>
</status>
<status package="visual-studio-rpi-pico-sshd-image" code="succeeded"/>
<binarylist package="Nudoku"/>
<binarylist package="geekofall"/>
<binarylist package="geekofall.1"/>
<binarylist package="http-parser"/>
<binarylist package="minicoredumper"/>
<binarylist package="opensuse-dovecot-image"/>
<binarylist package="opensuse-nsd-image"/>
<binarylist package="opensuse-opendkim-image"/>
<binarylist package="test"/>
<binarylist package="visual-studio-rpi-pico-sshd-image">
<binary filename="_blob.sha256:9ea20f002e582c3fc8d14062450a6c4a4165317961d2af9b9e7b0d4e080f1c3c" size="38617846" mtime="1719856307"/>
<binary filename="_blob.sha256:9f9058a297fba8e8d5234de28cee922e039e4f622722514d7012f36d5a4eabd9" size="312194914" mtime="1721404809"/>
<binary filename="_blob.sha256:ac4e7722af8bc4c504a796b53ff48c5071b52de2da633845cd0c74cfd32dec9f" size="6845" mtime="1721404809"/>
<binary filename="_buildenv" size="144706" mtime="1721404745"/>
<binary filename="_statistics" size="1012" mtime="1721404745"/>
<binary filename="rpi-pico-vscode.aarch64-6.182.basepackages" size="19094" mtime="1721404745"/>
<binary filename="rpi-pico-vscode.aarch64-6.182.cdx.json" size="102955" mtime="1721404745"/>
<binary filename="rpi-pico-vscode.aarch64-6.182.containerinfo" size="1364" mtime="1721404809"/>
<binary filename="rpi-pico-vscode.aarch64-6.182.obsbinlnk" size="701" mtime="1721404809"/>
<binary filename="rpi-pico-vscode.aarch64-6.182.packages" size="30189" mtime="1721404745"/>
<binary filename="rpi-pico-vscode.aarch64-6.182.report" size="66947" mtime="1721404745"/>
<binary filename="rpi-pico-vscode.aarch64-6.182.spdx.json" size="13509128" mtime="1721404745"/>
<binary filename="rpi-pico-vscode.aarch64-6.182.tar" size="350823936" mtime="1721404745"/>
</binarylist>
</result>
<result project="home:adamm" repository="container" arch="aarch64" code="published" state="published">
<status package="Nudoku" code="excluded"/>
<status package="geekofall" code="excluded"/>
<status package="geekofall.1" code="excluded"/>
<status package="http-parser" code="excluded"/>
<status package="minicoredumper" code="excluded"/>
<status package="opensuse-dovecot-image" code="broken">
<details>conflict in file _service</details>
</status>
<status package="opensuse-nsd-image" code="failed"/>
<status package="opensuse-opendkim-image" code="unresolvable">
<details>have choice for /usr/bin/openssl needed by opendkim: libressl openssl-1_0_0 openssl-3</details>
</status>
<status package="test" code="broken">
<details>no source uploaded</details>
</status>
<status package="visual-studio-rpi-pico-sshd-image" code="excluded"/>
<binarylist package="Nudoku"/>
<binarylist package="geekofall"/>
<binarylist package="geekofall.1"/>
<binarylist package="http-parser"/>
<binarylist package="minicoredumper"/>
<binarylist package="opensuse-dovecot-image">
<binary filename="_blob.sha256:6b4fea0b9f77d0a5b66de148fb28109c5012e0831d30ff14fefa953fd06b3bfb" size="4545634" mtime="1715975625"/>
<binary filename="_blob.sha256:b1e156fe04a0d30d27c7989c6403346f343212f39cc3ffdb0ab31207b3a11734" size="2579" mtime="1716584488"/>
<binary filename="_blob.sha256:c6588a65781845c90cda432251b7b098a64b94e98261a39306451c8318c9e130" size="31074584" mtime="1716584488"/>
<binary filename="_buildenv" size="144566" mtime="1716584481"/>
<binary filename="_statistics" size="1011" mtime="1716584481"/>
<binary filename="opensuse-dovecot-image.aarch64-1.0.0-Build15.21.basepackages" size="9920" mtime="1716584481"/>
<binary filename="opensuse-dovecot-image.aarch64-1.0.0-Build15.21.docker.cdx.json" size="48775" mtime="1716584481"/>
<binary filename="opensuse-dovecot-image.aarch64-1.0.0-Build15.21.docker.containerinfo" size="1485" mtime="1716584488"/>
<binary filename="opensuse-dovecot-image.aarch64-1.0.0-Build15.21.docker.obsbinlnk" size="745" mtime="1716584488"/>
<binary filename="opensuse-dovecot-image.aarch64-1.0.0-Build15.21.docker.spdx.json" size="2008180" mtime="1716584481"/>
<binary filename="opensuse-dovecot-image.aarch64-1.0.0-Build15.21.docker.tar" size="35627520" mtime="1716584481"/>
<binary filename="opensuse-dovecot-image.aarch64-1.0.0-Build15.21.docker.tar.sha256" size="125" mtime="1716584481"/>
<binary filename="opensuse-dovecot-image.aarch64-1.0.0-Build15.21.docker.tar.sha256.asc" size="481" mtime="1716584489"/>
<binary filename="opensuse-dovecot-image.aarch64-1.0.0-Build15.21.packages" size="15559" mtime="1716584481"/>
<binary filename="opensuse-dovecot-image.aarch64-1.0.0-Build15.21.report" size="33131" mtime="1716584481"/>
<binary filename="opensuse-dovecot-image.aarch64-1.0.0-Build15.21.verified" size="156" mtime="1716584481"/>
</binarylist>
<binarylist package="opensuse-nsd-image">
<binary filename="_blob.sha256:109084b53bf1ad4a0d98db0cb442ecb197d73fe946351001a6b4b756369ce074" size="4545407" mtime="1712925763"/>
<binary filename="_blob.sha256:8fdaf68f1e41f06656875fc0f29fc248e7011cef766fbdda2a2061a6b0722b9c" size="2531" mtime="1713297940"/>
<binary filename="_blob.sha256:db672aec4faacd3c9cefb56bde6795ed638c5239cc1aa3160f87e0965b0f03cd" size="9675022" mtime="1713297940"/>
<binary filename="_buildenv" size="142894" mtime="1713297937"/>
<binary filename="_statistics" size="1009" mtime="1713297937"/>
<binary filename="opensuse-nsd-image.aarch64-1.0.0-Build7.86.basepackages" size="9920" mtime="1713297937"/>
<binary filename="opensuse-nsd-image.aarch64-1.0.0-Build7.86.docker.cdx.json" size="41631" mtime="1713297937"/>
<binary filename="opensuse-nsd-image.aarch64-1.0.0-Build7.86.docker.containerinfo" size="1453" mtime="1713297940"/>
<binary filename="opensuse-nsd-image.aarch64-1.0.0-Build7.86.docker.obsbinlnk" size="710" mtime="1713297940"/>
<binary filename="opensuse-nsd-image.aarch64-1.0.0-Build7.86.docker.spdx.json" size="549331" mtime="1713297937"/>
<binary filename="opensuse-nsd-image.aarch64-1.0.0-Build7.86.docker.tar" size="14226944" mtime="1713297937"/>
<binary filename="opensuse-nsd-image.aarch64-1.0.0-Build7.86.docker.tar.sha256" size="120" mtime="1713297937"/>
<binary filename="opensuse-nsd-image.aarch64-1.0.0-Build7.86.docker.tar.sha256.asc" size="481" mtime="1713297940"/>
<binary filename="opensuse-nsd-image.aarch64-1.0.0-Build7.86.packages" size="13321" mtime="1713297937"/>
<binary filename="opensuse-nsd-image.aarch64-1.0.0-Build7.86.report" size="28055" mtime="1713297937"/>
<binary filename="opensuse-nsd-image.aarch64-1.0.0-Build7.86.verified" size="156" mtime="1713297937"/>
</binarylist>
<binarylist package="opensuse-opendkim-image"/>
<binarylist package="test"/>
<binarylist package="visual-studio-rpi-pico-sshd-image"/>
</result>
</resultlist>
`

View File

@ -8,7 +8,6 @@ import (
"src.opensuse.org/autogits/common" "src.opensuse.org/autogits/common"
"src.opensuse.org/autogits/common/gitea-generated/models" "src.opensuse.org/autogits/common/gitea-generated/models"
"src.opensuse.org/autogits/common/obs"
) )
const ( const (
@ -65,10 +64,6 @@ func processPullNotification(h *common.RequestHandler, notification *models.Noti
switch review.State { switch review.State {
case common.ReviewStateUnknown, common.ReviewStateRequestReview: case common.ReviewStateUnknown, common.ReviewStateRequestReview:
// start review -- create project in OBS
obsClient, _ := obs.NewClient("api.opensuse.org", obs.WithBaseURL("api.opensuse.org"))
// obsClient.GetSourceProjectNameMeta
case common.ReviewStatePending: case common.ReviewStatePending:
// waiting for build results // waiting for build results
case common.ReviewStateApproved: case common.ReviewStateApproved:
@ -114,6 +109,14 @@ func main() {
pollWorkNotifications() pollWorkNotifications()
c, _ := common.NewObsClient("api.opensuse.org", "autogits_obs_staging_bot", "?E3N9']$YaC9~uR1")
status, err := c.BuildStatus("home:adamm")
if err != nil {
log.Printf("err: %v\n", err)
} else {
log.Print(*status)
}
stuck := make(chan int) stuck := make(chan int)
<-stuck <-stuck
} }