.
This commit is contained in:
parent
07612fdcfc
commit
f4609de5a3
@ -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,
|
||||
|
1
obs-status-service/.gitignore
vendored
Normal file
1
obs-status-service/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
obs-status-service
|
@ -22,22 +22,29 @@ type BuildStatusCacheItem struct {
|
||||
|
||||
var obs *common.ObsClient
|
||||
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 {
|
||||
|
||||
return common.ObsBuildStatusDetail {
|
||||
Code: "succeeded",
|
||||
Description: "stuff",
|
||||
Success: true,
|
||||
Finished: true,
|
||||
}, nil
|
||||
}
|
||||
/*
|
||||
func PackageStatusSvg(buildStatus []common.ObsBuildStatusDetail) []byte {
|
||||
return
|
||||
}
|
||||
|
||||
func PackageStatusSvg(
|
||||
|
||||
*/
|
||||
func PackageStatusSummarySvg(buildStatus common.ObsBuildStatusDetail) []byte {
|
||||
fillColor := "orange"
|
||||
textColor := "grey"
|
||||
@ -51,10 +58,8 @@ func PackageStatusSummarySvg(buildStatus common.ObsBuildStatusDetail) []byte {
|
||||
}
|
||||
}
|
||||
|
||||
return []byte(
|
||||
`<svg version="1.1"
|
||||
width="200" height="20"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
return []byte(`
|
||||
<svg version="1.1" width="200" height="20" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect width="100%" height="100%" fill="` + fillColor + `" />
|
||||
<text x="20" y="25" font-size="60" text-anchor="middle" fill="` + textColor + `">` + buildStatus.Code + `</text>
|
||||
</svg>`)
|
||||
@ -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)))
|
||||
|
@ -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)
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user