.
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 {
|
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(
|
return fmt.Sprintf(
|
||||||
"%s:%s:%s:PR:%d",
|
"%s:%s:%s:PR:%d",
|
||||||
baseProject,
|
baseProject,
|
||||||
|
1
obs-status-service/.gitignore
vendored
Normal file
1
obs-status-service/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
obs-status-service
|
@ -17,27 +17,34 @@ const (
|
|||||||
|
|
||||||
type BuildStatusCacheItem struct {
|
type BuildStatusCacheItem struct {
|
||||||
CacheTime time.Time
|
CacheTime time.Time
|
||||||
Result []*common.BuildResult
|
Result []*common.BuildResult
|
||||||
}
|
}
|
||||||
|
|
||||||
var obs *common.ObsClient
|
var obs *common.ObsClient
|
||||||
var buildStatusCache map[string]BuildStatusCacheItem
|
var buildStatusCache map[string]BuildStatusCacheItem
|
||||||
|
/*
|
||||||
func CacheBuildStatus(prj, pkg string) ([]common.BuildResult, error) {
|
func CacheBuildStatus(prj, pkg string) ([]common.BuildResult, error) {
|
||||||
list, err := obs.BuildStatus(prj, pkg)
|
list, err := obs.BuildStatus(prj, pkg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
*/
|
||||||
func PackageBuildStatus(prj, pkg string) (common.ObsBuildStatusDetail, error) {
|
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(
|
func PackageStatusSvg(buildStatus []common.ObsBuildStatusDetail) []byte {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
*/
|
||||||
func PackageStatusSummarySvg(buildStatus common.ObsBuildStatusDetail) []byte {
|
func PackageStatusSummarySvg(buildStatus common.ObsBuildStatusDetail) []byte {
|
||||||
fillColor := "orange"
|
fillColor := "orange"
|
||||||
textColor := "grey"
|
textColor := "grey"
|
||||||
@ -51,10 +58,8 @@ func PackageStatusSummarySvg(buildStatus common.ObsBuildStatusDetail) []byte {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return []byte(
|
return []byte(`
|
||||||
`<svg version="1.1"
|
<svg version="1.1" width="200" height="20" xmlns="http://www.w3.org/2000/svg">
|
||||||
width="200" height="20"
|
|
||||||
xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<rect width="100%" height="100%" fill="` + fillColor + `" />
|
<rect width="100%" height="100%" fill="` + fillColor + `" />
|
||||||
<text x="20" y="25" font-size="60" text-anchor="middle" fill="` + textColor + `">` + buildStatus.Code + `</text>
|
<text x="20" y="25" font-size="60" text-anchor="middle" fill="` + textColor + `">` + buildStatus.Code + `</text>
|
||||||
</svg>`)
|
</svg>`)
|
||||||
@ -62,13 +67,17 @@ func PackageStatusSummarySvg(buildStatus common.ObsBuildStatusDetail) []byte {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
common.RequireObsSecretToken()
|
common.RequireObsSecretToken()
|
||||||
|
go ProcessingObsMessages("rabbit.opensuse.org", "opensuse", "opensuse", "pubsub")
|
||||||
|
|
||||||
obsHost := os.Getenv("OBS_HOSTNAME")
|
obsHost := os.Getenv("OBS_HOSTNAME")
|
||||||
if len(obsHost) == 0 {
|
if len(obsHost) == 0 {
|
||||||
log.Fatal("OBS_HOSTNAME env required.")
|
log.Fatal("OBS_HOSTNAME env required.")
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
if obs, err := common.NewObsClient(obsHost); err != nil {
|
if obs, err := common.NewObsClient(obsHost); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
http.HandleFunc("GET /{ObsProject}", func(res http.ResponseWriter, req *http.Request) {
|
http.HandleFunc("GET /{ObsProject}", func(res http.ResponseWriter, req *http.Request) {
|
||||||
res.WriteHeader(http.StatusBadRequest)
|
res.WriteHeader(http.StatusBadRequest)
|
||||||
@ -77,7 +86,8 @@ func main() {
|
|||||||
obsPrj := req.PathValue("ObsProject")
|
obsPrj := req.PathValue("ObsProject")
|
||||||
obsPkg := req.PathValue("ObsPackage")
|
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("content-type", "image/svg+xml")
|
||||||
res.Header().Add("size", fmt.Sprint(len(svg)))
|
res.Header().Add("size", fmt.Sprint(len(svg)))
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -20,6 +21,8 @@ type BuildNotification struct {
|
|||||||
Starttime, Endtime, Readytime string
|
Starttime, Endtime, Readytime string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var out *os.File
|
||||||
|
|
||||||
var obsNotifications map[string]*BuildNotification // Project/Package/Repositry/Arch as key
|
var obsNotifications map[string]*BuildNotification // Project/Package/Repositry/Arch as key
|
||||||
var notificationMutex sync.RWMutex
|
var notificationMutex sync.RWMutex
|
||||||
var notificationChannels map[string][]chan *BuildNotification
|
var notificationChannels map[string][]chan *BuildNotification
|
||||||
@ -65,6 +68,11 @@ func addObsNotificationToCache(notification *BuildNotification) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func processObsMessage(msg *rabbitmq.Delivery) {
|
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)
|
key := strings.SplitN(msg.RoutingKey, ".", 4)
|
||||||
if len(key) != 4 || len(key[3]) < 7 || key[3][:6] != "build_" {
|
if len(key) != 4 || len(key[3]) < 7 || key[3][:6] != "build_" {
|
||||||
return
|
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 {
|
if obsNotifications == nil {
|
||||||
obsNotifications = make(map[string]*BuildNotification)
|
obsNotifications = make(map[string]*BuildNotification)
|
||||||
// notificationChannels = make(map[string]chan *BuildNotification)
|
// notificationChannels = make(map[string]chan *BuildNotification)
|
||||||
@ -158,7 +173,7 @@ func ProcessingObsMessages(host, username, password, queueName string) {
|
|||||||
failOnError(err, "Cannot declare queue")
|
failOnError(err, "Cannot declare queue")
|
||||||
log.Printf("queue: %s:%d", q.Name, q.Consumers)
|
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")
|
failOnError(err, "Cannot bind queue to exchange")
|
||||||
|
|
||||||
msgs, err := ch.Consume(q.Name, "", true, true, false, false, nil)
|
msgs, err := ch.Consume(q.Name, "", true, true, false, false, nil)
|
||||||
|
@ -2,9 +2,11 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
"src.opensuse.org/autogits/common"
|
"src.opensuse.org/autogits/common"
|
||||||
|
"src.opensuse.org/autogits/common/gitea-generated/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -14,8 +16,40 @@ const (
|
|||||||
PrReview = "pr-review"
|
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 {
|
func processPullRequestClosed(h *common.RequestHandler) error {
|
||||||
|
// this needs to be moved to pull merger
|
||||||
return nil
|
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 {
|
func processPrjGitPullRequestSync(h *common.RequestHandler) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user