From 2548598bb8522e2cc2cb2c0e0fe774ac98f88c47 Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Wed, 3 Apr 2019 14:59:24 +0200 Subject: [PATCH] localrun: use userid and pass it to webhook --- cmd/agola/cmd/localrunstart.go | 14 +++++++++++++- internal/services/gitserver/main.go | 8 +++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/cmd/agola/cmd/localrunstart.go b/cmd/agola/cmd/localrunstart.go index 4f52fd6..95c38f6 100644 --- a/cmd/agola/cmd/localrunstart.go +++ b/cmd/agola/cmd/localrunstart.go @@ -15,7 +15,11 @@ package cmd import ( + "context" + "fmt" + gitsave "github.com/sorintlab/agola/internal/git-save" + "github.com/sorintlab/agola/internal/services/gateway/api" uuid "github.com/satori/go.uuid" "github.com/spf13/cobra" @@ -56,6 +60,13 @@ func init() { } func localRunStart(cmd *cobra.Command, args []string) error { + gwclient := api.NewClient(gatewayURL, token) + + user, _, err := gwclient.GetCurrentUser(context.TODO()) + if err != nil { + log.Fatalf("err: %v", err) + } + gs := gitsave.NewGitSave(logger, &gitsave.GitSaveConfig{ AddUntracked: localRunStartOpts.untracked, AddIgnored: localRunStartOpts.ignored, @@ -68,7 +79,8 @@ func localRunStart(cmd *cobra.Command, args []string) error { } log.Infof("pushing branch") - if err := gitsave.GitPush("", "http://172.17.0.1:8000/repos/sgotti/test02.git", "refs/gitsave/"+branch); err != nil { + repoURL := fmt.Sprintf("%s/repos/%s/test.git", gatewayURL, user.ID) + if err := gitsave.GitPush("", repoURL, "refs/gitsave/"+branch); err != nil { return err } diff --git a/internal/services/gitserver/main.go b/internal/services/gitserver/main.go index fe36a05..368e6f2 100644 --- a/internal/services/gitserver/main.go +++ b/internal/services/gitserver/main.go @@ -140,9 +140,15 @@ func (s *GitServer) repoPostCreateFunc(githookPath, gatewayURL string) handlers. f.WriteString(githookPath + " $oval $nval $ref\n") f.WriteString("done\n") + parts := strings.Split(string(repoPath), "/") + if len(parts) != 2 { + return errors.Errorf("wrong repo path: %q", repoPath) + } + userID := parts[0] + git := &util.Git{GitDir: repoAbsPath} git.ConfigSet(context.Background(), "agola.repo", repoPath) - git.ConfigSet(context.Background(), "agola.webhookURL", gatewayURL+"/webhooks") + git.ConfigSet(context.Background(), "agola.webhookURL", gatewayURL+"/webhooks?userid="+userID) return nil }