Compare commits
5 Commits
wip_manual
...
status_ser
Author | SHA256 | Date | |
---|---|---|---|
e8b6066bae | |||
42e2713cd8 | |||
3d24dce5c0 | |||
69dac4ec31 | |||
b7e03ab465 |
@@ -59,6 +59,7 @@ type AutogitConfig struct {
|
|||||||
Reviewers []string // only used by `pr` workflow
|
Reviewers []string // only used by `pr` workflow
|
||||||
ReviewGroups []ReviewGroup
|
ReviewGroups []ReviewGroup
|
||||||
Committers []string // group in addition to Reviewers and Maintainers that can order the bot around, mostly as helper for factory-maintainers
|
Committers []string // group in addition to Reviewers and Maintainers that can order the bot around, mostly as helper for factory-maintainers
|
||||||
|
Subdirs []string // list of directories to sort submodules into. Needed b/c _manifest cannot list non-existent directories
|
||||||
|
|
||||||
ManualMergeOnly bool // only merge with "Merge OK" comment by Project Maintainers and/or Package Maintainers and/or reviewers
|
ManualMergeOnly bool // only merge with "Merge OK" comment by Project Maintainers and/or Package Maintainers and/or reviewers
|
||||||
ManualMergeProject bool // require merge of ProjectGit PRs with "Merge OK" by ProjectMaintainers and/or reviewers
|
ManualMergeProject bool // require merge of ProjectGit PRs with "Merge OK" by ProjectMaintainers and/or reviewers
|
||||||
|
@@ -19,13 +19,11 @@ func (m *Manifest) SubdirForPackage(pkg string) string {
|
|||||||
|
|
||||||
idx := -1
|
idx := -1
|
||||||
matchLen := 0
|
matchLen := 0
|
||||||
lowercasePkg := strings.ToLower(pkg)
|
basePkg := path.Base(pkg)
|
||||||
|
lowercasePkg := strings.ToLower(basePkg)
|
||||||
|
|
||||||
for i, sub := range m.Subdirectories {
|
for i, sub := range m.Subdirectories {
|
||||||
basename := strings.ToLower(strings.TrimSuffix(sub, "/"))
|
basename := strings.ToLower(path.Base(sub))
|
||||||
if idx := strings.LastIndex(basename, "/"); idx > 0 {
|
|
||||||
basename = basename[idx+1:]
|
|
||||||
}
|
|
||||||
if strings.HasPrefix(lowercasePkg, basename) && matchLen < len(basename) {
|
if strings.HasPrefix(lowercasePkg, basename) && matchLen < len(basename) {
|
||||||
idx = i
|
idx = i
|
||||||
matchLen = len(basename)
|
matchLen = len(basename)
|
||||||
@@ -33,7 +31,7 @@ func (m *Manifest) SubdirForPackage(pkg string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if idx > -1 {
|
if idx > -1 {
|
||||||
return path.Join(m.Subdirectories[idx], pkg)
|
return path.Join(m.Subdirectories[idx], basePkg)
|
||||||
}
|
}
|
||||||
return pkg
|
return pkg
|
||||||
}
|
}
|
||||||
|
@@ -33,8 +33,8 @@ func TestManifestSubdirAssignments(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Name: "multilayer subdirs manifest with trailing /",
|
Name: "multilayer subdirs manifest with trailing /",
|
||||||
ManifestContent: "subdirectories:\n - a\n - b\n - libs/boo/\n - somedir/Node/",
|
ManifestContent: "subdirectories:\n - a\n - b\n - libs/boo/\n - somedir/Node/",
|
||||||
Packages: []string{"atom", "blarg", "Foobar", "X-Ray", "Boost", "NodeJS"},
|
Packages: []string{"atom", "blarg", "Foobar", "X-Ray", "Boost", "NodeJS", "foobar/node2"},
|
||||||
ManifestLocations: []string{"a/atom", "b/blarg", "Foobar", "X-Ray", "libs/boo/Boost", "somedir/Node/NodeJS"},
|
ManifestLocations: []string{"a/atom", "b/blarg", "Foobar", "X-Ray", "libs/boo/Boost", "somedir/Node/NodeJS", "somedir/Node/node2"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -562,25 +562,44 @@ func (c *ObsClient) DeleteProject(project string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ObsClient) BuildLog(prj, pkg, repo, arch string) (io.ReadCloser, error) {
|
||||||
|
url := c.baseUrl.JoinPath("build", prj, repo, arch, pkg, "_log")
|
||||||
|
query := url.Query()
|
||||||
|
query.Add("nostream", "1")
|
||||||
|
query.Add("start", "0")
|
||||||
|
url.RawQuery = query.Encode()
|
||||||
|
res, err := c.ObsRequestRaw("GET", url.String(), nil)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.Body, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type PackageBuildStatus struct {
|
type PackageBuildStatus struct {
|
||||||
Package string `xml:"package,attr"`
|
Package string `xml:"package,attr"`
|
||||||
Code string `xml:"code,attr"`
|
Code string `xml:"code,attr"`
|
||||||
Details string `xml:"details"`
|
Details string `xml:"details"`
|
||||||
|
|
||||||
|
LastUpdate int64
|
||||||
}
|
}
|
||||||
|
|
||||||
type BuildResult struct {
|
type BuildResult struct {
|
||||||
Project string `xml:"project,attr"`
|
Project string `xml:"project,attr"`
|
||||||
Repository string `xml:"repository,attr"`
|
Repository string `xml:"repository,attr"`
|
||||||
Arch string `xml:"arch,attr"`
|
Arch string `xml:"arch,attr"`
|
||||||
|
|
||||||
Code string `xml:"code,attr"`
|
Code string `xml:"code,attr"`
|
||||||
Dirty bool `xml:"dirty,attr"`
|
Dirty bool `xml:"dirty,attr"`
|
||||||
ScmSync string `xml:"scmsync"`
|
ScmSync string `xml:"scmsync"`
|
||||||
ScmInfo string `xml:"scminfo"`
|
ScmInfo string `xml:"scminfo"`
|
||||||
Status []PackageBuildStatus `xml:"status"`
|
Status []PackageBuildStatus `xml:"status"`
|
||||||
Binaries []BinaryList `xml:"binarylist"`
|
Binaries []BinaryList `xml:"binarylist"`
|
||||||
|
|
||||||
|
LastUpdate int64
|
||||||
}
|
}
|
||||||
|
|
||||||
type Binary struct {
|
type Binary struct {
|
||||||
@@ -600,6 +619,7 @@ type BuildResultList struct {
|
|||||||
Result []BuildResult `xml:"result"`
|
Result []BuildResult `xml:"result"`
|
||||||
|
|
||||||
isLastBuild bool
|
isLastBuild bool
|
||||||
|
LastUpdate int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *BuildResultList) GetPackageList() []string {
|
func (r *BuildResultList) GetPackageList() []string {
|
||||||
@@ -622,6 +642,48 @@ func (r *BuildResultList) GetPackageList() []string {
|
|||||||
return pkgList
|
return pkgList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func packageSort(A, B PackageBuildStatus) int {
|
||||||
|
return strings.Compare(A.Package, B.Package)
|
||||||
|
}
|
||||||
|
|
||||||
|
func repoSort(A, B BuildResult) int {
|
||||||
|
eq := strings.Compare(A.Project, B.Project)
|
||||||
|
if eq == 0 {
|
||||||
|
eq = strings.Compare(A.Repository, B.Repository)
|
||||||
|
if eq == 0 {
|
||||||
|
eq = strings.Compare(A.Arch, B.Arch)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return eq
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *BuildResultList) MergePackageState(now int64, pkgState *BuildResultList) {
|
||||||
|
for _, nr := range pkgState.Result {
|
||||||
|
idx, found := slices.BinarySearchFunc(r.Result, nr, repoSort)
|
||||||
|
// not found, new repo?
|
||||||
|
if !found {
|
||||||
|
nr.LastUpdate = now
|
||||||
|
r.Result = slices.Insert(r.Result, idx, nr)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// update current repo
|
||||||
|
repo := &r.Result[idx]
|
||||||
|
|
||||||
|
// update all the packages in the repo
|
||||||
|
for _, p := range nr.Status {
|
||||||
|
p.LastUpdate = now
|
||||||
|
idx, found := slices.BinarySearchFunc(repo.Status, p, packageSort)
|
||||||
|
if !found {
|
||||||
|
repo.Status = slices.Insert(repo.Status, idx, p)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
repo.Status[idx] = p
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (r *BuildResultList) BuildResultSummary() (success, finished bool) {
|
func (r *BuildResultList) BuildResultSummary() (success, finished bool) {
|
||||||
if r == nil {
|
if r == nil {
|
||||||
return false, false
|
return false, false
|
||||||
@@ -889,5 +951,11 @@ func (c *ObsClient) BuildStatusWithState(project string, opts *BuildResultOption
|
|||||||
if ret != nil {
|
if ret != nil {
|
||||||
ret.isLastBuild = opts.LastBuild
|
ret.isLastBuild = opts.LastBuild
|
||||||
}
|
}
|
||||||
|
|
||||||
|
slices.SortFunc(ret.Result, repoSort)
|
||||||
|
for _, r := range ret.Result {
|
||||||
|
slices.SortFunc(r.Status, packageSort)
|
||||||
|
}
|
||||||
|
|
||||||
return ret, err
|
return ret, err
|
||||||
}
|
}
|
||||||
|
@@ -22,55 +22,32 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"runtime/debug"
|
|
||||||
"slices"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
rabbitmq "github.com/rabbitmq/amqp091-go"
|
rabbitmq "github.com/rabbitmq/amqp091-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
const RequestType_CreateBrachTag = "create"
|
type RabbitConnection struct {
|
||||||
const RequestType_DeleteBranchTag = "delete"
|
|
||||||
const RequestType_Fork = "fork"
|
|
||||||
const RequestType_Issue = "issues"
|
|
||||||
const RequestType_IssueAssign = "issue_assign"
|
|
||||||
const RequestType_IssueComment = "issue_comment"
|
|
||||||
const RequestType_IssueLabel = "issue_label"
|
|
||||||
const RequestType_IssueMilestone = "issue_milestone"
|
|
||||||
const RequestType_Push = "push"
|
|
||||||
const RequestType_Repository = "repository"
|
|
||||||
const RequestType_Release = "release"
|
|
||||||
const RequestType_PR = "pull_request"
|
|
||||||
const RequestType_PRAssign = "pull_request_assign"
|
|
||||||
const RequestType_PRLabel = "pull_request_label"
|
|
||||||
const RequestType_PRComment = "pull_request_comment"
|
|
||||||
const RequestType_PRMilestone = "pull_request_milestone"
|
|
||||||
const RequestType_PRSync = "pull_request_sync"
|
|
||||||
const RequestType_PRReviewAccepted = "pull_request_review_approved"
|
|
||||||
const RequestType_PRReviewRejected = "pull_request_review_rejected"
|
|
||||||
const RequestType_PRReviewRequest = "pull_request_review_request"
|
|
||||||
const RequestType_PRReviewComment = "pull_request_review_comment"
|
|
||||||
const RequestType_Wiki = "wiki"
|
|
||||||
|
|
||||||
type RequestProcessor interface {
|
|
||||||
ProcessFunc(*Request) error
|
|
||||||
}
|
|
||||||
|
|
||||||
type ListenDefinitions struct {
|
|
||||||
RabbitURL *url.URL // amqps://user:password@host/queue
|
RabbitURL *url.URL // amqps://user:password@host/queue
|
||||||
|
|
||||||
GitAuthor string
|
queueName string
|
||||||
Handlers map[string]RequestProcessor
|
ch *rabbitmq.Channel
|
||||||
Orgs []string
|
|
||||||
|
|
||||||
topics []string
|
topics []string
|
||||||
topicSubChanges chan string // +topic = subscribe, -topic = unsubscribe
|
topicSubChanges chan string // +topic = subscribe, -topic = unsubscribe
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RabbitProcessor interface {
|
||||||
|
GenerateTopics() []string
|
||||||
|
|
||||||
|
Connection() *RabbitConnection
|
||||||
|
ProcessRabbitMessage(msg RabbitMessage) error
|
||||||
|
}
|
||||||
|
|
||||||
type RabbitMessage rabbitmq.Delivery
|
type RabbitMessage rabbitmq.Delivery
|
||||||
|
|
||||||
func (l *ListenDefinitions) processTopicChanges(ch *rabbitmq.Channel, queueName string) {
|
func (l *RabbitConnection) ProcessTopicChanges() {
|
||||||
for {
|
for {
|
||||||
topic, ok := <-l.topicSubChanges
|
topic, ok := <-l.topicSubChanges
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -80,11 +57,11 @@ func (l *ListenDefinitions) processTopicChanges(ch *rabbitmq.Channel, queueName
|
|||||||
LogDebug(" topic change:", topic)
|
LogDebug(" topic change:", topic)
|
||||||
switch topic[0] {
|
switch topic[0] {
|
||||||
case '+':
|
case '+':
|
||||||
if err := ch.QueueBind(queueName, topic[1:], "pubsub", false, nil); err != nil {
|
if err := l.ch.QueueBind(l.queueName, topic[1:], "pubsub", false, nil); err != nil {
|
||||||
LogError(err)
|
LogError(err)
|
||||||
}
|
}
|
||||||
case '-':
|
case '-':
|
||||||
if err := ch.QueueUnbind(queueName, topic[1:], "pubsub", nil); err != nil {
|
if err := l.ch.QueueUnbind(l.queueName, topic[1:], "pubsub", nil); err != nil {
|
||||||
LogError(err)
|
LogError(err)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -93,7 +70,7 @@ func (l *ListenDefinitions) processTopicChanges(ch *rabbitmq.Channel, queueName
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ListenDefinitions) processRabbitMQ(msgCh chan<- RabbitMessage) error {
|
func (l *RabbitConnection) ProcessRabbitMQ(msgCh chan<- RabbitMessage) error {
|
||||||
queueName := l.RabbitURL.Path
|
queueName := l.RabbitURL.Path
|
||||||
l.RabbitURL.Path = ""
|
l.RabbitURL.Path = ""
|
||||||
|
|
||||||
@@ -152,7 +129,7 @@ func (l *ListenDefinitions) processRabbitMQ(msgCh chan<- RabbitMessage) error {
|
|||||||
LogDebug(" -- listening to topics:")
|
LogDebug(" -- listening to topics:")
|
||||||
l.topicSubChanges = make(chan string)
|
l.topicSubChanges = make(chan string)
|
||||||
defer close(l.topicSubChanges)
|
defer close(l.topicSubChanges)
|
||||||
go l.processTopicChanges(ch, q.Name)
|
go l.ProcessTopicChanges()
|
||||||
|
|
||||||
for _, topic := range l.topics {
|
for _, topic := range l.topics {
|
||||||
l.topicSubChanges <- "+" + topic
|
l.topicSubChanges <- "+" + topic
|
||||||
@@ -174,18 +151,18 @@ func (l *ListenDefinitions) processRabbitMQ(msgCh chan<- RabbitMessage) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ListenDefinitions) connectAndProcessRabbitMQ(ch chan<- RabbitMessage) {
|
func (l *RabbitConnection) ConnectAndProcessRabbitMQ(ch chan<- RabbitMessage) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
LogError(r)
|
LogError(r)
|
||||||
LogError("'crash' RabbitMQ worker. Recovering... reconnecting...")
|
LogError("'crash' RabbitMQ worker. Recovering... reconnecting...")
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
go l.connectAndProcessRabbitMQ(ch)
|
go l.ConnectAndProcessRabbitMQ(ch)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
err := l.processRabbitMQ(ch)
|
err := l.ProcessRabbitMQ(ch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LogError("Error in RabbitMQ connection. %#v", err)
|
LogError("Error in RabbitMQ connection. %#v", err)
|
||||||
LogInfo("Reconnecting in 2 seconds...")
|
LogInfo("Reconnecting in 2 seconds...")
|
||||||
@@ -194,49 +171,20 @@ func (l *ListenDefinitions) connectAndProcessRabbitMQ(ch chan<- RabbitMessage) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ListenDefinitions) connectToRabbitMQ() chan RabbitMessage {
|
func (l *RabbitConnection) ConnectToRabbitMQ(processor RabbitProcessor) <-chan RabbitMessage {
|
||||||
|
LogInfo("RabbitMQ connection:", l.RabbitURL.String())
|
||||||
|
|
||||||
|
l.RabbitURL.User = url.UserPassword(rabbitUser, rabbitPassword)
|
||||||
|
l.topics = processor.GenerateTopics()
|
||||||
|
|
||||||
ch := make(chan RabbitMessage, 100)
|
ch := make(chan RabbitMessage, 100)
|
||||||
go l.connectAndProcessRabbitMQ(ch)
|
go l.ConnectAndProcessRabbitMQ(ch)
|
||||||
|
|
||||||
return ch
|
return ch
|
||||||
}
|
}
|
||||||
|
|
||||||
func ProcessEvent(f RequestProcessor, request *Request) {
|
func (l *RabbitConnection) UpdateTopics(processor RabbitProcessor) {
|
||||||
defer func() {
|
newTopics := processor.GenerateTopics()
|
||||||
if r := recover(); r != nil {
|
|
||||||
LogError("panic caught")
|
|
||||||
if err, ok := r.(error); !ok {
|
|
||||||
LogError(err)
|
|
||||||
}
|
|
||||||
LogError(string(debug.Stack()))
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
if err := f.ProcessFunc(request); err != nil {
|
|
||||||
LogError(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *ListenDefinitions) generateTopics() []string {
|
|
||||||
topics := make([]string, 0, len(l.Handlers)*len(l.Orgs))
|
|
||||||
scope := "suse"
|
|
||||||
if l.RabbitURL.Hostname() == "rabbit.opensuse.org" {
|
|
||||||
scope = "opensuse"
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, org := range l.Orgs {
|
|
||||||
for requestType, _ := range l.Handlers {
|
|
||||||
topics = append(topics, fmt.Sprintf("%s.src.%s.%s.#", scope, org, requestType))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
slices.Sort(topics)
|
|
||||||
return slices.Compact(topics)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *ListenDefinitions) UpdateTopics() {
|
|
||||||
newTopics := l.generateTopics()
|
|
||||||
|
|
||||||
j := 0
|
j := 0
|
||||||
next_new_topic:
|
next_new_topic:
|
||||||
@@ -273,14 +221,8 @@ next_new_topic:
|
|||||||
l.topics = newTopics
|
l.topics = newTopics
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ListenDefinitions) ProcessRabbitMQEvents() error {
|
func ProcessRabbitMQEvents(processor RabbitProcessor) error {
|
||||||
LogInfo("RabbitMQ connection:", l.RabbitURL.String())
|
ch := processor.Connection().ConnectToRabbitMQ(processor)
|
||||||
LogDebug("# Handlers:", len(l.Handlers))
|
|
||||||
LogDebug("# Orgs:", len(l.Orgs))
|
|
||||||
|
|
||||||
l.RabbitURL.User = url.UserPassword(rabbitUser, rabbitPassword)
|
|
||||||
l.topics = l.generateTopics()
|
|
||||||
ch := l.connectToRabbitMQ()
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
msg, ok := <-ch
|
msg, ok := <-ch
|
||||||
@@ -289,36 +231,8 @@ func (l *ListenDefinitions) ProcessRabbitMQEvents() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LogDebug("event:", msg.RoutingKey)
|
LogDebug("event:", msg.RoutingKey)
|
||||||
|
if err := processor.ProcessRabbitMessage(msg); err != nil {
|
||||||
route := strings.Split(msg.RoutingKey, ".")
|
LogError("Error processing", msg.RoutingKey, err)
|
||||||
if len(route) > 3 {
|
|
||||||
reqType := route[3]
|
|
||||||
org := route[2]
|
|
||||||
|
|
||||||
if !slices.Contains(l.Orgs, org) {
|
|
||||||
LogInfo("Got event for unhandeled org:", org)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
LogDebug("org:", org, "type:", reqType)
|
|
||||||
if handler, found := l.Handlers[reqType]; found {
|
|
||||||
/* h, err := CreateRequestHandler()
|
|
||||||
if err != nil {
|
|
||||||
log.Println("Cannot create request handler", err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
req, err := ParseRequestJSON(reqType, msg.Body)
|
|
||||||
if err != nil {
|
|
||||||
LogError("Error parsing request JSON:", err)
|
|
||||||
continue
|
|
||||||
} else {
|
|
||||||
LogDebug("processing req", req.Type)
|
|
||||||
// h.Request = req
|
|
||||||
ProcessEvent(handler, req)
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
130
common/rabbitmq_gitea.go
Normal file
130
common/rabbitmq_gitea.go
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Autogits.
|
||||||
|
*
|
||||||
|
* Copyright © 2024 SUSE LLC
|
||||||
|
*
|
||||||
|
* Autogits is free software: you can redistribute it and/or modify it under
|
||||||
|
* the terms of the GNU General Public License as published by the Free Software
|
||||||
|
* Foundation, either version 2 of the License, or (at your option) any later
|
||||||
|
* version.
|
||||||
|
*
|
||||||
|
* Autogits is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* Foobar. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"runtime/debug"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
RequestType_CreateBrachTag = "create"
|
||||||
|
RequestType_DeleteBranchTag = "delete"
|
||||||
|
RequestType_Fork = "fork"
|
||||||
|
RequestType_Issue = "issues"
|
||||||
|
RequestType_IssueAssign = "issue_assign"
|
||||||
|
RequestType_IssueComment = "issue_comment"
|
||||||
|
RequestType_IssueLabel = "issue_label"
|
||||||
|
RequestType_IssueMilestone = "issue_milestone"
|
||||||
|
RequestType_Push = "push"
|
||||||
|
RequestType_Repository = "repository"
|
||||||
|
RequestType_Release = "release"
|
||||||
|
RequestType_PR = "pull_request"
|
||||||
|
RequestType_PRAssign = "pull_request_assign"
|
||||||
|
RequestType_PRLabel = "pull_request_label"
|
||||||
|
RequestType_PRComment = "pull_request_comment"
|
||||||
|
RequestType_PRMilestone = "pull_request_milestone"
|
||||||
|
RequestType_PRSync = "pull_request_sync"
|
||||||
|
RequestType_PRReviewAccepted = "pull_request_review_approved"
|
||||||
|
RequestType_PRReviewRejected = "pull_request_review_rejected"
|
||||||
|
RequestType_PRReviewRequest = "pull_request_review_request"
|
||||||
|
RequestType_PRReviewComment = "pull_request_review_comment"
|
||||||
|
RequestType_Wiki = "wiki"
|
||||||
|
)
|
||||||
|
|
||||||
|
type RequestProcessor interface {
|
||||||
|
ProcessFunc(*Request) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type RabbitMQGiteaEventsProcessor struct {
|
||||||
|
Handlers map[string]RequestProcessor
|
||||||
|
Orgs []string
|
||||||
|
|
||||||
|
c *RabbitConnection
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gitea *RabbitMQGiteaEventsProcessor) Connection() *RabbitConnection {
|
||||||
|
if gitea.c == nil {
|
||||||
|
gitea.c = &RabbitConnection{}
|
||||||
|
}
|
||||||
|
return gitea.c
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gitea *RabbitMQGiteaEventsProcessor) GenerateTopics() []string {
|
||||||
|
topics := make([]string, 0, len(gitea.Handlers)*len(gitea.Orgs))
|
||||||
|
scope := "suse"
|
||||||
|
if gitea.c.RabbitURL.Hostname() == "rabbit.opensuse.org" {
|
||||||
|
scope = "opensuse"
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, org := range gitea.Orgs {
|
||||||
|
for requestType, _ := range gitea.Handlers {
|
||||||
|
topics = append(topics, fmt.Sprintf("%s.src.%s.%s.#", scope, org, requestType))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
slices.Sort(topics)
|
||||||
|
return slices.Compact(topics)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gitea *RabbitMQGiteaEventsProcessor) ProcessRabbitMessage(msg RabbitMessage) error {
|
||||||
|
route := strings.Split(msg.RoutingKey, ".")
|
||||||
|
if len(route) > 3 {
|
||||||
|
reqType := route[3]
|
||||||
|
org := route[2]
|
||||||
|
|
||||||
|
if !slices.Contains(gitea.Orgs, org) {
|
||||||
|
LogInfo("Got event for unhandeled org:", org)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
LogDebug("org:", org, "type:", reqType)
|
||||||
|
if handler, found := gitea.Handlers[reqType]; found {
|
||||||
|
req, err := ParseRequestJSON(reqType, msg.Body)
|
||||||
|
if err != nil {
|
||||||
|
LogError("Error parsing request JSON:", err)
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
LogDebug("processing req", req.Type)
|
||||||
|
// h.Request = req
|
||||||
|
ProcessEvent(handler, req)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("Invalid routing key: %s", route)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ProcessEvent(f RequestProcessor, request *Request) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
LogError("panic caught")
|
||||||
|
if err, ok := r.(error); !ok {
|
||||||
|
LogError(err)
|
||||||
|
}
|
||||||
|
LogError(string(debug.Stack()))
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
if err := f.ProcessFunc(request); err != nil {
|
||||||
|
LogError(err)
|
||||||
|
}
|
||||||
|
}
|
115
common/rabbitmq_obs.go
Normal file
115
common/rabbitmq_obs.go
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ObsMessageType_PackageBuildFail = "package.build_fail"
|
||||||
|
ObsMessageType_PackageBuildSuccess = "package.build_success"
|
||||||
|
ObsMessageType_PackageBuildUnchanged = "package.build_unchanged"
|
||||||
|
|
||||||
|
ObsMessageType_RepoBuildFinished = "repo.build_finished"
|
||||||
|
ObsMessageType_RepoBuildStarted = "repo.build_started"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BuildResultMsg struct {
|
||||||
|
Status string
|
||||||
|
Project string `json:"project"`
|
||||||
|
Package string `json:"package"`
|
||||||
|
Repo string `json:"repository"`
|
||||||
|
Arch string `json:"arch"`
|
||||||
|
|
||||||
|
StartTime int32 `json:"starttime"`
|
||||||
|
EndTime int32 `json:"endtime"`
|
||||||
|
WorkerID string `json:"workerid"`
|
||||||
|
Version string `json:"versrel"`
|
||||||
|
Build string `json:"buildtype"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RepoBuildMsg struct {
|
||||||
|
Status string
|
||||||
|
Project string `json:"project"`
|
||||||
|
Repo string `json:"repo"`
|
||||||
|
Arch string `json:"arch"`
|
||||||
|
BuildId string `json:"buildid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var ObsRabbitMessageError_UnknownMessageType error = errors.New("Unknown message type")
|
||||||
|
var ObsRabbitMessageError_ParseError error = errors.New("JSON parsing error")
|
||||||
|
|
||||||
|
func ParseObsRabbitMessaege(ObsMessageType string, data []byte) (interface{}, error) {
|
||||||
|
unmarshall := func(data []byte, v any) (interface{}, error) {
|
||||||
|
if err := json.Unmarshal(data, v); err != nil {
|
||||||
|
return nil, fmt.Errorf("%w: %s", ObsRabbitMessageError_ParseError, err)
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ObsMessageType {
|
||||||
|
case ObsMessageType_PackageBuildSuccess, ObsMessageType_PackageBuildUnchanged:
|
||||||
|
ret := &BuildResultMsg{Status: "succeeded"}
|
||||||
|
return unmarshall(data, ret)
|
||||||
|
case ObsMessageType_PackageBuildFail:
|
||||||
|
ret := &BuildResultMsg{Status: "failed"}
|
||||||
|
return unmarshall(data, ret)
|
||||||
|
case ObsMessageType_RepoBuildFinished:
|
||||||
|
ret := &RepoBuildMsg{Status: "finished"}
|
||||||
|
return unmarshall(data, ret)
|
||||||
|
case ObsMessageType_RepoBuildStarted:
|
||||||
|
ret := &RepoBuildMsg{Status: "building"}
|
||||||
|
return unmarshall(data, ret)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, fmt.Errorf("%w: %s", ObsRabbitMessageError_UnknownMessageType, ObsMessageType)
|
||||||
|
}
|
||||||
|
|
||||||
|
type ObsMessageProcessor func(topic string, data []byte) error
|
||||||
|
|
||||||
|
type RabbitMQObsBuildStatusProcessor struct {
|
||||||
|
Handlers map[string]ObsMessageProcessor
|
||||||
|
|
||||||
|
c *RabbitConnection
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *RabbitMQObsBuildStatusProcessor) routingKeyPrefix() string {
|
||||||
|
if strings.HasSuffix(o.c.RabbitURL.Hostname(), "opensuse.org") {
|
||||||
|
return "opensuse"
|
||||||
|
}
|
||||||
|
|
||||||
|
return "suse"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *RabbitMQObsBuildStatusProcessor) GenerateTopics() []string {
|
||||||
|
prefix := o.routingKeyPrefix()
|
||||||
|
msgs := make([]string, len(o.Handlers))
|
||||||
|
idx := 0
|
||||||
|
for k, _ := range o.Handlers {
|
||||||
|
msgs[idx] = prefix + ".obs." + k
|
||||||
|
idx++
|
||||||
|
}
|
||||||
|
slices.Sort(msgs)
|
||||||
|
return msgs
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *RabbitMQObsBuildStatusProcessor) Connection() *RabbitConnection {
|
||||||
|
if o.c == nil {
|
||||||
|
o.c = &RabbitConnection{}
|
||||||
|
}
|
||||||
|
|
||||||
|
return o.c
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *RabbitMQObsBuildStatusProcessor) ProcessRabbitMessage(msg RabbitMessage) error {
|
||||||
|
prefix := o.routingKeyPrefix() + ".obs."
|
||||||
|
topic := strings.TrimPrefix(msg.RoutingKey, prefix)
|
||||||
|
if h, ok := o.Handlers[topic]; ok {
|
||||||
|
return h(topic, msg.Body)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("Unhandled message received: %s", msg.RoutingKey)
|
||||||
|
}
|
@@ -50,11 +50,13 @@ func TestListenDefinitionsTopicUpdate(t *testing.T) {
|
|||||||
u, _ := url.Parse("amqps://rabbit.example.com")
|
u, _ := url.Parse("amqps://rabbit.example.com")
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
l := ListenDefinitions{
|
l := &RabbitMQGiteaEventsProcessor{
|
||||||
Orgs: test.orgs1,
|
Orgs: test.orgs1,
|
||||||
Handlers: make(map[string]RequestProcessor),
|
Handlers: make(map[string]RequestProcessor),
|
||||||
topicSubChanges: make(chan string, len(test.topicDelta)*10),
|
c: &RabbitConnection{
|
||||||
RabbitURL: u,
|
RabbitURL: u,
|
||||||
|
topicSubChanges: make(chan string, len(test.topicDelta)*10),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
slices.Sort(test.topicDelta)
|
slices.Sort(test.topicDelta)
|
||||||
@@ -64,11 +66,11 @@ func TestListenDefinitionsTopicUpdate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
changes := []string{}
|
changes := []string{}
|
||||||
l.UpdateTopics()
|
l.c.UpdateTopics(l)
|
||||||
a:
|
a:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case c := <-l.topicSubChanges:
|
case c := <-l.c.topicSubChanges:
|
||||||
changes = append(changes, c)
|
changes = append(changes, c)
|
||||||
default:
|
default:
|
||||||
changes = []string{}
|
changes = []string{}
|
||||||
@@ -78,13 +80,13 @@ func TestListenDefinitionsTopicUpdate(t *testing.T) {
|
|||||||
|
|
||||||
l.Orgs = test.orgs2
|
l.Orgs = test.orgs2
|
||||||
|
|
||||||
l.UpdateTopics()
|
l.c.UpdateTopics(l)
|
||||||
changes = []string{}
|
changes = []string{}
|
||||||
|
|
||||||
b:
|
b:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case c := <-l.topicSubChanges:
|
case c := <-l.c.topicSubChanges:
|
||||||
changes = append(changes, c)
|
changes = append(changes, c)
|
||||||
default:
|
default:
|
||||||
slices.Sort(changes)
|
slices.Sort(changes)
|
@@ -113,6 +113,10 @@ func (s *Submodule) parseKeyValue(line string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Submodule) ManifestSubmodulePath(manifest *Manifest) string {
|
||||||
|
return manifest.SubdirForPackage(s.Path)
|
||||||
|
}
|
||||||
|
|
||||||
func ParseSubmodulesFile(reader io.Reader) ([]Submodule, error) {
|
func ParseSubmodulesFile(reader io.Reader) ([]Submodule, error) {
|
||||||
data, err := io.ReadAll(reader)
|
data, err := io.ReadAll(reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -173,4 +173,3 @@ func (d DevelProjects) GetDevelProject(pkg string) (string, error) {
|
|||||||
|
|
||||||
return "", DevelProjectNotFound
|
return "", DevelProjectNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,6 +22,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
@@ -78,7 +79,7 @@ func ProjectStatusSummarySvg(project string) []byte {
|
|||||||
return ret.Bytes()
|
return ret.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
func PackageStatusSummarySvg(status common.PackageBuildStatus) []byte {
|
func PackageStatusSummarySvg(status *common.PackageBuildStatus) []byte {
|
||||||
buildStatus, ok := common.ObsBuildStatusDetails[status.Code]
|
buildStatus, ok := common.ObsBuildStatusDetails[status.Code]
|
||||||
if !ok {
|
if !ok {
|
||||||
buildStatus = common.ObsBuildStatusDetails["error"]
|
buildStatus = common.ObsBuildStatusDetails["error"]
|
||||||
@@ -108,8 +109,10 @@ func main() {
|
|||||||
key := flag.String("key-file", "", "Private key for the TLS certificate")
|
key := flag.String("key-file", "", "Private key for the TLS certificate")
|
||||||
listen := flag.String("listen", "[::1]:8080", "Listening string")
|
listen := flag.String("listen", "[::1]:8080", "Listening string")
|
||||||
disableTls := flag.Bool("no-tls", false, "Disable TLS")
|
disableTls := flag.Bool("no-tls", false, "Disable TLS")
|
||||||
obsHost := flag.String("obs-host", "api.opensuse.org", "OBS API endpoint for package status information")
|
obsHost := flag.String("obs-host", "https://api.opensuse.org", "OBS API endpoint for package status information")
|
||||||
flag.BoolVar(&debug, "debug", false, "Enable debug logging")
|
flag.BoolVar(&debug, "debug", false, "Enable debug logging")
|
||||||
|
RabbitMQHost := flag.String("rabbit-mq", "amqps://rabbit.opensuse.org", "RabbitMQ message bus server")
|
||||||
|
Topic := flag.String("topic", "opensuse.obs", "RabbitMQ topic prefix")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
common.PanicOnError(common.RequireObsSecretToken())
|
common.PanicOnError(common.RequireObsSecretToken())
|
||||||
@@ -143,21 +146,25 @@ func main() {
|
|||||||
|
|
||||||
res.Header().Add("content-type", "image/svg+xml")
|
res.Header().Add("content-type", "image/svg+xml")
|
||||||
|
|
||||||
prjStatus := GetCurrentStatus(prj)
|
status := GetDetailedBuildStatus(prj, pkg, repo, arch)
|
||||||
if prjStatus == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, r := range prjStatus.Result {
|
|
||||||
if r.Arch == arch && r.Repository == repo {
|
|
||||||
for _, status := range r.Status {
|
|
||||||
if status.Package == pkg {
|
|
||||||
res.Write(PackageStatusSummarySvg(status))
|
res.Write(PackageStatusSummarySvg(status))
|
||||||
|
})
|
||||||
|
http.HandleFunc("GET /{Project}/{Package}/{Repository}/{Arch}/buildlog", func(res http.ResponseWriter, req *http.Request) {
|
||||||
|
prj := req.PathValue("Project")
|
||||||
|
pkg := req.PathValue("Package")
|
||||||
|
repo := req.PathValue("Repository")
|
||||||
|
arch := req.PathValue("Arch")
|
||||||
|
|
||||||
|
// status := GetDetailedBuildStatus(prj, pkg, repo, arch)
|
||||||
|
data, err := obs.BuildLog(prj, pkg, repo, arch)
|
||||||
|
if err != nil {
|
||||||
|
res.WriteHeader(http.StatusInternalServerError)
|
||||||
|
common.LogError("Failed to fetch build log for:", prj, pkg, repo, arch, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
defer data.Close()
|
||||||
}
|
|
||||||
}
|
io.Copy(res, data)
|
||||||
})
|
})
|
||||||
|
|
||||||
go ProcessUpdates()
|
go ProcessUpdates()
|
||||||
|
3
obs-status-service/rabbit.go
Normal file
3
obs-status-service/rabbit.go
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
|
@@ -1,8 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"slices"
|
"slices"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -24,14 +24,86 @@ type StatusUpdateMsg struct {
|
|||||||
|
|
||||||
func GetCurrentStatus(project string) *common.BuildResultList {
|
func GetCurrentStatus(project string) *common.BuildResultList {
|
||||||
statusMutex.RLock()
|
statusMutex.RLock()
|
||||||
defer statusMutex.RUnlock()
|
|
||||||
|
|
||||||
if ret, found := CurrentStatus[project]; found {
|
if ret, found := CurrentStatus[project]; found {
|
||||||
|
statusMutex.RUnlock()
|
||||||
return ret
|
return ret
|
||||||
} else {
|
}
|
||||||
go WatchObsProject(obs, project)
|
|
||||||
|
res, err := obs.BuildStatus(project)
|
||||||
|
statusMutex.RUnlock()
|
||||||
|
statusMutex.Lock()
|
||||||
|
defer statusMutex.Unlock()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
CurrentStatus[project] = res
|
||||||
|
|
||||||
|
now := time.Now().Unix()
|
||||||
|
CurrentStatus[project].LastUpdate = now
|
||||||
|
for _, r := range res.Result {
|
||||||
|
r.LastUpdate = now
|
||||||
|
for _, p := range r.Status {
|
||||||
|
p.LastUpdate = now
|
||||||
|
}
|
||||||
|
slices.SortFunc(r.Status, packageSort)
|
||||||
|
}
|
||||||
|
slices.SortFunc(res.Result, repoSort)
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func updatePrjPackage(prjState *common.BuildResultList, pkg string, now int64, pkgState *common.BuildResultList) {
|
||||||
|
for prjState.
|
||||||
|
Result[0].Status[0].Package
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractPackageBuildStatus(prjState *common.BuildResultList, pkg string) []*common.PackageBuildStatus {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetDetailedPackageBuildStatus(prj, pkg string) []*common.PackageBuildStatus {
|
||||||
|
statusMutex.RLock()
|
||||||
|
now := time.Now().Unix()
|
||||||
|
|
||||||
|
cachedPrj, found := CurrentStatus[prj]
|
||||||
|
if found {
|
||||||
|
statusMutex.Unlock()
|
||||||
|
if now-cachedPrj.LastUpdate < 60 {
|
||||||
|
return extractPackageBuildStatus(cachedPrj, pkg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret, err := obs.BuildStatus(prj, pkg)
|
||||||
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
statusMutex.Lock()
|
||||||
|
defer statusMutex.Unlock()
|
||||||
|
|
||||||
|
updatePrjPackage(cachedPrj, pkg, now, ret)
|
||||||
|
return extractPackageBuildStatus(cachedPrj, pkg)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetDetailedBuildStatus(prj, pkg, repo, arch string) *common.PackageBuildStatus {
|
||||||
|
prjStatus := GetCurrentStatus(prj)
|
||||||
|
if prjStatus == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, r := range prjStatus.Result {
|
||||||
|
if r.Arch == arch && r.Repository == repo {
|
||||||
|
for _, status := range r.Status {
|
||||||
|
if status.Package == pkg {
|
||||||
|
return &status
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ProcessUpdates() {
|
func ProcessUpdates() {
|
||||||
@@ -53,30 +125,3 @@ func ProcessUpdates() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WatchObsProject(obs common.ObsStatusFetcherWithState, ObsProject string) {
|
|
||||||
old_state := ""
|
|
||||||
|
|
||||||
mutex.Lock()
|
|
||||||
if pos, found := slices.BinarySearch(WatchedRepos, ObsProject); found {
|
|
||||||
mutex.Unlock()
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
WatchedRepos = slices.Insert(WatchedRepos, pos, ObsProject)
|
|
||||||
mutex.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
LogDebug("+ watching", ObsProject)
|
|
||||||
opts := common.BuildResultOptions{}
|
|
||||||
for {
|
|
||||||
state, err := obs.BuildStatusWithState(ObsProject, &opts)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(" *** Error fetching build for", ObsProject, err)
|
|
||||||
time.Sleep(time.Minute)
|
|
||||||
} else {
|
|
||||||
opts.OldState = state.State
|
|
||||||
LogDebug(" --> update", ObsProject, " => ", old_state)
|
|
||||||
StatusUpdateCh <- StatusUpdateMsg{ObsProject: ObsProject, Result: state}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -526,7 +526,7 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var defs common.ListenDefinitions
|
defs := &common.RabbitMQGiteaEventsProcessor{}
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if len(*basePath) == 0 {
|
if len(*basePath) == 0 {
|
||||||
@@ -557,7 +557,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
log.Println("*** Reconfiguring ***")
|
log.Println("*** Reconfiguring ***")
|
||||||
updateConfiguration(*configFilename, &defs.Orgs)
|
updateConfiguration(*configFilename, &defs.Orgs)
|
||||||
defs.UpdateTopics()
|
defs.Connection().UpdateTopics(defs)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
signal.Notify(signalChannel, syscall.SIGHUP)
|
signal.Notify(signalChannel, syscall.SIGHUP)
|
||||||
@@ -573,18 +573,17 @@ func main() {
|
|||||||
|
|
||||||
updateConfiguration(*configFilename, &defs.Orgs)
|
updateConfiguration(*configFilename, &defs.Orgs)
|
||||||
|
|
||||||
defs.GitAuthor = GitAuthor
|
defs.Connection().RabbitURL, err = url.Parse(*rabbitUrl)
|
||||||
defs.RabbitURL, err = url.Parse(*rabbitUrl)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicf("cannot parse server URL. Err: %#v\n", err)
|
log.Panicf("cannot parse server URL. Err: %#v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
go consistencyCheckProcess()
|
go consistencyCheckProcess()
|
||||||
log.Println("defs:", defs)
|
log.Println("defs:", *defs)
|
||||||
|
|
||||||
defs.Handlers = make(map[string]common.RequestProcessor)
|
defs.Handlers = make(map[string]common.RequestProcessor)
|
||||||
defs.Handlers[common.RequestType_Push] = &PushActionProcessor{}
|
defs.Handlers[common.RequestType_Push] = &PushActionProcessor{}
|
||||||
defs.Handlers[common.RequestType_Repository] = &RepositoryActionProcessor{}
|
defs.Handlers[common.RequestType_Repository] = &RepositoryActionProcessor{}
|
||||||
|
|
||||||
log.Fatal(defs.ProcessRabbitMQEvents())
|
log.Fatal(common.ProcessRabbitMQEvents(defs))
|
||||||
}
|
}
|
||||||
|
@@ -162,9 +162,9 @@ func main() {
|
|||||||
checker := CreateDefaultStateChecker(*checkOnStart, req, Gitea, time.Duration(*checkIntervalHours)*time.Hour)
|
checker := CreateDefaultStateChecker(*checkOnStart, req, Gitea, time.Duration(*checkIntervalHours)*time.Hour)
|
||||||
go checker.ConsistencyCheckProcess()
|
go checker.ConsistencyCheckProcess()
|
||||||
|
|
||||||
listenDefs := common.ListenDefinitions{
|
listenDefs := &common.RabbitMQGiteaEventsProcessor{
|
||||||
Orgs: orgs,
|
Orgs: orgs,
|
||||||
GitAuthor: GitAuthor,
|
// GitAuthor: GitAuthor,
|
||||||
Handlers: map[string]common.RequestProcessor{
|
Handlers: map[string]common.RequestProcessor{
|
||||||
common.RequestType_PR: req,
|
common.RequestType_PR: req,
|
||||||
common.RequestType_PRSync: req,
|
common.RequestType_PRSync: req,
|
||||||
@@ -172,7 +172,7 @@ func main() {
|
|||||||
common.RequestType_PRReviewRejected: req,
|
common.RequestType_PRReviewRejected: req,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
listenDefs.RabbitURL, _ = url.Parse(*rabbitUrl)
|
listenDefs.Connection().RabbitURL, _ = url.Parse(*rabbitUrl)
|
||||||
|
|
||||||
common.PanicOnError(listenDefs.ProcessRabbitMQEvents())
|
common.PanicOnError(common.ProcessRabbitMQEvents(listenDefs))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user