localrun: use userid and pass it to webhook
This commit is contained in:
parent
2d68be8a30
commit
2548598bb8
@ -15,7 +15,11 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
gitsave "github.com/sorintlab/agola/internal/git-save"
|
gitsave "github.com/sorintlab/agola/internal/git-save"
|
||||||
|
"github.com/sorintlab/agola/internal/services/gateway/api"
|
||||||
|
|
||||||
uuid "github.com/satori/go.uuid"
|
uuid "github.com/satori/go.uuid"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -56,6 +60,13 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func localRunStart(cmd *cobra.Command, args []string) error {
|
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{
|
gs := gitsave.NewGitSave(logger, &gitsave.GitSaveConfig{
|
||||||
AddUntracked: localRunStartOpts.untracked,
|
AddUntracked: localRunStartOpts.untracked,
|
||||||
AddIgnored: localRunStartOpts.ignored,
|
AddIgnored: localRunStartOpts.ignored,
|
||||||
@ -68,7 +79,8 @@ func localRunStart(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("pushing branch")
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,9 +140,15 @@ func (s *GitServer) repoPostCreateFunc(githookPath, gatewayURL string) handlers.
|
|||||||
f.WriteString(githookPath + " $oval $nval $ref\n")
|
f.WriteString(githookPath + " $oval $nval $ref\n")
|
||||||
f.WriteString("done\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 := &util.Git{GitDir: repoAbsPath}
|
||||||
git.ConfigSet(context.Background(), "agola.repo", repoPath)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user