Compare commits
1 Commits
status_ser
...
conflicts
Author | SHA256 | Date | |
---|---|---|---|
3d8671a7fe |
@@ -59,7 +59,6 @@ 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
|
||||||
|
@@ -22,32 +22,55 @@ 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RabbitConnection struct {
|
const RequestType_CreateBrachTag = "create"
|
||||||
|
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
|
||||||
|
|
||||||
queueName string
|
GitAuthor string
|
||||||
ch *rabbitmq.Channel
|
Handlers map[string]RequestProcessor
|
||||||
|
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 *RabbitConnection) ProcessTopicChanges() {
|
func (l *ListenDefinitions) processTopicChanges(ch *rabbitmq.Channel, queueName string) {
|
||||||
for {
|
for {
|
||||||
topic, ok := <-l.topicSubChanges
|
topic, ok := <-l.topicSubChanges
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -57,11 +80,11 @@ func (l *RabbitConnection) ProcessTopicChanges() {
|
|||||||
LogDebug(" topic change:", topic)
|
LogDebug(" topic change:", topic)
|
||||||
switch topic[0] {
|
switch topic[0] {
|
||||||
case '+':
|
case '+':
|
||||||
if err := l.ch.QueueBind(l.queueName, topic[1:], "pubsub", false, nil); err != nil {
|
if err := ch.QueueBind(queueName, topic[1:], "pubsub", false, nil); err != nil {
|
||||||
LogError(err)
|
LogError(err)
|
||||||
}
|
}
|
||||||
case '-':
|
case '-':
|
||||||
if err := l.ch.QueueUnbind(l.queueName, topic[1:], "pubsub", nil); err != nil {
|
if err := ch.QueueUnbind(queueName, topic[1:], "pubsub", nil); err != nil {
|
||||||
LogError(err)
|
LogError(err)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -70,7 +93,7 @@ func (l *RabbitConnection) ProcessTopicChanges() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *RabbitConnection) ProcessRabbitMQ(msgCh chan<- RabbitMessage) error {
|
func (l *ListenDefinitions) processRabbitMQ(msgCh chan<- RabbitMessage) error {
|
||||||
queueName := l.RabbitURL.Path
|
queueName := l.RabbitURL.Path
|
||||||
l.RabbitURL.Path = ""
|
l.RabbitURL.Path = ""
|
||||||
|
|
||||||
@@ -129,7 +152,7 @@ func (l *RabbitConnection) 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()
|
go l.processTopicChanges(ch, q.Name)
|
||||||
|
|
||||||
for _, topic := range l.topics {
|
for _, topic := range l.topics {
|
||||||
l.topicSubChanges <- "+" + topic
|
l.topicSubChanges <- "+" + topic
|
||||||
@@ -151,18 +174,18 @@ func (l *RabbitConnection) ProcessRabbitMQ(msgCh chan<- RabbitMessage) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *RabbitConnection) ConnectAndProcessRabbitMQ(ch chan<- RabbitMessage) {
|
func (l *ListenDefinitions) 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...")
|
||||||
@@ -171,20 +194,49 @@ func (l *RabbitConnection) ConnectAndProcessRabbitMQ(ch chan<- RabbitMessage) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *RabbitConnection) ConnectToRabbitMQ(processor RabbitProcessor) <-chan RabbitMessage {
|
func (l *ListenDefinitions) connectToRabbitMQ() 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 (l *RabbitConnection) UpdateTopics(processor RabbitProcessor) {
|
func ProcessEvent(f RequestProcessor, request *Request) {
|
||||||
newTopics := processor.GenerateTopics()
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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:
|
||||||
@@ -221,8 +273,14 @@ next_new_topic:
|
|||||||
l.topics = newTopics
|
l.topics = newTopics
|
||||||
}
|
}
|
||||||
|
|
||||||
func ProcessRabbitMQEvents(processor RabbitProcessor) error {
|
func (l *ListenDefinitions) ProcessRabbitMQEvents() error {
|
||||||
ch := processor.Connection().ConnectToRabbitMQ(processor)
|
LogInfo("RabbitMQ connection:", l.RabbitURL.String())
|
||||||
|
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
|
||||||
@@ -231,8 +289,36 @@ func ProcessRabbitMQEvents(processor RabbitProcessor) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LogDebug("event:", msg.RoutingKey)
|
LogDebug("event:", msg.RoutingKey)
|
||||||
if err := processor.ProcessRabbitMessage(msg); err != nil {
|
|
||||||
LogError("Error processing", msg.RoutingKey, err)
|
route := strings.Split(msg.RoutingKey, ".")
|
||||||
|
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)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -50,13 +50,11 @@ 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 := &RabbitMQGiteaEventsProcessor{
|
l := ListenDefinitions{
|
||||||
Orgs: test.orgs1,
|
Orgs: test.orgs1,
|
||||||
Handlers: make(map[string]RequestProcessor),
|
Handlers: make(map[string]RequestProcessor),
|
||||||
c: &RabbitConnection{
|
topicSubChanges: make(chan string, len(test.topicDelta)*10),
|
||||||
RabbitURL: u,
|
RabbitURL: u,
|
||||||
topicSubChanges: make(chan string, len(test.topicDelta)*10),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
slices.Sort(test.topicDelta)
|
slices.Sort(test.topicDelta)
|
||||||
@@ -66,11 +64,11 @@ func TestListenDefinitionsTopicUpdate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
changes := []string{}
|
changes := []string{}
|
||||||
l.c.UpdateTopics(l)
|
l.UpdateTopics()
|
||||||
a:
|
a:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case c := <-l.c.topicSubChanges:
|
case c := <-l.topicSubChanges:
|
||||||
changes = append(changes, c)
|
changes = append(changes, c)
|
||||||
default:
|
default:
|
||||||
changes = []string{}
|
changes = []string{}
|
||||||
@@ -80,13 +78,13 @@ func TestListenDefinitionsTopicUpdate(t *testing.T) {
|
|||||||
|
|
||||||
l.Orgs = test.orgs2
|
l.Orgs = test.orgs2
|
||||||
|
|
||||||
l.c.UpdateTopics(l)
|
l.UpdateTopics()
|
||||||
changes = []string{}
|
changes = []string{}
|
||||||
|
|
||||||
b:
|
b:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case c := <-l.c.topicSubChanges:
|
case c := <-l.topicSubChanges:
|
||||||
changes = append(changes, c)
|
changes = append(changes, c)
|
||||||
default:
|
default:
|
||||||
slices.Sort(changes)
|
slices.Sort(changes)
|
@@ -1,56 +0,0 @@
|
|||||||
package common
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Manifest struct {
|
|
||||||
Subdirectories []string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Manifest) SubdirForPackage(pkg string) string {
|
|
||||||
if m == nil {
|
|
||||||
return pkg
|
|
||||||
}
|
|
||||||
|
|
||||||
idx := -1
|
|
||||||
matchLen := 0
|
|
||||||
basePkg := path.Base(pkg)
|
|
||||||
lowercasePkg := strings.ToLower(basePkg)
|
|
||||||
|
|
||||||
for i, sub := range m.Subdirectories {
|
|
||||||
basename := strings.ToLower(path.Base(sub))
|
|
||||||
if strings.HasPrefix(lowercasePkg, basename) && matchLen < len(basename) {
|
|
||||||
idx = i
|
|
||||||
matchLen = len(basename)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if idx > -1 {
|
|
||||||
return path.Join(m.Subdirectories[idx], basePkg)
|
|
||||||
}
|
|
||||||
return pkg
|
|
||||||
}
|
|
||||||
|
|
||||||
func ReadManifestFile(filename string) (*Manifest, error) {
|
|
||||||
data, err := os.ReadFile(filename)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return ParseManifestFile(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ParseManifestFile(data []byte) (*Manifest, error) {
|
|
||||||
ret := &Manifest{}
|
|
||||||
err := yaml.Unmarshal(data, ret)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret, nil
|
|
||||||
}
|
|
@@ -1,56 +0,0 @@
|
|||||||
package common_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"src.opensuse.org/autogits/common"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestManifestSubdirAssignments(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
Name string
|
|
||||||
ManifestContent string
|
|
||||||
Packages []string
|
|
||||||
ManifestLocations []string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
Name: "empty manifest",
|
|
||||||
Packages: []string{"atom", "blarg", "Foobar", "X-Ray", "boost", "NodeJS"},
|
|
||||||
ManifestLocations: []string{"atom", "blarg", "Foobar", "X-Ray", "boost", "NodeJS"},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "only few subdirs manifest",
|
|
||||||
ManifestContent: "subdirectories:\n - a\n - b",
|
|
||||||
Packages: []string{"atom", "blarg", "Foobar", "X-Ray", "Boost", "NodeJS"},
|
|
||||||
ManifestLocations: []string{"a/atom", "b/blarg", "Foobar", "X-Ray", "b/Boost", "NodeJS"},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "multilayer subdirs manifest",
|
|
||||||
ManifestContent: "subdirectories:\n - a\n - b\n - libs/boo",
|
|
||||||
Packages: []string{"atom", "blarg", "Foobar", "X-Ray", "Boost", "NodeJS"},
|
|
||||||
ManifestLocations: []string{"a/atom", "b/blarg", "Foobar", "X-Ray", "libs/boo/Boost", "NodeJS"},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "multilayer subdirs manifest with trailing /",
|
|
||||||
ManifestContent: "subdirectories:\n - a\n - b\n - libs/boo/\n - somedir/Node/",
|
|
||||||
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", "somedir/Node/node2"},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, test := range tests {
|
|
||||||
t.Run(test.Name, func(t *testing.T) {
|
|
||||||
m, err := common.ParseManifestFile([]byte(test.ManifestContent))
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, pkg := range test.Packages {
|
|
||||||
expected := test.ManifestLocations[i]
|
|
||||||
if l := m.SubdirForPackage(pkg); l != expected {
|
|
||||||
t.Error("Expected:", expected, "but got:", l)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
@@ -562,44 +562,25 @@ 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 {
|
||||||
@@ -619,7 +600,6 @@ 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 {
|
||||||
@@ -642,48 +622,6 @@ 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
|
||||||
@@ -951,11 +889,5 @@ 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
|
||||||
}
|
}
|
||||||
|
@@ -25,13 +25,6 @@ type PRSet struct {
|
|||||||
BotUser string
|
BotUser string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (prinfo *PRInfo) PRComponents() (org string, repo string, idx int64) {
|
|
||||||
org = prinfo.PR.Base.Repo.Owner.UserName
|
|
||||||
repo = prinfo.PR.Base.Repo.Name
|
|
||||||
idx = prinfo.PR.Index
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func readPRData(gitea GiteaPRFetcher, pr *models.PullRequest, currentSet []*PRInfo, config *AutogitConfig) ([]*PRInfo, error) {
|
func readPRData(gitea GiteaPRFetcher, pr *models.PullRequest, currentSet []*PRInfo, config *AutogitConfig) ([]*PRInfo, error) {
|
||||||
for _, p := range currentSet {
|
for _, p := range currentSet {
|
||||||
if pr.Index == p.PR.Index && pr.Base.Repo.Name == p.PR.Base.Repo.Name && pr.Base.Repo.Owner.UserName == p.PR.Base.Repo.Owner.UserName {
|
if pr.Index == p.PR.Index && pr.Base.Repo.Name == p.PR.Base.Repo.Name && pr.Base.Repo.Owner.UserName == p.PR.Base.Repo.Owner.UserName {
|
||||||
|
48
common/pr_conflict_resolution.go
Normal file
48
common/pr_conflict_resolution.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var UnknownParser error = errors.New("Cannot parse path")
|
||||||
|
|
||||||
|
type PRConflictResolver interface {
|
||||||
|
/*
|
||||||
|
stage_content -> { merge_base (stage1), head (stage2), merge_head (stage3) }
|
||||||
|
*/
|
||||||
|
Resolve(path string, stage_contents [3]string) error
|
||||||
|
}
|
||||||
|
|
||||||
|
var resolvers []PRConflictResolver = []PRConflictResolver{
|
||||||
|
&submodule_conflict_resolver{},
|
||||||
|
}
|
||||||
|
|
||||||
|
func ResolveMergeConflict(path string, file_contents [3]string) error {
|
||||||
|
for _, r := range resolvers {
|
||||||
|
if err := r.Resolve(path, file_contents); err != UnknownParser {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return UnknownParser
|
||||||
|
}
|
||||||
|
|
||||||
|
type submodule_conflict_resolver struct{}
|
||||||
|
|
||||||
|
func (*submodule_conflict_resolver) Resolve(path string, stage [3]string) error {
|
||||||
|
if path != ".gitmodules" {
|
||||||
|
return UnknownParser
|
||||||
|
}
|
||||||
|
return UnknownParser
|
||||||
|
}
|
||||||
|
|
||||||
|
type changes_file_resolver struct{}
|
||||||
|
|
||||||
|
func (*changes_file_resolver) Resolve(path string, stage [3]string) error {
|
||||||
|
if !strings.HasSuffix(path, ".changes") {
|
||||||
|
return UnknownParser
|
||||||
|
}
|
||||||
|
|
||||||
|
return UnknownParser
|
||||||
|
}
|
10
common/pr_conflict_resolution_test.go
Normal file
10
common/pr_conflict_resolution_test.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package common_test
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func ResolveSubmoduleConflicts(t *testing.T) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func ResolveChangesFileConflict(t *testing.T) {
|
||||||
|
}
|
||||||
|
|
@@ -1,130 +0,0 @@
|
|||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,115 +0,0 @@
|
|||||||
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)
|
|
||||||
}
|
|
@@ -113,10 +113,6 @@ 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,3 +173,4 @@ func (d DevelProjects) GetDevelProject(pkg string) (string, error) {
|
|||||||
|
|
||||||
return "", DevelProjectNotFound
|
return "", DevelProjectNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -73,10 +73,6 @@ func runObsCommand(args ...string) ([]string, error) {
|
|||||||
|
|
||||||
var DebugMode bool
|
var DebugMode bool
|
||||||
|
|
||||||
func giteaPackage(pkg string) string {
|
|
||||||
return strings.ReplaceAll(pkg, "+", "_")
|
|
||||||
}
|
|
||||||
|
|
||||||
func projectMaintainer(obs *common.ObsClient, prj string) ([]string, []string) { // users, groups
|
func projectMaintainer(obs *common.ObsClient, prj string) ([]string, []string) { // users, groups
|
||||||
meta, err := obs.GetProjectMeta(prj)
|
meta, err := obs.GetProjectMeta(prj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -190,16 +186,13 @@ func cloneDevel(git common.Git, gitDir, outName, urlString string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func importRepos(packages []string) {
|
func importRepos(packages []string) {
|
||||||
RepoToObsName := make(map[string]string)
|
|
||||||
|
|
||||||
factoryRepos := make([]*models.Repository, 0, len(packages)*2)
|
factoryRepos := make([]*models.Repository, 0, len(packages)*2)
|
||||||
develProjectPackages := make([]string, 0, len(packages))
|
develProjectPackages := make([]string, 0, len(packages))
|
||||||
for _, pkg := range packages {
|
for _, pkg := range packages {
|
||||||
src_pkg_name := strings.Split(pkg, ":")
|
src_pkg_name := strings.Split(pkg, ":")
|
||||||
RepoToObsName[giteaPackage(src_pkg_name[0])] = src_pkg_name[0]
|
|
||||||
repo, err := client.Repository.RepoGet(
|
repo, err := client.Repository.RepoGet(
|
||||||
repository.NewRepoGetParams().
|
repository.NewRepoGetParams().
|
||||||
WithDefaults().WithOwner("pool").WithRepo(giteaPackage(src_pkg_name[0])),
|
WithDefaults().WithOwner("pool").WithRepo(src_pkg_name[0]),
|
||||||
r.DefaultAuthentication)
|
r.DefaultAuthentication)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -226,7 +219,7 @@ func importRepos(packages []string) {
|
|||||||
|
|
||||||
oldPackageNames := make([]string, 0, len(factoryRepos))
|
oldPackageNames := make([]string, 0, len(factoryRepos))
|
||||||
for _, repo := range factoryRepos {
|
for _, repo := range factoryRepos {
|
||||||
oldPackageNames = append(oldPackageNames, RepoToObsName[repo.Name])
|
oldPackageNames = append(oldPackageNames, repo.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// fork packags from pool
|
// fork packags from pool
|
||||||
@@ -248,60 +241,44 @@ func importRepos(packages []string) {
|
|||||||
log.Println("adding remotes...")
|
log.Println("adding remotes...")
|
||||||
for i := 0; i < len(factoryRepos); i++ {
|
for i := 0; i < len(factoryRepos); i++ {
|
||||||
pkg := factoryRepos[i]
|
pkg := factoryRepos[i]
|
||||||
pkgName := RepoToObsName[pkg.Name]
|
|
||||||
gitName := pkg.Name
|
|
||||||
|
|
||||||
// verify that package was created by `git-importer`, or it's scmsync package and clone it
|
// verify that package was created by `git-importer`, or it's scmsync package and clone it
|
||||||
fi, err := os.Stat(filepath.Join(git.GetPath(), gitName))
|
fi, err := os.Stat(filepath.Join(git.GetPath(), pkg.Name))
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
if slices.Contains(develProjectPackages, pkgName) {
|
if slices.Contains(develProjectPackages, pkg.Name) {
|
||||||
// failed import of former factory package
|
// failed import of former factory package
|
||||||
log.Println("Failed to import former factory pkg:", pkgName)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// scmsync?
|
// scmsync?
|
||||||
devel_project, err := devel_projects.GetDevelProject(pkgName)
|
devel_project, err := devel_projects.GetDevelProject(pkg.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicln("devel project not found for", RepoToObsName[pkg.Name], "err:", err)
|
log.Panicln("devel project not found for", pkg.Name, "err:", err)
|
||||||
}
|
}
|
||||||
meta, _ := obs.GetPackageMeta(devel_project, pkgName)
|
meta, _ := obs.GetPackageMeta(devel_project, pkg.Name)
|
||||||
if len(meta.ScmSync) > 0 {
|
if len(meta.ScmSync) > 0 {
|
||||||
if err2 := cloneDevel(git, "", gitName, meta.ScmSync); err != nil {
|
if err2 := cloneDevel(git, "", pkg.Name, meta.ScmSync); err != nil {
|
||||||
log.Panicln(err2)
|
log.Panicln(err2)
|
||||||
}
|
}
|
||||||
if err2 := git.GitExec(gitName, "checkout", "-B", "main"); err2 != nil {
|
git.GitExecOrPanic(pkg.Name, "checkout", "-B", "main")
|
||||||
git.GitExecOrPanic(gitName, "checkout", "-B", "master")
|
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// try again, should now exist
|
// try again, should now exist
|
||||||
if fi, err = os.Stat(filepath.Join(git.GetPath(), gitName)); err != nil {
|
if fi, err = os.Stat(filepath.Join(git.GetPath(), pkg.Name)); err != nil {
|
||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
}
|
}
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
} else {
|
} else {
|
||||||
// verify that we do not have scmsync for imported packages
|
// verify that we do not have scmsync for imported packages
|
||||||
meta, err := obs.GetPackageMeta(prj, pkgName)
|
meta, err := obs.GetPackageMeta(prj, pkg.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(meta.ScmSync) > 0 {
|
if len(meta.ScmSync) > 0 {
|
||||||
u, err := url.Parse(meta.ScmSync)
|
log.Panicln("importing an scmsync package??:", prj, pkg.Name)
|
||||||
if err != nil {
|
|
||||||
log.Println("Invlid scmsync in", pkg, meta.ScmSync, err)
|
|
||||||
}
|
|
||||||
o, err := url.Parse(strings.TrimSpace(git.GitExecWithOutputOrPanic(gitName, "remote", "get-url", "origin")))
|
|
||||||
log.Println("Invlid scmsync in git repo", pkg, meta.ScmSync, err)
|
|
||||||
if u.Host != o.Host || u.Path != u.Path {
|
|
||||||
log.Panicln("importing an scmsync package??:", prj, gitName)
|
|
||||||
} else {
|
|
||||||
log.Println("previous SCMSYNC package. Pull.")
|
|
||||||
git.GitExecOrPanic(gitName, "pull", "origin", "HEAD:main")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,11 +287,11 @@ func importRepos(packages []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add remote repos
|
// add remote repos
|
||||||
out := git.GitExecWithOutputOrPanic(gitName, "remote", "show", "-n")
|
out := git.GitExecWithOutputOrPanic(pkg.Name, "remote", "show", "-n")
|
||||||
switch pkg.Owner.UserName {
|
switch pkg.Owner.UserName {
|
||||||
case "pool":
|
case "pool":
|
||||||
if !slices.Contains(strings.Split(out, "\n"), "pool") {
|
if !slices.Contains(strings.Split(out, "\n"), "pool") {
|
||||||
out := git.GitExecWithOutputOrPanic(gitName, "remote", "add", "pool", pkg.CloneURL)
|
out := git.GitExecWithOutputOrPanic(pkg.Name, "remote", "add", "pool", pkg.CloneURL)
|
||||||
if len(strings.TrimSpace(out)) > 1 {
|
if len(strings.TrimSpace(out)) > 1 {
|
||||||
log.Println(out)
|
log.Println(out)
|
||||||
}
|
}
|
||||||
@@ -421,22 +398,12 @@ func importRepos(packages []string) {
|
|||||||
|
|
||||||
for i := 0; i < len(develProjectPackages); i++ {
|
for i := 0; i < len(develProjectPackages); i++ {
|
||||||
pkg := develProjectPackages[i]
|
pkg := develProjectPackages[i]
|
||||||
meta, err := obs.GetPackageMeta(prj, pkg)
|
meta, _ := obs.GetPackageMeta(prj, pkg)
|
||||||
if err != nil {
|
if len(meta.ScmSync) > 0 {
|
||||||
meta, err = obs.GetPackageMeta(prj, pkg)
|
if err2 := cloneDevel(git, "", pkg, meta.ScmSync); err2 != nil {
|
||||||
if err != nil {
|
log.Panicln(err2)
|
||||||
log.Println("Error fetching pkg meta for:", prj, pkg, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if meta == nil {
|
|
||||||
log.Println(" **** pkg meta is nil? ****")
|
|
||||||
} else if len(meta.ScmSync) > 0 {
|
|
||||||
if _, err := os.Stat(path.Join(git.GetPath(), pkg)); os.IsNotExist(err) {
|
|
||||||
if err2 := cloneDevel(git, "", pkg, meta.ScmSync); err2 != nil {
|
|
||||||
log.Panicln(err2)
|
|
||||||
}
|
|
||||||
git.GitExecOrPanic(pkg, "checkout", "-B", "main")
|
|
||||||
}
|
}
|
||||||
|
git.GitExecOrPanic(pkg, "checkout", "-B", "main")
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
common.PanicOnError(gitImporter(prj, pkg))
|
common.PanicOnError(gitImporter(prj, pkg))
|
||||||
@@ -498,7 +465,7 @@ func importRepos(packages []string) {
|
|||||||
remotes := common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkg.Name, "remote", "show"), "\n")
|
remotes := common.SplitStringNoEmpty(git.GitExecWithOutputOrPanic(pkg.Name, "remote", "show"), "\n")
|
||||||
if !slices.Contains(remotes, "develorigin") {
|
if !slices.Contains(remotes, "develorigin") {
|
||||||
git.GitExecOrPanic(pkg.Name, "remote", "add", "develorigin", repo.SSHURL)
|
git.GitExecOrPanic(pkg.Name, "remote", "add", "develorigin", repo.SSHURL)
|
||||||
// git.GitExecOrPanic(pkgName, "fetch", "devel")
|
// git.GitExecOrPanic(pkg.Name, "fetch", "devel")
|
||||||
}
|
}
|
||||||
if slices.Contains(remotes, "origin") {
|
if slices.Contains(remotes, "origin") {
|
||||||
git.GitExecOrPanic(pkg.Name, "lfs", "fetch", "--all")
|
git.GitExecOrPanic(pkg.Name, "lfs", "fetch", "--all")
|
||||||
@@ -506,8 +473,8 @@ func importRepos(packages []string) {
|
|||||||
}
|
}
|
||||||
git.GitExecOrPanic(pkg.Name, "push", "develorigin", "main", "-f")
|
git.GitExecOrPanic(pkg.Name, "push", "develorigin", "main", "-f")
|
||||||
git.GitExec(pkg.Name, "push", "develorigin", "--delete", "factory", "devel")
|
git.GitExec(pkg.Name, "push", "develorigin", "--delete", "factory", "devel")
|
||||||
// git.GitExecOrPanic(pkg.ame, "checkout", "-B", "main", "devel/main")
|
// git.GitExecOrPanic(pkg.Name, "checkout", "-B", "main", "devel/main")
|
||||||
_, err := client.Repository.RepoEdit(repository.NewRepoEditParams().WithOwner(org).WithRepo(giteaPackage(repo.Name)).WithBody(&models.EditRepoOption{
|
_, err := client.Repository.RepoEdit(repository.NewRepoEditParams().WithOwner(org).WithRepo(repo.Name).WithBody(&models.EditRepoOption{
|
||||||
DefaultBranch: "main",
|
DefaultBranch: "main",
|
||||||
DefaultMergeStyle: "fast-forward-only",
|
DefaultMergeStyle: "fast-forward-only",
|
||||||
HasPullRequests: true,
|
HasPullRequests: true,
|
||||||
@@ -532,13 +499,12 @@ func importRepos(packages []string) {
|
|||||||
|
|
||||||
for _, pkg := range develProjectPackages {
|
for _, pkg := range develProjectPackages {
|
||||||
var repo *models.Repository
|
var repo *models.Repository
|
||||||
if repoData, err := client.Repository.RepoGet(repository.NewRepoGetParams().WithOwner(org).WithRepo(giteaPackage(pkg)), r.DefaultAuthentication); err != nil {
|
if repoData, err := client.Repository.RepoGet(repository.NewRepoGetParams().WithOwner(org).WithRepo(pkg), r.DefaultAuthentication); err != nil {
|
||||||
giteaPkg := giteaPackage(pkg)
|
|
||||||
_, err := client.Organization.CreateOrgRepo(organization.NewCreateOrgRepoParams().WithOrg(org).WithBody(
|
_, err := client.Organization.CreateOrgRepo(organization.NewCreateOrgRepoParams().WithOrg(org).WithBody(
|
||||||
&models.CreateRepoOption{
|
&models.CreateRepoOption{
|
||||||
ObjectFormatName: "sha256",
|
ObjectFormatName: "sha256",
|
||||||
AutoInit: false,
|
AutoInit: false,
|
||||||
Name: &giteaPkg,
|
Name: &pkg,
|
||||||
DefaultBranch: "main",
|
DefaultBranch: "main",
|
||||||
}),
|
}),
|
||||||
r.DefaultAuthentication,
|
r.DefaultAuthentication,
|
||||||
@@ -548,7 +514,7 @@ func importRepos(packages []string) {
|
|||||||
log.Panicln("Error creating new package repository:", pkg, err)
|
log.Panicln("Error creating new package repository:", pkg, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ret, err := client.Repository.RepoEdit(repository.NewRepoEditParams().WithOwner(org).WithRepo(giteaPkg).WithBody(
|
ret, err := client.Repository.RepoEdit(repository.NewRepoEditParams().WithOwner(org).WithRepo(pkg).WithBody(
|
||||||
&models.EditRepoOption{
|
&models.EditRepoOption{
|
||||||
HasPullRequests: true,
|
HasPullRequests: true,
|
||||||
HasPackages: false,
|
HasPackages: false,
|
||||||
@@ -588,7 +554,7 @@ func importRepos(packages []string) {
|
|||||||
git.GitExecOrPanic(pkg, "push", "develorigin", "main", "-f")
|
git.GitExecOrPanic(pkg, "push", "develorigin", "main", "-f")
|
||||||
git.GitExec(pkg, "push", "develorigin", "--delete", "factory", "devel")
|
git.GitExec(pkg, "push", "develorigin", "--delete", "factory", "devel")
|
||||||
|
|
||||||
_, err := client.Repository.RepoEdit(repository.NewRepoEditParams().WithOwner(org).WithRepo(giteaPackage(pkg)).WithBody(&models.EditRepoOption{
|
_, err := client.Repository.RepoEdit(repository.NewRepoEditParams().WithOwner(org).WithRepo(pkg).WithBody(&models.EditRepoOption{
|
||||||
DefaultBranch: "main",
|
DefaultBranch: "main",
|
||||||
DefaultMergeStyle: "fast-forward-only",
|
DefaultMergeStyle: "fast-forward-only",
|
||||||
}), r.DefaultAuthentication)
|
}), r.DefaultAuthentication)
|
||||||
@@ -687,7 +653,7 @@ func syncPackageCollaborators(pkg string, orig_uids []common.PersonRepoMeta) []s
|
|||||||
missing := []string{}
|
missing := []string{}
|
||||||
uids := make([]common.PersonRepoMeta, len(orig_uids))
|
uids := make([]common.PersonRepoMeta, len(orig_uids))
|
||||||
copy(uids, orig_uids)
|
copy(uids, orig_uids)
|
||||||
collab, err := client.Repository.RepoListCollaborators(repository.NewRepoListCollaboratorsParams().WithOwner(org).WithRepo(giteaPackage(pkg)), r.DefaultAuthentication)
|
collab, err := client.Repository.RepoListCollaborators(repository.NewRepoListCollaboratorsParams().WithOwner(org).WithRepo(pkg), r.DefaultAuthentication)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, &repository.RepoListCollaboratorsNotFound{}) {
|
if errors.Is(err, &repository.RepoListCollaboratorsNotFound{}) {
|
||||||
return missing
|
return missing
|
||||||
@@ -708,7 +674,7 @@ func syncPackageCollaborators(pkg string, orig_uids []common.PersonRepoMeta) []s
|
|||||||
log.Println("missing collabs for", pkg, ":", uids)
|
log.Println("missing collabs for", pkg, ":", uids)
|
||||||
}
|
}
|
||||||
for _, u := range uids {
|
for _, u := range uids {
|
||||||
_, err := client.Repository.RepoAddCollaborator(repository.NewRepoAddCollaboratorParams().WithOwner(org).WithRepo(giteaPackage(pkg)).WithBody(&models.AddCollaboratorOption{
|
_, err := client.Repository.RepoAddCollaborator(repository.NewRepoAddCollaboratorParams().WithOwner(org).WithRepo(pkg).WithBody(&models.AddCollaboratorOption{
|
||||||
Permission: "write",
|
Permission: "write",
|
||||||
}).WithCollaborator(u.UserID), r.DefaultAuthentication)
|
}).WithCollaborator(u.UserID), r.DefaultAuthentication)
|
||||||
|
|
||||||
@@ -843,14 +809,14 @@ func createPrjGit() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
}
|
}
|
||||||
file.WriteString("{\n // Reference build project\n \"ObsProject\": \"" + prj + "\",\n}\n")
|
file.WriteString("{\n // Reference build project\n \"ObsProject\": \""+prj+"\",\n}\n")
|
||||||
file.Close()
|
file.Close()
|
||||||
git.GitExecOrPanic(common.DefaultGitPrj, "add", "staging.config")
|
git.GitExecOrPanic(common.DefaultGitPrj, "add", "staging.config")
|
||||||
|
|
||||||
if file, err = os.Create(path.Join(git.GetPath(), common.DefaultGitPrj, "workflow.config")); err != nil {
|
if file, err = os.Create(path.Join(git.GetPath(), common.DefaultGitPrj, "workflow.config")); err != nil {
|
||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
}
|
}
|
||||||
file.WriteString("{\n \"Workflows\": [\"direct\", \"pr\"],\n \"Organization\": \"" + org + "\",\n}\n")
|
file.WriteString("{\n \"Workflows\": [\"direct\", \"pr\"],\n \"Organization\": \""+org+"\",\n}\n")
|
||||||
file.Close()
|
file.Close()
|
||||||
git.GitExecOrPanic(common.DefaultGitPrj, "add", "workflow.config")
|
git.GitExecOrPanic(common.DefaultGitPrj, "add", "workflow.config")
|
||||||
}
|
}
|
||||||
@@ -891,7 +857,6 @@ func main() {
|
|||||||
syncMaintainers := flags.Bool("sync-maintainers-only", false, "Sync maintainers to Gitea and exit")
|
syncMaintainers := flags.Bool("sync-maintainers-only", false, "Sync maintainers to Gitea and exit")
|
||||||
flags.BoolVar(&forceBadPool, "bad-pool", false, "Force packages if pool has no branches due to bad import")
|
flags.BoolVar(&forceBadPool, "bad-pool", false, "Force packages if pool has no branches due to bad import")
|
||||||
flags.BoolVar(&forceNonPoolPackages, "non-pool", false, "Allow packages that are not in pool to be created. WARNING: Can't add to factory later!")
|
flags.BoolVar(&forceNonPoolPackages, "non-pool", false, "Allow packages that are not in pool to be created. WARNING: Can't add to factory later!")
|
||||||
specificPackage := flags.String("package", "", "Process specific package only, ignoring the others")
|
|
||||||
|
|
||||||
if help := flags.Parse(os.Args[1:]); help == flag.ErrHelp || flags.NArg() != 2 {
|
if help := flags.Parse(os.Args[1:]); help == flag.ErrHelp || flags.NArg() != 2 {
|
||||||
printHelp(helpString.String())
|
printHelp(helpString.String())
|
||||||
@@ -988,15 +953,11 @@ func main() {
|
|||||||
if *purgeOnly {
|
if *purgeOnly {
|
||||||
log.Println("Purging repositories...")
|
log.Println("Purging repositories...")
|
||||||
for _, pkg := range packages {
|
for _, pkg := range packages {
|
||||||
client.Repository.RepoDelete(repository.NewRepoDeleteParams().WithOwner(org).WithRepo(giteaPackage(pkg)), r.DefaultAuthentication)
|
client.Repository.RepoDelete(repository.NewRepoDeleteParams().WithOwner(org).WithRepo(pkg), r.DefaultAuthentication)
|
||||||
}
|
}
|
||||||
os.Exit(10)
|
os.Exit(10)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(*specificPackage) != 0 {
|
|
||||||
importRepos([]string{*specificPackage})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
importRepos(packages)
|
importRepos(packages)
|
||||||
syncMaintainersToGitea(packages)
|
syncMaintainersToGitea(packages)
|
||||||
}
|
}
|
||||||
|
@@ -1,46 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/tailscale/hujson"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Config struct {
|
|
||||||
ForgeEndpoint string `json:"forge_url"`
|
|
||||||
Keys []string `json:"keys"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type contextKey string
|
|
||||||
|
|
||||||
const configKey contextKey = "config"
|
|
||||||
|
|
||||||
func ReadConfig(reader io.Reader) (*Config, error) {
|
|
||||||
data, err := io.ReadAll(reader)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error reading config data: %w", err)
|
|
||||||
}
|
|
||||||
config := Config{}
|
|
||||||
data, err = hujson.Standardize(data)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to parse json: %w", err)
|
|
||||||
}
|
|
||||||
if err := json.Unmarshal(data, &config); err != nil {
|
|
||||||
return nil, fmt.Errorf("error parsing json to api keys and target url: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &config, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func ReadConfigFile(filename string) (*Config, error) {
|
|
||||||
file, err := os.Open(filename)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("cannot open config file for reading. err: %w", err)
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
return ReadConfig(file)
|
|
||||||
}
|
|
@@ -1,15 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
func ConfigMiddleWare(cfg *Config) func(http.Handler) http.Handler {
|
|
||||||
return func(next http.Handler) http.Handler {
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
ctx := context.WithValue(r.Context(), configKey, cfg)
|
|
||||||
next.ServeHTTP(w, r.WithContext(ctx))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,169 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"slices"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"src.opensuse.org/autogits/common"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Status struct {
|
|
||||||
Context string `json:"context"`
|
|
||||||
State string `json:"state"`
|
|
||||||
TargetUrl string `json:"target_url"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type StatusInput struct {
|
|
||||||
State string `json:"state"`
|
|
||||||
TargetUrl string `json:"target_url"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
configFile := flag.String("config", "", "status proxy config file")
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
if *configFile == "" {
|
|
||||||
common.LogError("missing required argument config")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
config, err := ReadConfigFile(*configFile)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
common.LogError("Failed to read config file", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
|
||||||
|
|
||||||
mux.Handle("/repos/{owner}/{repo}/statuses/{sha}", ConfigMiddleWare(config)(http.HandlerFunc(StatusProxy)))
|
|
||||||
|
|
||||||
common.LogInfo("server up and listening on :3000")
|
|
||||||
err = http.ListenAndServe(":3000", mux)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
common.LogError("Server failed to start up", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func StatusProxy(w http.ResponseWriter, r *http.Request) {
|
|
||||||
if r.Method == http.MethodPost {
|
|
||||||
config, ok := r.Context().Value(configKey).(*Config)
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
common.LogError("Config missing from context")
|
|
||||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
header := r.Header.Get("Authorization")
|
|
||||||
if header == "" {
|
|
||||||
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
token_arr := strings.Split(header, " ")
|
|
||||||
if len(token_arr) != 2 {
|
|
||||||
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.EqualFold(token_arr[0], "Bearer") {
|
|
||||||
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
token := token_arr[1]
|
|
||||||
|
|
||||||
if !slices.Contains(config.Keys, token) {
|
|
||||||
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
owner := r.PathValue("owner")
|
|
||||||
repo := r.PathValue("repo")
|
|
||||||
sha := r.PathValue("sha")
|
|
||||||
|
|
||||||
if !ok {
|
|
||||||
common.LogError("Failed to get config from context, is it set?")
|
|
||||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
|
|
||||||
posturl := fmt.Sprintf("%s/repos/%s/%s/statuses/%s", config.ForgeEndpoint, owner, repo, sha)
|
|
||||||
decoder := json.NewDecoder(r.Body)
|
|
||||||
var statusinput StatusInput
|
|
||||||
err := decoder.Decode(&statusinput)
|
|
||||||
if err != nil {
|
|
||||||
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
status := Status{
|
|
||||||
Context: "Build in obs",
|
|
||||||
State: statusinput.State,
|
|
||||||
TargetUrl: statusinput.TargetUrl,
|
|
||||||
}
|
|
||||||
|
|
||||||
status_payload, err := json.Marshal(status)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
client := &http.Client{}
|
|
||||||
req, err := http.NewRequest("POST", posturl, bytes.NewBuffer(status_payload))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ForgeToken := os.Getenv("GITEA_TOKEN")
|
|
||||||
|
|
||||||
if ForgeToken == "" {
|
|
||||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
|
||||||
common.LogError("GITEA_TOKEN was not set, all requests will fail")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
req.Header.Add("Content-Type", "Content-Type")
|
|
||||||
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", ForgeToken))
|
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
common.LogError(fmt.Sprintf("Request to forge endpoint failed: %v", err))
|
|
||||||
http.Error(w, http.StatusText(http.StatusBadGateway), http.StatusBadGateway)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
w.WriteHeader(resp.StatusCode)
|
|
||||||
|
|
||||||
/*
|
|
||||||
the commented out section sets every key
|
|
||||||
value from the headers, unsure if this
|
|
||||||
leaks information from gitea
|
|
||||||
|
|
||||||
for k, v := range resp.Header {
|
|
||||||
for _, vv := range v {
|
|
||||||
w.Header().Add(k, vv)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
_, err = io.Copy(w, resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
common.LogError("Error copying response body: %v", err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
http.Error(w, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
@@ -11,7 +11,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
|
||||||
|
|
||||||
"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"
|
||||||
@@ -22,10 +21,9 @@ var acceptRx *regexp.Regexp
|
|||||||
var rejectRx *regexp.Regexp
|
var rejectRx *regexp.Regexp
|
||||||
var groupName string
|
var groupName string
|
||||||
|
|
||||||
func InitRegex(newGroupName string) {
|
func InitRegex(groupName string) {
|
||||||
groupName = newGroupName
|
acceptRx = regexp.MustCompile("\\s*:\\s*LGTM")
|
||||||
acceptRx = regexp.MustCompile("^:\\s*(LGTM|approved?)")
|
rejectRx = regexp.MustCompile("\\s*:\\s*")
|
||||||
rejectRx = regexp.MustCompile("^:\\s*")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseReviewLine(reviewText string) (bool, string) {
|
func ParseReviewLine(reviewText string) (bool, string) {
|
||||||
@@ -36,18 +34,7 @@ func ParseReviewLine(reviewText string) (bool, string) {
|
|||||||
return false, line
|
return false, line
|
||||||
}
|
}
|
||||||
|
|
||||||
l := line[glen:]
|
return true, line[glen:]
|
||||||
for idx, r := range l {
|
|
||||||
if unicode.IsSpace(r) {
|
|
||||||
continue
|
|
||||||
} else if r == ':' {
|
|
||||||
return true, l[idx:]
|
|
||||||
} else {
|
|
||||||
return false, line
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false, line
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReviewAccepted(reviewText string) bool {
|
func ReviewAccepted(reviewText string) bool {
|
||||||
|
@@ -2,76 +2,6 @@ package main
|
|||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestReviewApprovalCheck(t *testing.T) {
|
func TestReviews(t *testing.T) {
|
||||||
tests := []struct {
|
|
||||||
Name string
|
|
||||||
GroupName string
|
|
||||||
InString string
|
|
||||||
Approved bool
|
|
||||||
Rejected bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
Name: "Empty String",
|
|
||||||
GroupName: "group",
|
|
||||||
InString: "",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "Random Text",
|
|
||||||
GroupName: "group",
|
|
||||||
InString: "some things LGTM",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "Group name with Random Text means disapproval",
|
|
||||||
GroupName: "group",
|
|
||||||
InString: "@group: some things LGTM",
|
|
||||||
Rejected: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "Bad name with Approval",
|
|
||||||
GroupName: "group2",
|
|
||||||
InString: "@group: LGTM",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "Bad name with Approval",
|
|
||||||
GroupName: "group2",
|
|
||||||
InString: "@group: LGTM",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "LGTM approval",
|
|
||||||
GroupName: "group2",
|
|
||||||
InString: "@group2: LGTM",
|
|
||||||
Approved: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "approval",
|
|
||||||
GroupName: "group2",
|
|
||||||
InString: "@group2: approved",
|
|
||||||
Approved: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "approval",
|
|
||||||
GroupName: "group2",
|
|
||||||
InString: "@group2: approve",
|
|
||||||
Approved: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "disapproval",
|
|
||||||
GroupName: "group2",
|
|
||||||
InString: "@group2: disapprove",
|
|
||||||
Rejected: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, test := range tests {
|
|
||||||
t.Run(test.Name, func(t *testing.T) {
|
|
||||||
InitRegex(test.GroupName)
|
|
||||||
|
|
||||||
if r := ReviewAccepted(test.InString); r != test.Approved {
|
|
||||||
t.Error("ReviewAccepted() returned", r, "expecting", test.Approved)
|
|
||||||
}
|
|
||||||
if r := ReviewRejected(test.InString); r != test.Rejected {
|
|
||||||
t.Error("ReviewRejected() returned", r, "expecting", test.Rejected)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -22,7 +22,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
@@ -79,7 +78,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"]
|
||||||
@@ -109,10 +108,8 @@ 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", "https://api.opensuse.org", "OBS API endpoint for package status information")
|
obsHost := flag.String("obs-host", "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())
|
||||||
@@ -146,25 +143,21 @@ func main() {
|
|||||||
|
|
||||||
res.Header().Add("content-type", "image/svg+xml")
|
res.Header().Add("content-type", "image/svg+xml")
|
||||||
|
|
||||||
status := GetDetailedBuildStatus(prj, pkg, repo, arch)
|
prjStatus := GetCurrentStatus(prj)
|
||||||
res.Write(PackageStatusSummarySvg(status))
|
if prjStatus == nil {
|
||||||
})
|
|
||||||
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)
|
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))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
go ProcessUpdates()
|
go ProcessUpdates()
|
||||||
|
@@ -1,3 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
|
|
@@ -1,8 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -24,86 +24,14 @@ 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() {
|
||||||
@@ -125,3 +53,30 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
defs := &common.RabbitMQGiteaEventsProcessor{}
|
var defs common.ListenDefinitions
|
||||||
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.Connection().UpdateTopics(defs)
|
defs.UpdateTopics()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
signal.Notify(signalChannel, syscall.SIGHUP)
|
signal.Notify(signalChannel, syscall.SIGHUP)
|
||||||
@@ -573,17 +573,18 @@ func main() {
|
|||||||
|
|
||||||
updateConfiguration(*configFilename, &defs.Orgs)
|
updateConfiguration(*configFilename, &defs.Orgs)
|
||||||
|
|
||||||
defs.Connection().RabbitURL, err = url.Parse(*rabbitUrl)
|
defs.GitAuthor = GitAuthor
|
||||||
|
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(common.ProcessRabbitMQEvents(defs))
|
log.Fatal(defs.ProcessRabbitMQEvents())
|
||||||
}
|
}
|
||||||
|
@@ -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.RabbitMQGiteaEventsProcessor{
|
listenDefs := common.ListenDefinitions{
|
||||||
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.Connection().RabbitURL, _ = url.Parse(*rabbitUrl)
|
listenDefs.RabbitURL, _ = url.Parse(*rabbitUrl)
|
||||||
|
|
||||||
common.PanicOnError(common.ProcessRabbitMQEvents(listenDefs))
|
common.PanicOnError(listenDefs.ProcessRabbitMQEvents())
|
||||||
}
|
}
|
||||||
|
@@ -18,33 +18,6 @@ func prGitBranchNameForPR(repo string, prNo int) string {
|
|||||||
return fmt.Sprintf("PR_%s#%d", repo, prNo)
|
return fmt.Sprintf("PR_%s#%d", repo, prNo)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrjGitDescription(prset *common.PRSet) (title string, desc string) {
|
|
||||||
title_refs := make([]string, 0, len(prset.PRs)-1)
|
|
||||||
refs := make([]string, 0, len(prset.PRs)-1)
|
|
||||||
|
|
||||||
for _, pr := range prset.PRs {
|
|
||||||
org, repo, idx := pr.PRComponents()
|
|
||||||
|
|
||||||
title_refs = append(title_refs, repo)
|
|
||||||
ref := fmt.Sprintf(common.PrPattern, org, repo, idx)
|
|
||||||
refs = append(refs, ref)
|
|
||||||
}
|
|
||||||
|
|
||||||
title = "Forwarded PRs: " + strings.Join(title_refs, ", ")
|
|
||||||
desc = fmt.Sprintf("This is a forwarded pull request by %s\nreferencing the following pull request(s):\n\n", GitAuthor) + strings.Join(refs, ",\n")
|
|
||||||
|
|
||||||
if prset.Config.ManualMergeOnly {
|
|
||||||
desc = desc + "\n\nManualMergeOnly enabled. To merge, 'merge ok' is required in either the project PR or every package PR."
|
|
||||||
}
|
|
||||||
if prset.Config.ManualMergeProject {
|
|
||||||
desc = desc + "\nManualMergeProject enabled. To merge, 'merge ok' is required by project maintainer in the project PR."
|
|
||||||
}
|
|
||||||
if !prset.Config.ManualMergeOnly && !prset.Config.ManualMergeProject {
|
|
||||||
desc = desc + "\nAutomatic merge enabled. This will merge when all review requirements are satisfied."
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func verifyRepositoryConfiguration(repo *models.Repository) error {
|
func verifyRepositoryConfiguration(repo *models.Repository) error {
|
||||||
if repo.AutodetectManualMerge && repo.AllowManualMerge {
|
if repo.AutodetectManualMerge && repo.AllowManualMerge {
|
||||||
return nil
|
return nil
|
||||||
@@ -117,20 +90,24 @@ func AllocatePRProcessor(req *common.PullRequestWebhookEvent, configs common.Aut
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pr *PRProcessor) SetSubmodulesToMatchPRSet(prset *common.PRSet) error {
|
func (pr *PRProcessor) SetSubmodulesToMatchPRSet(prset *common.PRSet) ([]string, []string, error) {
|
||||||
git := pr.git
|
git := pr.git
|
||||||
subList, err := git.GitSubmoduleList(common.DefaultGitPrj, "HEAD")
|
subList, err := git.GitSubmoduleList(common.DefaultGitPrj, "HEAD")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.LogError("Error fetching submodule list for PrjGit", err)
|
common.LogError("Error fetching submodule list for PrjGit", err)
|
||||||
return err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refs := make([]string, 0, len(prset.PRs))
|
||||||
|
title_refs := make([]string, 0, len(prset.PRs))
|
||||||
for _, pr := range prset.PRs {
|
for _, pr := range prset.PRs {
|
||||||
if prset.IsPrjGitPR(pr.PR) {
|
if prset.IsPrjGitPR(pr.PR) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
org, repo, idx := pr.PRComponents()
|
org := pr.PR.Base.Repo.Owner.UserName
|
||||||
|
repo := pr.PR.Base.Repo.Name
|
||||||
|
idx := pr.PR.Index
|
||||||
prHead := pr.PR.Head.Sha
|
prHead := pr.PR.Head.Sha
|
||||||
revert := false
|
revert := false
|
||||||
|
|
||||||
@@ -141,7 +118,7 @@ func (pr *PRProcessor) SetSubmodulesToMatchPRSet(prset *common.PRSet) error {
|
|||||||
var valid bool
|
var valid bool
|
||||||
if prHead, valid = git.GitSubmoduleCommitId(common.DefaultGitPrj, repo, prjGitPR.PR.MergeBase); !valid {
|
if prHead, valid = git.GitSubmoduleCommitId(common.DefaultGitPrj, repo, prjGitPR.PR.MergeBase); !valid {
|
||||||
common.LogError("Failed fetching original submodule commit id for repo")
|
common.LogError("Failed fetching original submodule commit id for repo")
|
||||||
return err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
revert = true
|
revert = true
|
||||||
@@ -158,6 +135,9 @@ func (pr *PRProcessor) SetSubmodulesToMatchPRSet(prset *common.PRSet) error {
|
|||||||
|
|
||||||
if revert {
|
if revert {
|
||||||
commitMsg = fmt.Sprintln("auto-created for", repo, "\n\nThis commit was autocreated by", GitAuthor, "removing\n", ref)
|
commitMsg = fmt.Sprintln("auto-created for", repo, "\n\nThis commit was autocreated by", GitAuthor, "removing\n", ref)
|
||||||
|
} else {
|
||||||
|
refs = append(refs, ref)
|
||||||
|
title_refs = append(title_refs, repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
updateSubmoduleInPR(submodulePath, prHead, git)
|
updateSubmoduleInPR(submodulePath, prHead, git)
|
||||||
@@ -176,7 +156,7 @@ func (pr *PRProcessor) SetSubmodulesToMatchPRSet(prset *common.PRSet) error {
|
|||||||
common.LogError("Failed to find expected repo:", repo)
|
common.LogError("Failed to find expected repo:", repo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return title_refs, refs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pr *PRProcessor) CreatePRjGitPR(prjGitPRbranch string, prset *common.PRSet) error {
|
func (pr *PRProcessor) CreatePRjGitPR(prjGitPRbranch string, prset *common.PRSet) error {
|
||||||
@@ -196,7 +176,8 @@ func (pr *PRProcessor) CreatePRjGitPR(prjGitPRbranch string, prset *common.PRSet
|
|||||||
common.LogError("Failed to fetch PrjGit branch", prjGitPRbranch, err)
|
common.LogError("Failed to fetch PrjGit branch", prjGitPRbranch, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := pr.SetSubmodulesToMatchPRSet(prset); err != nil {
|
title_refs, refs, err := pr.SetSubmodulesToMatchPRSet(prset)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
newHeadCommit, err := git.GitBranchHead(common.DefaultGitPrj, prjGitPRbranch)
|
newHeadCommit, err := git.GitBranchHead(common.DefaultGitPrj, prjGitPRbranch)
|
||||||
@@ -207,8 +188,10 @@ func (pr *PRProcessor) CreatePRjGitPR(prjGitPRbranch string, prset *common.PRSet
|
|||||||
|
|
||||||
if !common.IsDryRun && headCommit != newHeadCommit {
|
if !common.IsDryRun && headCommit != newHeadCommit {
|
||||||
common.PanicOnError(git.GitExec(common.DefaultGitPrj, "push", RemoteName, "+HEAD:"+prjGitPRbranch))
|
common.PanicOnError(git.GitExec(common.DefaultGitPrj, "push", RemoteName, "+HEAD:"+prjGitPRbranch))
|
||||||
title, desc := PrjGitDescription(prset)
|
pr, err := Gitea.CreatePullRequestIfNotExist(PrjGit, prjGitPRbranch, PrjGitBranch,
|
||||||
pr, err := Gitea.CreatePullRequestIfNotExist(PrjGit, prjGitPRbranch, PrjGitBranch, title, desc)
|
"Forwarded PRs: "+strings.Join(title_refs, ", "),
|
||||||
|
fmt.Sprintf("This is a forwarded pull request by %s\nreferencing the following pull request(s):\n\n", GitAuthor)+strings.Join(refs, ", "),
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
common.LogError("Error creating PrjGit PR:", err)
|
common.LogError("Error creating PrjGit PR:", err)
|
||||||
return err
|
return err
|
||||||
@@ -264,10 +247,10 @@ func (pr *PRProcessor) UpdatePrjGitPR(prset *common.PRSet) error {
|
|||||||
PrjGitPR.RemoteName, err = git.GitClone(common.DefaultGitPrj, prjGitPRbranch, PrjGit.SSHURL)
|
PrjGitPR.RemoteName, err = git.GitClone(common.DefaultGitPrj, prjGitPRbranch, PrjGit.SSHURL)
|
||||||
common.PanicOnError(err)
|
common.PanicOnError(err)
|
||||||
git.GitExecOrPanic(common.DefaultGitPrj, "fetch", PrjGitPR.RemoteName, PrjGitBranch)
|
git.GitExecOrPanic(common.DefaultGitPrj, "fetch", PrjGitPR.RemoteName, PrjGitBranch)
|
||||||
|
ExpectedMergeCommit, err := git.GitRemoteHead(common.DefaultGitPrj, PrjGitPR.RemoteName, PrjGitBranch)
|
||||||
|
|
||||||
forcePush := false
|
forcePush := false
|
||||||
// trust Gitea here on mergeability
|
if ExpectedMergeCommit != PrjGitPR.PR.MergeBase {
|
||||||
if !PrjGitPR.PR.Mergeable {
|
|
||||||
common.PanicOnError(pr.RebaseAndSkipSubmoduleCommits(prset, PrjGitBranch))
|
common.PanicOnError(pr.RebaseAndSkipSubmoduleCommits(prset, PrjGitBranch))
|
||||||
forcePush = true
|
forcePush = true
|
||||||
}
|
}
|
||||||
@@ -277,7 +260,8 @@ func (pr *PRProcessor) UpdatePrjGitPR(prset *common.PRSet) error {
|
|||||||
common.LogError("Failed to fetch PrjGit branch", prjGitPRbranch, err)
|
common.LogError("Failed to fetch PrjGit branch", prjGitPRbranch, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := pr.SetSubmodulesToMatchPRSet(prset); err != nil {
|
title_refs, refs, err := pr.SetSubmodulesToMatchPRSet(prset)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
newHeadCommit, err := git.GitBranchHead(common.DefaultGitPrj, prjGitPRbranch)
|
newHeadCommit, err := git.GitBranchHead(common.DefaultGitPrj, prjGitPRbranch)
|
||||||
@@ -294,7 +278,9 @@ func (pr *PRProcessor) UpdatePrjGitPR(prset *common.PRSet) error {
|
|||||||
common.PanicOnError(git.GitExec(common.DefaultGitPrj, params...))
|
common.PanicOnError(git.GitExec(common.DefaultGitPrj, params...))
|
||||||
|
|
||||||
// update PR
|
// update PR
|
||||||
PrjGitTitle, PrjGitBody := PrjGitDescription(prset)
|
PrjGitTitle := "Forwarded PRs: " + strings.Join(title_refs, ", ")
|
||||||
|
PrjGitBody := fmt.Sprintf("This is a forwarded pull request by %s\nreferencing the following pull request(s):\n\n", GitAuthor) + strings.Join(refs, ", ")
|
||||||
|
|
||||||
Gitea.UpdatePullRequest(PrjGit.Owner.UserName, PrjGit.Name, PrjGitPR.PR.Index, &models.EditPullRequestOption{
|
Gitea.UpdatePullRequest(PrjGit.Owner.UserName, PrjGit.Name, PrjGitPR.PR.Index, &models.EditPullRequestOption{
|
||||||
RemoveDeadline: true,
|
RemoveDeadline: true,
|
||||||
Title: PrjGitTitle,
|
Title: PrjGitTitle,
|
||||||
@@ -340,7 +326,9 @@ func (pr *PRProcessor) Process(req *common.PullRequestWebhookEvent) error {
|
|||||||
common.LogInfo("PR State is closed:", prjGitPR.PR.State)
|
common.LogInfo("PR State is closed:", prjGitPR.PR.State)
|
||||||
for _, pr := range prset.PRs {
|
for _, pr := range prset.PRs {
|
||||||
if pr.PR.State == "open" {
|
if pr.PR.State == "open" {
|
||||||
org, repo, idx := pr.PRComponents()
|
org := pr.PR.Base.Repo.Owner.UserName
|
||||||
|
repo := pr.PR.Base.Repo.Name
|
||||||
|
idx := pr.PR.Index
|
||||||
Gitea.UpdatePullRequest(org, repo, idx, &models.EditPullRequestOption{
|
Gitea.UpdatePullRequest(org, repo, idx, &models.EditPullRequestOption{
|
||||||
State: "closed",
|
State: "closed",
|
||||||
})
|
})
|
||||||
@@ -349,14 +337,6 @@ func (pr *PRProcessor) Process(req *common.PullRequestWebhookEvent) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(prset.PRs) > 1 {
|
|
||||||
for _, pr := range prset.PRs {
|
|
||||||
if prset.IsPrjGitPR(pr.PR) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = pr.UpdatePrjGitPR(prset); err != nil {
|
if err = pr.UpdatePrjGitPR(prset); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user