package main

import (
	"os"

	"src.opensuse.org/autogits/common"
)

const (
	GitAuthor = "GiteaBot - Obs Staging"
	ObsBuildBot = "/obsbuild"
)

var GiteaToken string
	var runId uint



func allocateRequestHandler() *common.RequestHandler {
	return &common.RequestHandler {
		Logger: common.CreateStdoutLogger(os.Stdout, os.Stdout),
	}
}

func PollWorkNotifications() {
	h := allocateRequestHandler()
	data, err := h.GetNotifications(nil)

	if err != nil {
		h.LogPlainError(err)
		return
	}

	if data != nil {
		for _, notification := range data {
			h.Log("[+] id: %d", notification.ID)
			h.Log("    title: %s", notification.Subject.Title)
			h.Log("    subj:  %#v", notification.Subject)
		}
	}
}

func main() {
	var defs common.ListenDefinitions

	defs.Url = ObsBuildBot
	defs.GitAuthor = GitAuthor

	common.RequireGiteaSecretToken()
	common.RequireObsSecretToken()

//	go ProcessingObsMessages("rabbit.opensuse.org", "opensuse", "opensuse", "")

	PollWorkNotifications()

	stuck := make(chan int) 
	<-stuck
}
