fix obs staging bot

This commit is contained in:
Adam Majer 2025-02-10 15:14:29 +01:00
parent 61d9359ce3
commit 2f38e559d1
2 changed files with 26 additions and 11 deletions

View File

@ -61,9 +61,9 @@ type RepositoryPathMeta struct {
type RepositoryMeta struct { type RepositoryMeta struct {
Name string `xml:"name,attr"` Name string `xml:"name,attr"`
BuildTrigger string `xml:"rebuild,attr"` BuildTrigger string `xml:"rebuild,attr,omitempty"`
BlockMode string `xml:"block"` BlockMode string `xml:"block,attr,omitempty"`
LinkedBuild string `xml:"linkedbuild"` LinkedBuild string `xml:"linkedbuild,attr,omitempty"`
Archs []string `xml:"arch"` Archs []string `xml:"arch"`
Paths []RepositoryPathMeta `xml:"path"` Paths []RepositoryPathMeta `xml:"path"`
} }
@ -76,8 +76,8 @@ type ProjectMeta struct {
XMLName xml.Name `xml:"project"` XMLName xml.Name `xml:"project"`
Name string `xml:"name,attr"` Name string `xml:"name,attr"`
Title string `xml:"title"` Title string `xml:"title"`
Description string `xml:"description"` Description string `xml:"description,omitempty"`
Url string `xml:"url"` Url string `xml:"url,omitempty"`
ScmSync string `xml:"scmsync"` ScmSync string `xml:"scmsync"`
Repositories []RepositoryMeta `xml:"repository"` Repositories []RepositoryMeta `xml:"repository"`

View File

@ -551,17 +551,30 @@ func pollWorkNotifications(giteaHost string) {
if data != nil { if data != nil {
for _, notification := range data { for _, notification := range data {
switch notification.Subject.Type { log.Println(notification.ID, "--", notification.Subject)
case "Pull":
processPullNotification(gitea, notification) if !ListPullNotificationsOnly && (ProcessIDOnly < 0 || ProcessIDOnly == notification.ID) {
default: switch notification.Subject.Type {
gitea.SetNotificationRead(notification.ID) case "Pull":
processPullNotification(gitea, notification)
default:
gitea.SetNotificationRead(notification.ID)
}
} }
} }
} }
} }
var ListPullNotificationsOnly bool
var ProcessIDOnly int64
var Debug bool
func main() { func main() {
flag.BoolVar(&Debug, "debug", false, "One-shot run. Use for debugging")
flag.BoolVar(&ListPullNotificationsOnly, "list-notifications-only", false, "Only lists notifications without acting on them")
flag.Int64Var(&ProcessIDOnly, "id", -1, "Process only the specific ID and ignore the rest. Use for debugging")
flag.Parse()
failOnError(common.RequireGiteaSecretToken(), "Cannot find GITEA_TOKEN") failOnError(common.RequireGiteaSecretToken(), "Cannot find GITEA_TOKEN")
failOnError(common.RequireObsSecretToken(), "Cannot find OBS_USER and OBS_PASSWORD") failOnError(common.RequireObsSecretToken(), "Cannot find OBS_USER and OBS_PASSWORD")
@ -571,7 +584,9 @@ func main() {
for { for {
pollWorkNotifications(*giteaHost) pollWorkNotifications(*giteaHost)
if Debug {
break
}
time.Sleep(10 * time.Minute) time.Sleep(10 * time.Minute)
} }
} }