.
This commit is contained in:
parent
8db4d8c302
commit
6d650d68b1
@ -1,10 +1,12 @@
|
||||
package common;
|
||||
package common
|
||||
|
||||
const (
|
||||
GiteaTokenEnv = "GITEA_TOKEN"
|
||||
DefaultGitPrj = "_ObsPrj"
|
||||
GiteaRequestHeader = "X-Gitea-Event-Type"
|
||||
GiteaTokenEnv = "GITEA_TOKEN"
|
||||
ObsUserEnv = "OBS_USER"
|
||||
ObsPasswordEnv = "OBS_PW"
|
||||
|
||||
DefaultGitPrj = "_ObsPrj"
|
||||
GiteaRequestHeader = "X-Gitea-Event-Type"
|
||||
|
||||
Bot_BuildReview = "autogits_obs_staging_bot"
|
||||
)
|
||||
|
||||
|
@ -16,7 +16,7 @@ type ObsClient struct {
|
||||
cookie string
|
||||
}
|
||||
|
||||
func NewObsClient(host, username, password string) (*ObsClient, error) {
|
||||
func NewObsClient(host string) (*ObsClient, error) {
|
||||
baseUrl, err := url.Parse("https://" + host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -25,8 +25,8 @@ func NewObsClient(host, username, password string) (*ObsClient, error) {
|
||||
return &ObsClient{
|
||||
baseUrl: baseUrl,
|
||||
client: &http.Client{},
|
||||
user: username,
|
||||
password: password,
|
||||
user: obsUser,
|
||||
password: obsPassword,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -40,6 +40,10 @@ type RepositoryMeta struct {
|
||||
}
|
||||
}
|
||||
|
||||
type Flags struct {
|
||||
Contents string `xml:",innerxml"`
|
||||
}
|
||||
|
||||
type ProjectMeta struct {
|
||||
XMLName xml.Name `xml:"project"`
|
||||
Name string `xml:"name,attr"`
|
||||
@ -47,6 +51,9 @@ type ProjectMeta struct {
|
||||
Description string `xml:"description"`
|
||||
ScmSync string `xml:"xmlsync"`
|
||||
Repositories []Repository `xml:"repository"`
|
||||
|
||||
BuildFlags Flags `xml:"build"`
|
||||
PublicFlags Flags `xml:"publish"`
|
||||
}
|
||||
|
||||
func parseProjectMeta(data []byte) (*ProjectMeta, error) {
|
||||
|
@ -8,10 +8,12 @@ func TestParseProjectMeta(t *testing.T) {
|
||||
res, err := parseProjectMeta([]byte(metaPrjData))
|
||||
|
||||
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) {
|
||||
@ -29,7 +31,7 @@ func TestParsingOfBuildResults(t *testing.T) {
|
||||
}
|
||||
|
||||
if res.Result[0].Binaries[0].Package != "Nudoku" ||
|
||||
len(res.Result[0].Binaries[0].Binary) != 0 {
|
||||
len(res.Result[0].Binaries[0].Binary) != 0 {
|
||||
|
||||
t.Fatal(res.Result[0].Binaries[0])
|
||||
}
|
||||
|
@ -6,7 +6,8 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
var giteaToken, obsToken string
|
||||
var giteaToken string
|
||||
var obsUser, obsPassword string
|
||||
|
||||
func RequireGiteaSecretToken() error {
|
||||
giteaToken = os.Getenv(GiteaTokenEnv)
|
||||
@ -23,6 +24,23 @@ func RequireGiteaSecretToken() 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
|
||||
}
|
||||
|
||||
|
@ -55,6 +55,12 @@ func processPullNotification(h *common.RequestHandler, notification *models.Noti
|
||||
h.Log(reviewer.UserName)
|
||||
}
|
||||
|
||||
obsClient, err := common.NewObsClient("api.opensuse.org")
|
||||
if err != nil {
|
||||
h.LogPlainError(err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, review := range reviews {
|
||||
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 {
|
||||
case common.ReviewStateUnknown, common.ReviewStateRequestReview:
|
||||
// create build project, if doesn't exist, and add it to pending requests
|
||||
case common.ReviewStatePending:
|
||||
// waiting for build results
|
||||
case common.ReviewStateApproved:
|
||||
@ -109,13 +116,6 @@ func main() {
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user