localrun: use userid and pass it to webhook

This commit is contained in:
Simone Gotti 2019-04-03 14:59:24 +02:00
parent 2d68be8a30
commit 2548598bb8
2 changed files with 20 additions and 2 deletions

View File

@ -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
}

View File

@ -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
}