.
This commit is contained in:
parent
8db4d8c302
commit
6d650d68b1
@ -1,10 +1,12 @@
|
|||||||
package common;
|
package common
|
||||||
|
|
||||||
const (
|
const (
|
||||||
GiteaTokenEnv = "GITEA_TOKEN"
|
GiteaTokenEnv = "GITEA_TOKEN"
|
||||||
|
ObsUserEnv = "OBS_USER"
|
||||||
|
ObsPasswordEnv = "OBS_PW"
|
||||||
|
|
||||||
DefaultGitPrj = "_ObsPrj"
|
DefaultGitPrj = "_ObsPrj"
|
||||||
GiteaRequestHeader = "X-Gitea-Event-Type"
|
GiteaRequestHeader = "X-Gitea-Event-Type"
|
||||||
|
|
||||||
Bot_BuildReview = "autogits_obs_staging_bot"
|
Bot_BuildReview = "autogits_obs_staging_bot"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ type ObsClient struct {
|
|||||||
cookie string
|
cookie string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewObsClient(host, username, password string) (*ObsClient, error) {
|
func NewObsClient(host string) (*ObsClient, error) {
|
||||||
baseUrl, err := url.Parse("https://" + host)
|
baseUrl, err := url.Parse("https://" + host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -25,8 +25,8 @@ func NewObsClient(host, username, password string) (*ObsClient, error) {
|
|||||||
return &ObsClient{
|
return &ObsClient{
|
||||||
baseUrl: baseUrl,
|
baseUrl: baseUrl,
|
||||||
client: &http.Client{},
|
client: &http.Client{},
|
||||||
user: username,
|
user: obsUser,
|
||||||
password: password,
|
password: obsPassword,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,6 +40,10 @@ type RepositoryMeta struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Flags struct {
|
||||||
|
Contents string `xml:",innerxml"`
|
||||||
|
}
|
||||||
|
|
||||||
type ProjectMeta struct {
|
type ProjectMeta struct {
|
||||||
XMLName xml.Name `xml:"project"`
|
XMLName xml.Name `xml:"project"`
|
||||||
Name string `xml:"name,attr"`
|
Name string `xml:"name,attr"`
|
||||||
@ -47,6 +51,9 @@ type ProjectMeta struct {
|
|||||||
Description string `xml:"description"`
|
Description string `xml:"description"`
|
||||||
ScmSync string `xml:"xmlsync"`
|
ScmSync string `xml:"xmlsync"`
|
||||||
Repositories []Repository `xml:"repository"`
|
Repositories []Repository `xml:"repository"`
|
||||||
|
|
||||||
|
BuildFlags Flags `xml:"build"`
|
||||||
|
PublicFlags Flags `xml:"publish"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseProjectMeta(data []byte) (*ProjectMeta, error) {
|
func parseProjectMeta(data []byte) (*ProjectMeta, error) {
|
||||||
|
@ -8,10 +8,12 @@ func TestParseProjectMeta(t *testing.T) {
|
|||||||
res, err := parseProjectMeta([]byte(metaPrjData))
|
res, err := parseProjectMeta([]byte(metaPrjData))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if res.
|
if len(res.BuildFlags.Contents) < 1 {
|
||||||
|
t.Fatalf("Build flags are not as expected")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParsingOfBuildResults(t *testing.T) {
|
func TestParsingOfBuildResults(t *testing.T) {
|
||||||
|
@ -6,7 +6,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
var giteaToken, obsToken string
|
var giteaToken string
|
||||||
|
var obsUser, obsPassword string
|
||||||
|
|
||||||
func RequireGiteaSecretToken() error {
|
func RequireGiteaSecretToken() error {
|
||||||
giteaToken = os.Getenv(GiteaTokenEnv)
|
giteaToken = os.Getenv(GiteaTokenEnv)
|
||||||
@ -23,6 +24,23 @@ func RequireGiteaSecretToken() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func RequireObsSecretToken() error {
|
func RequireObsSecretToken() error {
|
||||||
|
obsPassword = os.Getenv(ObsUserEnv)
|
||||||
|
obsUser = os.Getenv(ObsPasswordEnv)
|
||||||
|
|
||||||
|
if len(obsPassword) < 10 || len(obsUser) < 2 {
|
||||||
|
return fmt.Errorf("Missing OBS authentication: %s %s", ObsUserEnv, ObsPasswordEnv)
|
||||||
|
}
|
||||||
|
|
||||||
|
err := os.Setenv(ObsUserEnv, "")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Cannot reset %s: %v", ObsUserEnv, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.Setenv(ObsPasswordEnv, "")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Cannot reset %s: %v", ObsPasswordEnv, err)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +55,12 @@ func processPullNotification(h *common.RequestHandler, notification *models.Noti
|
|||||||
h.Log(reviewer.UserName)
|
h.Log(reviewer.UserName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
obsClient, err := common.NewObsClient("api.opensuse.org")
|
||||||
|
if err != nil {
|
||||||
|
h.LogPlainError(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
for _, review := range reviews {
|
for _, review := range reviews {
|
||||||
h.Log("state: %s, body: %s, id:%d\n", string(review.State), review.Body, review.ID)
|
h.Log("state: %s, body: %s, id:%d\n", string(review.State), review.Body, review.ID)
|
||||||
|
|
||||||
@ -64,6 +70,7 @@ func processPullNotification(h *common.RequestHandler, notification *models.Noti
|
|||||||
|
|
||||||
switch review.State {
|
switch review.State {
|
||||||
case common.ReviewStateUnknown, common.ReviewStateRequestReview:
|
case common.ReviewStateUnknown, common.ReviewStateRequestReview:
|
||||||
|
// create build project, if doesn't exist, and add it to pending requests
|
||||||
case common.ReviewStatePending:
|
case common.ReviewStatePending:
|
||||||
// waiting for build results
|
// waiting for build results
|
||||||
case common.ReviewStateApproved:
|
case common.ReviewStateApproved:
|
||||||
@ -109,13 +116,6 @@ func main() {
|
|||||||
|
|
||||||
pollWorkNotifications()
|
pollWorkNotifications()
|
||||||
|
|
||||||
c, _ := common.NewObsClient("api.opensuse.org", "autogits_obs_staging_bot", "?E3N9']$YaC9~uR1")
|
|
||||||
status, err := c.BuildStatus("home:adamm")
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("err: %v\n", err)
|
|
||||||
} else {
|
|
||||||
log.Print(*status)
|
|
||||||
}
|
|
||||||
|
|
||||||
stuck := make(chan int)
|
stuck := make(chan int)
|
||||||
<-stuck
|
<-stuck
|
||||||
|
Loading…
Reference in New Issue
Block a user