Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions admin/server/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@ import (
"github.com/eapache/go-resiliency/retrier"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing/object"
githttp "github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/google/go-github/v71/github"
"github.com/rilldata/rill/admin"
"github.com/rilldata/rill/admin/database"
"github.com/rilldata/rill/admin/pkg/gitutil"
"github.com/rilldata/rill/admin/pkg/urlutil"
"github.com/rilldata/rill/admin/server/auth"
cligitutil "github.com/rilldata/rill/cli/pkg/gitutil"
adminv1 "github.com/rilldata/rill/proto/gen/rill/admin/v1"
"github.com/rilldata/rill/runtime/pkg/archive"
rtgitutil "github.com/rilldata/rill/runtime/pkg/gitutil"
"github.com/rilldata/rill/runtime/pkg/httputil"
"github.com/rilldata/rill/runtime/pkg/middleware"
"github.com/rilldata/rill/runtime/pkg/observability"
Expand Down Expand Up @@ -421,7 +420,7 @@ func (s *Server) ConnectProjectToGithub(ctx context.Context, req *adminv1.Connec
}

if proj.ArchiveAssetID != nil {
author := &object.Signature{
author := rtgitutil.Signature{
Name: user.GithubUsername,
Email: user.Email,
}
Expand Down Expand Up @@ -1207,7 +1206,7 @@ func (s *Server) createRepo(ctx context.Context, remote, branch string, user *da
return token, nil
}

func (s *Server) pushAssetToGit(ctx context.Context, assetID, remote, branch, token string, author *object.Signature) error {
func (s *Server) pushAssetToGit(ctx context.Context, assetID, remote, branch, token string, author rtgitutil.Signature) error {
asset, err := s.admin.DB.FindAsset(ctx, assetID)
if err != nil {
return err
Expand All @@ -1230,13 +1229,13 @@ func (s *Server) pushAssetToGit(ctx context.Context, assetID, remote, branch, to
return err
}

config := &cligitutil.Config{
config := &rtgitutil.Config{
Remote: remote,
Username: "x-access-token",
Password: token,
DefaultBranch: branch,
}
return cligitutil.CommitAndPush(ctx, projPath, config, "", author)
return rtgitutil.CommitAndPush(ctx, projPath, config, "", author)
}

func (s *Server) githubAppInstallationURL(state githubConnectState) (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion admin/testadmin/testadmin.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import (
"github.com/rilldata/rill/admin/jobs/river"
"github.com/rilldata/rill/admin/pkg/pgtestcontainer"
"github.com/rilldata/rill/admin/server"
"github.com/rilldata/rill/cli/pkg/gitutil"
"github.com/rilldata/rill/cli/pkg/version"
"github.com/rilldata/rill/runtime"
"github.com/rilldata/rill/runtime/drivers"
"github.com/rilldata/rill/runtime/pkg/activity"
"github.com/rilldata/rill/runtime/pkg/email"
"github.com/rilldata/rill/runtime/pkg/gitutil"
"github.com/rilldata/rill/runtime/pkg/ratelimit"
runtimeserver "github.com/rilldata/rill/runtime/server"
runtimeauth "github.com/rilldata/rill/runtime/server/auth"
Expand Down
9 changes: 3 additions & 6 deletions cli/cmd/deploy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import (
"testing"
"time"

"github.com/go-git/go-git/v5/plumbing/object"
"github.com/google/go-github/v71/github"
"github.com/google/uuid"
"github.com/rilldata/rill/admin/client"
"github.com/rilldata/rill/admin/database"
"github.com/rilldata/rill/admin/testadmin"
"github.com/rilldata/rill/cli/pkg/gitutil"
"github.com/rilldata/rill/cli/testcli"
adminv1 "github.com/rilldata/rill/proto/gen/rill/admin/v1"
"github.com/rilldata/rill/runtime/pkg/gitutil"
"github.com/rilldata/rill/runtime/testruntime/testmode"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -194,10 +193,9 @@ func testSelfHostedDeploy(t *testing.T, adminClient *client.Client, ghClient *gi
// the create repo API does not wait for repo creation to be fully processed; poll until ready
waitForGithubRepo(t, ghClient, *repo.Owner.Login, repoName)

author := &object.Signature{
author := gitutil.Signature{
Name: "Rill test user",
Email: "test.user@rilldata.com",
When: time.Now(),
}
authCloneURL := authGitURL(t, *repo.CloneURL, token)
err = gitutil.CommitAndPush(t.Context(), tempDir, &gitutil.Config{
Expand Down Expand Up @@ -268,10 +266,9 @@ func testSelfHostedMonorepoDeploy(t *testing.T, adminClient *client.Client, ghCl
// the create repo API does not wait for repo creation to be fully processed; poll until ready
waitForGithubRepo(t, ghClient, *repo.Owner.Login, repoName)

author := &object.Signature{
author := gitutil.Signature{
Name: "Rill test user",
Email: "test.user@rilldata.com",
When: time.Now(),
}
err = gitutil.CommitAndPush(t.Context(), tempDir, &gitutil.Config{
Remote: authGitURL(t, *repo.CloneURL, token),
Expand Down
6 changes: 2 additions & 4 deletions cli/cmd/devtool/seed.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"fmt"
"os"

"github.com/go-git/go-git/v5"
"github.com/rilldata/rill/cli/cmd/project"
"github.com/rilldata/rill/cli/pkg/cmdutil"
adminv1 "github.com/rilldata/rill/proto/gen/rill/admin/v1"
"github.com/rilldata/rill/runtime/pkg/gitutil"
"github.com/spf13/cobra"
)

Expand All @@ -28,9 +28,7 @@ func SeedCmd(ch *cmdutil.Helper) *cobra.Command {
return err
}
defer os.RemoveAll(temp)
_, err = git.PlainClone(temp, false, &git.CloneOptions{
URL: "https://github.com/rilldata/rill-examples.git",
})
err = gitutil.Clone(cmd.Context(), temp, "https://github.com/rilldata/rill-examples.git", "", false, false)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/devtool/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/joho/godotenv"
"github.com/redis/go-redis/v9"
"github.com/rilldata/rill/cli/pkg/cmdutil"
"github.com/rilldata/rill/cli/pkg/gitutil"
"github.com/rilldata/rill/runtime/pkg/gitutil"
"github.com/rilldata/rill/runtime/pkg/graceful"
"github.com/rilldata/rill/runtime/pkg/observability"
"github.com/spf13/cobra"
Expand Down
29 changes: 6 additions & 23 deletions cli/cmd/project/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

"github.com/rilldata/rill/cli/cmd/env"
"github.com/rilldata/rill/cli/pkg/cmdutil"
"github.com/rilldata/rill/cli/pkg/gitutil"
adminv1 "github.com/rilldata/rill/proto/gen/rill/admin/v1"
"github.com/rilldata/rill/runtime/pkg/gitutil"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -56,10 +56,10 @@ func CloneCmd(ch *cmdutil.Helper) *cobra.Command {
}
}

// create directory, the go-git SDK does not create the directory
err = recreateDir(path)
if err != nil {
return fmt.Errorf("failed to create directory %q: %w", path, err)
// clear any existing contents so git clone can populate the directory
// (git clone creates the target directory itself, but refuses to clone into a non-empty one)
if err := os.RemoveAll(path); err != nil {
return fmt.Errorf("failed to remove directory %q: %w", path, err)
}

// get config
Expand All @@ -69,7 +69,7 @@ func CloneCmd(ch *cmdutil.Helper) *cobra.Command {
}

// clone repository
_, err = gitutil.Clone(cmd.Context(), path, config)
err = gitutil.CloneWithConfig(cmd.Context(), path, config)
if err != nil {
return err
}
Expand Down Expand Up @@ -123,20 +123,3 @@ func isDirAbsentOrEmpty(path string) (bool, error) {
// Check if the directory is empty
return len(entries) == 0, nil
}

func recreateDir(path string) error {
// Remove directory and its contents if exists
err := os.RemoveAll(path)
if err != nil {
// NOTE: does not return an error if the directory does not exist
return fmt.Errorf("failed to remove dir: %w", err)
}

// Create the directory again
err = os.MkdirAll(path, os.ModePerm)
if err != nil {
return fmt.Errorf("failed to create dir: %w", err)
}

return nil
}
8 changes: 4 additions & 4 deletions cli/cmd/project/connect_github.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
"github.com/rilldata/rill/cli/cmd/org"
"github.com/rilldata/rill/cli/pkg/browser"
"github.com/rilldata/rill/cli/pkg/cmdutil"
"github.com/rilldata/rill/cli/pkg/gitutil"
"github.com/rilldata/rill/cli/pkg/local"
"github.com/rilldata/rill/cli/pkg/printer"
adminv1 "github.com/rilldata/rill/proto/gen/rill/admin/v1"
"github.com/rilldata/rill/runtime/pkg/activity"
"github.com/rilldata/rill/runtime/pkg/gitutil"
"github.com/spf13/cobra"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -120,7 +120,7 @@ func ConnectGithubFlow(ctx context.Context, ch *cmdutil.Helper, opts *DeployOpts
}

// Error if the repository is not in sync with the remote
ok, err := repoInSyncFlow(ch, localGitPath, opts.SubPath, opts.RemoteName)
ok, err := repoInSyncFlow(ctx, ch, localGitPath, opts.SubPath, opts.RemoteName)
if err != nil {
return err
}
Expand Down Expand Up @@ -513,8 +513,8 @@ func createProjectFlow(ctx context.Context, ch *cmdutil.Helper, req *adminv1.Cre
return res, err
}

func repoInSyncFlow(ch *cmdutil.Helper, gitPath, subpath, remoteName string) (bool, error) {
st, err := gitutil.RunGitStatus(gitPath, subpath, remoteName, "")
func repoInSyncFlow(ctx context.Context, ch *cmdutil.Helper, gitPath, subpath, remoteName string) (bool, error) {
st, err := gitutil.Status(ctx, gitPath, subpath, remoteName, "")
if err != nil {
return false, err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/project/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"github.com/rilldata/rill/cli/cmd/org"
"github.com/rilldata/rill/cli/pkg/browser"
"github.com/rilldata/rill/cli/pkg/cmdutil"
"github.com/rilldata/rill/cli/pkg/gitutil"
"github.com/rilldata/rill/cli/pkg/local"
"github.com/rilldata/rill/cli/pkg/printer"
adminv1 "github.com/rilldata/rill/proto/gen/rill/admin/v1"
"github.com/rilldata/rill/runtime/pkg/activity"
"github.com/rilldata/rill/runtime/pkg/fileutil"
"github.com/rilldata/rill/runtime/pkg/gitutil"
"github.com/spf13/cobra"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/project/deployment/deployments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (

"github.com/google/go-github/v71/github"
"github.com/rilldata/rill/admin/testadmin"
"github.com/rilldata/rill/cli/pkg/gitutil"
"github.com/rilldata/rill/cli/testcli"
adminv1 "github.com/rilldata/rill/proto/gen/rill/admin/v1"
"github.com/rilldata/rill/runtime/drivers"
"github.com/rilldata/rill/runtime/pkg/gitutil"
"github.com/rilldata/rill/runtime/testruntime/testmode"
"github.com/stretchr/testify/require"
)
Expand Down
9 changes: 5 additions & 4 deletions cli/cmd/start/start.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package start

import (
"context"
"fmt"
"os"
"path/filepath"
Expand All @@ -9,8 +10,8 @@ import (
"github.com/joho/godotenv"
"github.com/rilldata/rill/cli/pkg/cmdutil"
"github.com/rilldata/rill/cli/pkg/envdetect"
"github.com/rilldata/rill/cli/pkg/gitutil"
"github.com/rilldata/rill/cli/pkg/local"
"github.com/rilldata/rill/runtime/pkg/gitutil"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -41,7 +42,7 @@ func StartCmd(ch *cmdutil.Helper) *cobra.Command {
var projectPath string
if len(args) > 0 {
var err error
projectPath, err = ResolveProjectPath(args[0])
projectPath, err = ResolveProjectPath(cmd.Context(), args[0])
if err != nil {
return err
}
Expand Down Expand Up @@ -198,9 +199,9 @@ func StartCmd(ch *cmdutil.Helper) *cobra.Command {
return startCmd
}

func ResolveProjectPath(path string) (string, error) {
func ResolveProjectPath(ctx context.Context, path string) (string, error) {
if strings.HasSuffix(path, ".git") {
repoName, err := gitutil.CloneRepo(path)
repoName, err := gitutil.CloneRepo(ctx, path)
if err != nil {
return "", fmt.Errorf("clone repo error: %w", err)
}
Expand Down
12 changes: 7 additions & 5 deletions cli/cmd/sudo/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package sudo
import (
"fmt"

"github.com/go-git/go-git/v5/plumbing/transport"
"github.com/rilldata/rill/cli/pkg/cmdutil"
adminv1 "github.com/rilldata/rill/proto/gen/rill/admin/v1"
"github.com/rilldata/rill/runtime/pkg/gitutil"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -37,13 +37,15 @@ func cloneCmd(ch *cmdutil.Helper) *cobra.Command {
return nil
}

ep, err := transport.NewEndpoint(res.GitRepoUrl)
config := &gitutil.Config{
Remote: res.GitRepoUrl,
Username: res.GitUsername,
Password: res.GitPassword,
}
cloneURL, err := config.FullyQualifiedRemote()
if err != nil {
return err
}
ep.User = res.GitUsername
ep.Password = res.GitPassword
cloneURL := ep.String()

fmt.Printf("\tgit clone %s\n\n", cloneURL)
fmt.Println("Full details:")
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func ValidateCmd(ch *cmdutil.Helper) *cobra.Command {
var projectPath string
if len(args) > 0 {
var err error
projectPath, err = start.ResolveProjectPath(args[0])
projectPath, err = start.ResolveProjectPath(cmd.Context(), args[0])
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/pkg/cmdutil/githelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"slices"
"strings"

"github.com/rilldata/rill/cli/pkg/gitutil"
adminv1 "github.com/rilldata/rill/proto/gen/rill/admin/v1"
"github.com/rilldata/rill/runtime/drivers"
"github.com/rilldata/rill/runtime/pkg/gitutil"
"golang.org/x/sync/semaphore"
)

Expand Down
Loading
Loading