diff --git a/obs-staging-bot/main.go b/obs-staging-bot/main.go index 5c6001d..c0e3471 100644 --- a/obs-staging-bot/main.go +++ b/obs-staging-bot/main.go @@ -51,6 +51,15 @@ func fetchPrGit(h *common.RequestHandler, pr *models.PullRequest) error { } func getObsProjectAssociatedWithPr(baseProject string, pr *models.PullRequest) string { + if pr.Base.Repo.Name == common.DefaultGitPrj { + // if default project git, we don't need it in project name to be unique + return fmt.Sprintf( + "%s:%s:PR:%d", + baseProject, + common.ObsSafeProjectName(pr.Base.Repo.Owner.UserName), + pr.Index, + ) + } return fmt.Sprintf( "%s:%s:%s:PR:%d", baseProject, diff --git a/obs-status-service/.gitignore b/obs-status-service/.gitignore new file mode 100644 index 0000000..28bc07e --- /dev/null +++ b/obs-status-service/.gitignore @@ -0,0 +1 @@ +obs-status-service diff --git a/obs-status-service/main.go b/obs-status-service/main.go index 042e809..4634cc0 100644 --- a/obs-status-service/main.go +++ b/obs-status-service/main.go @@ -17,27 +17,34 @@ const ( type BuildStatusCacheItem struct { CacheTime time.Time - Result []*common.BuildResult + Result []*common.BuildResult } var obs *common.ObsClient - var buildStatusCache map[string]BuildStatusCacheItem - +var buildStatusCache map[string]BuildStatusCacheItem +/* func CacheBuildStatus(prj, pkg string) ([]common.BuildResult, error) { list, err := obs.BuildStatus(prj, pkg) if err != nil { return nil, err } + + return } - +*/ func PackageBuildStatus(prj, pkg string) (common.ObsBuildStatusDetail, error) { - for _, r := range list.Result { - - } -} - -func PackageStatusSvg( - + return common.ObsBuildStatusDetail { + Code: "succeeded", + Description: "stuff", + Success: true, + Finished: true, + }, nil +} +/* +func PackageStatusSvg(buildStatus []common.ObsBuildStatusDetail) []byte { + return +} +*/ func PackageStatusSummarySvg(buildStatus common.ObsBuildStatusDetail) []byte { fillColor := "orange" textColor := "grey" @@ -51,10 +58,8 @@ func PackageStatusSummarySvg(buildStatus common.ObsBuildStatusDetail) []byte { } } - return []byte( - ` + return []byte(` + ` + buildStatus.Code + ` `) @@ -62,13 +67,17 @@ func PackageStatusSummarySvg(buildStatus common.ObsBuildStatusDetail) []byte { func main() { common.RequireObsSecretToken() + go ProcessingObsMessages("rabbit.opensuse.org", "opensuse", "opensuse", "pubsub") + obsHost := os.Getenv("OBS_HOSTNAME") if len(obsHost) == 0 { log.Fatal("OBS_HOSTNAME env required.") } + /* if obs, err := common.NewObsClient(obsHost); err != nil { log.Fatal(err) } + */ http.HandleFunc("GET /{ObsProject}", func(res http.ResponseWriter, req *http.Request) { res.WriteHeader(http.StatusBadRequest) @@ -77,7 +86,8 @@ func main() { obsPrj := req.PathValue("ObsProject") obsPkg := req.PathValue("ObsPackage") - svg := PackageStatusSvg(PackageBuildStatus(obsPrj, obsPkg)) + status, _ := PackageBuildStatus(obsPrj, obsPkg) + svg := PackageStatusSummarySvg(status) res.Header().Add("content-type", "image/svg+xml") res.Header().Add("size", fmt.Sprint(len(svg))) diff --git a/obs-status-service/rabbitmq.go b/obs-status-service/rabbitmq.go index 433b299..06d7617 100644 --- a/obs-status-service/rabbitmq.go +++ b/obs-status-service/rabbitmq.go @@ -4,6 +4,7 @@ import ( "crypto/tls" "encoding/json" "log" + "os" "strings" "sync" "time" @@ -20,6 +21,8 @@ type BuildNotification struct { Starttime, Endtime, Readytime string } +var out *os.File + var obsNotifications map[string]*BuildNotification // Project/Package/Repositry/Arch as key var notificationMutex sync.RWMutex var notificationChannels map[string][]chan *BuildNotification @@ -65,6 +68,11 @@ func addObsNotificationToCache(notification *BuildNotification) { } func processObsMessage(msg *rabbitmq.Delivery) { + out.Write([]byte(msg.Timestamp.String())) + out.Write([]byte("\n")) + out.Write(msg.Body) + out.Write([]byte("\n--------------------------\n")) + return key := strings.SplitN(msg.RoutingKey, ".", 4) if len(key) != 4 || len(key[3]) < 7 || key[3][:6] != "build_" { return @@ -109,6 +117,13 @@ func ProcessingObsMessages(host, username, password, queueName string) { } }() + var err error + out, err = os.OpenFile("messages.txt", os.O_WRONLY, 0644) + if err != nil { + log.Printf("Cannot open message.txt: %v", err) + return + } + if obsNotifications == nil { obsNotifications = make(map[string]*BuildNotification) // notificationChannels = make(map[string]chan *BuildNotification) @@ -158,7 +173,7 @@ func ProcessingObsMessages(host, username, password, queueName string) { failOnError(err, "Cannot declare queue") log.Printf("queue: %s:%d", q.Name, q.Consumers) - err = ch.QueueBind(q.Name, "*.obs.package.*", "pubsub", false, nil) + err = ch.QueueBind(q.Name, "*.obs.*.*", "pubsub", false, nil) failOnError(err, "Cannot bind queue to exchange") msgs, err := ch.Consume(q.Name, "", true, true, false, false, nil) diff --git a/pr-review/main.go b/pr-review/main.go index 6da1db0..946e4e0 100644 --- a/pr-review/main.go +++ b/pr-review/main.go @@ -2,9 +2,11 @@ package main import ( "fmt" + "os" "path" "src.opensuse.org/autogits/common" + "src.opensuse.org/autogits/common/gitea-generated/models" ) const ( @@ -14,8 +16,40 @@ const ( PrReview = "pr-review" ) +func fetchPrGit(h *common.RequestHandler, pr *models.PullRequest) error { + // clone PR head and base and return path + if h.HasError() { + return h.Error + } + if _, err := os.Stat(path.Join(h.GitPath, pr.Head.Sha)); os.IsNotExist(err) { + h.GitExec("", "clone", "--depth", "1", pr.Head.Repo.CloneURL, pr.Head.Sha) + h.GitExec(pr.Head.Sha, "fetch", "--depth", "1", "origin", pr.Head.Sha, pr.Base.Sha) + } else if err != nil { + h.Error = err + } + + return h.Error +} + func processPullRequestClosed(h *common.RequestHandler) error { + // this needs to be moved to pull merger return nil +/* + req := h.Data.(*common.PullRequestAction) + if req.Repository.Name != common.DefaultGitPrj { + // we only handle project git PR updates here + return nil + } + + + + if err := fetchPrGit(h, req.Pull_Request); err != nil { + return err + } + headSubmodules := h.GitSubmoduleList(dir, pr.Head.Sha) + baseSubmodules := h.GitSubmoduleList(dir, pr.Base.Sha) + return nil + */ } func processPrjGitPullRequestSync(h *common.RequestHandler) error {