Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cf0a7d7

Browse files
committed
Merge branch 'main' into gplata/model-tests
2 parents 6f9a1fa + 964b95a commit cf0a7d7

File tree

263 files changed

+8560
-6682
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

263 files changed

+8560
-6682
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ docs.generate:
4343
rm -rf docs/docs/reference/cli docs/docs/reference/yaml
4444
if [ -f ~/.rill/config.yaml ]; then mv ~/.rill/config.yaml ~/.rill/config.yaml.tmp; fi;
4545
go run -ldflags="-X main.Version=$(shell git describe --tags `git rev-list --tags --max-count=1`)" ./cli docs generate-cli docs/docs/reference/cli/
46-
go run -ldflags="-X main.Version=$(shell git describe --tags `git rev-list --tags --max-count=1`)" ./cli docs generate-project docs/docs/reference/yaml
46+
go run -ldflags="-X main.Version=$(shell git describe --tags `git rev-list --tags --max-count=1`)" ./cli docs generate-project docs/docs/hidden/yaml
4747
if [ -f ~/.rill/config.yaml.tmp ]; then mv ~/.rill/config.yaml.tmp ~/.rill/config.yaml; fi;
4848

4949
.PHONY: proto.generate

admin/admin.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/rilldata/rill/admin/database"
1313
"github.com/rilldata/rill/admin/jobs"
1414
"github.com/rilldata/rill/admin/provisioner"
15+
"github.com/rilldata/rill/cli/pkg/version"
1516
"github.com/rilldata/rill/runtime/pkg/email"
1617
"github.com/rilldata/rill/runtime/server/auth"
1718
"go.uber.org/zap"
@@ -26,8 +27,7 @@ type Options struct {
2627
ProvisionerSetJSON string
2728
ProvisionerMaxConcurrency int
2829
DefaultProvisioner string
29-
VersionNumber string
30-
VersionCommit string
30+
Version version.Version
3131
MetricsProjectOrg string
3232
MetricsProjectName string
3333
AutoscalerCron string
@@ -48,8 +48,7 @@ type Service struct {
4848
Logger *zap.Logger
4949
opts *Options
5050
issuer *auth.Issuer
51-
VersionNumber string
52-
VersionCommit string
51+
Version version.Version
5352
MetricsProjectID string
5453
AutoscalerCron string
5554
ScaleDownConstraint int
@@ -126,8 +125,7 @@ func New(ctx context.Context, opts *Options, logger *zap.Logger, issuer *auth.Is
126125
Logger: logger,
127126
opts: opts,
128127
issuer: issuer,
129-
VersionNumber: opts.VersionNumber,
130-
VersionCommit: opts.VersionCommit,
128+
Version: opts.Version,
131129
MetricsProjectID: metricsProjectID,
132130
AutoscalerCron: opts.AutoscalerCron,
133131
ScaleDownConstraint: opts.ScaleDownConstraint,

admin/database/database.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ type DB interface {
8181
// FindProjectsForOrgAndUser lists the public projects in the org and the projects where user is added as an external user
8282
FindProjectsForOrgAndUser(ctx context.Context, orgID, userID string, includePublic bool, afterProjectName string, limit int) ([]*Project, error)
8383
FindPublicProjectsInOrganization(ctx context.Context, orgID, afterProjectName string, limit int) ([]*Project, error)
84-
FindProjectsByGithubURL(ctx context.Context, githubURL string) ([]*Project, error)
84+
FindProjectsByGitRemote(ctx context.Context, remote string) ([]*Project, error)
8585
FindProjectsByGithubInstallationID(ctx context.Context, id int64) ([]*Project, error)
8686
FindProject(ctx context.Context, id string) (*Project, error)
8787
FindProjectByName(ctx context.Context, orgName string, name string) (*Project, error)
@@ -413,7 +413,7 @@ type Project struct {
413413
// ArchiveAssetID is set when project files are managed by Rill instead of maintained in Git.
414414
// If ArchiveAssetID is set all git related fields will be empty.
415415
ArchiveAssetID *string `db:"archive_asset_id"`
416-
GithubURL *string `db:"github_url"`
416+
GitRemote *string `db:"git_remote"`
417417
GithubInstallationID *int64 `db:"github_installation_id"`
418418
GithubRepoID *int64 `db:"github_repo_id"`
419419
ManagedGitRepoID *string `db:"managed_git_repo_id"`
@@ -441,7 +441,7 @@ type InsertProjectOptions struct {
441441
CreatedByUserID *string
442442
Provisioner string
443443
ArchiveAssetID *string
444-
GithubURL *string `validate:"omitempty,http_url"`
444+
GitRemote *string `validate:"omitempty,http_url,endswith=.git"`
445445
GithubInstallationID *int64 `validate:"omitempty,ne=0"`
446446
GithubRepoID *int64
447447
ManagedGitRepoID *string
@@ -461,7 +461,7 @@ type UpdateProjectOptions struct {
461461
Public bool
462462
Provisioner string
463463
ArchiveAssetID *string
464-
GithubURL *string `validate:"omitempty,http_url"`
464+
GitRemote *string `validate:"omitempty,http_url,endswith=.git"`
465465
GithubInstallationID *int64 `validate:"omitempty,ne=0"`
466466
GithubRepoID *int64
467467
ManagedGitRepoID *string
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- Rename projects.github_url to projects.git_remote
2+
ALTER TABLE projects RENAME COLUMN github_url TO git_remote;
3+
4+
-- Repeat migration 0070.sql to compensate for bug.
5+
UPDATE projects
6+
SET git_remote = concat(git_remote, '.git')
7+
WHERE git_remote IS NOT NULL
8+
AND git_remote NOT LIKE '%.git';

admin/database/postgres/postgres.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,9 @@ func (c *connection) FindPublicProjectsInOrganization(ctx context.Context, orgID
329329
return c.projectsFromDTOs(res)
330330
}
331331

332-
func (c *connection) FindProjectsByGithubURL(ctx context.Context, githubURL string) ([]*database.Project, error) {
332+
func (c *connection) FindProjectsByGitRemote(ctx context.Context, remote string) ([]*database.Project, error) {
333333
var res []*projectDTO
334-
err := c.getDB(ctx).SelectContext(ctx, &res, "SELECT p.* FROM projects p WHERE lower(p.github_url)=lower($1) ", githubURL)
334+
err := c.getDB(ctx).SelectContext(ctx, &res, "SELECT p.* FROM projects p WHERE lower(p.git_remote)=lower($1)", remote)
335335
if err != nil {
336336
return nil, parseErr("projects", err)
337337
}
@@ -388,9 +388,9 @@ func (c *connection) InsertProject(ctx context.Context, opts *database.InsertPro
388388

389389
res := &projectDTO{}
390390
err := c.getDB(ctx).QueryRowxContext(ctx, `
391-
INSERT INTO projects (org_id, name, description, public, created_by_user_id, provisioner, prod_olap_driver, prod_olap_dsn, prod_slots, subpath, prod_branch, archive_asset_id, github_url, github_installation_id, github_repo_id, managed_git_repo_id, prod_ttl_seconds, prod_version)
391+
INSERT INTO projects (org_id, name, description, public, created_by_user_id, provisioner, prod_olap_driver, prod_olap_dsn, prod_slots, subpath, prod_branch, archive_asset_id, git_remote, github_installation_id, github_repo_id, managed_git_repo_id, prod_ttl_seconds, prod_version)
392392
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18) RETURNING *`,
393-
opts.OrganizationID, opts.Name, opts.Description, opts.Public, opts.CreatedByUserID, opts.Provisioner, opts.ProdOLAPDriver, opts.ProdOLAPDSN, opts.ProdSlots, opts.Subpath, opts.ProdBranch, opts.ArchiveAssetID, opts.GithubURL, opts.GithubInstallationID, opts.GithubRepoID, opts.ManagedGitRepoID, opts.ProdTTLSeconds, opts.ProdVersion,
393+
opts.OrganizationID, opts.Name, opts.Description, opts.Public, opts.CreatedByUserID, opts.Provisioner, opts.ProdOLAPDriver, opts.ProdOLAPDSN, opts.ProdSlots, opts.Subpath, opts.ProdBranch, opts.ArchiveAssetID, opts.GitRemote, opts.GithubInstallationID, opts.GithubRepoID, opts.ManagedGitRepoID, opts.ProdTTLSeconds, opts.ProdVersion,
394394
).StructScan(res)
395395
if err != nil {
396396
return nil, parseErr("project", err)
@@ -413,9 +413,9 @@ func (c *connection) UpdateProject(ctx context.Context, id string, opts *databas
413413

414414
res := &projectDTO{}
415415
err := c.getDB(ctx).QueryRowxContext(ctx, `
416-
UPDATE projects SET name=$1, description=$2, public=$3, prod_branch=$4, github_url=$5, github_installation_id=$6, github_repo_id=$7, managed_git_repo_id=$8, archive_asset_id=$9, prod_deployment_id=$10, provisioner=$11, prod_slots=$12, subpath=$13, prod_ttl_seconds=$14, annotations=$15, prod_version=$16, updated_on=now()
416+
UPDATE projects SET name=$1, description=$2, public=$3, prod_branch=$4, git_remote=$5, github_installation_id=$6, github_repo_id=$7, managed_git_repo_id=$8, archive_asset_id=$9, prod_deployment_id=$10, provisioner=$11, prod_slots=$12, subpath=$13, prod_ttl_seconds=$14, annotations=$15, prod_version=$16, updated_on=now()
417417
WHERE id=$17 RETURNING *`,
418-
opts.Name, opts.Description, opts.Public, opts.ProdBranch, opts.GithubURL, opts.GithubInstallationID, opts.GithubRepoID, opts.ManagedGitRepoID, opts.ArchiveAssetID, opts.ProdDeploymentID, opts.Provisioner, opts.ProdSlots, opts.Subpath, opts.ProdTTLSeconds, opts.Annotations, opts.ProdVersion, id,
418+
opts.Name, opts.Description, opts.Public, opts.ProdBranch, opts.GitRemote, opts.GithubInstallationID, opts.GithubRepoID, opts.ManagedGitRepoID, opts.ArchiveAssetID, opts.ProdDeploymentID, opts.Provisioner, opts.ProdSlots, opts.Subpath, opts.ProdTTLSeconds, opts.Annotations, opts.ProdVersion, id,
419419
).StructScan(res)
420420
if err != nil {
421421
return nil, parseErr("project", err)

admin/deployments.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -567,11 +567,11 @@ func (s *Service) findProvisionedRuntimeResource(ctx context.Context, deployment
567567
}
568568

569569
func (s *Service) resolveRillVersion() string {
570-
if s.VersionNumber != "" {
571-
return s.VersionNumber
570+
if s.Version.Number != "" {
571+
return s.Version.Number
572572
}
573-
if s.VersionCommit != "" {
574-
return s.VersionCommit
573+
if s.Version.Commit != "" {
574+
return s.Version.Commit
575575
}
576576
return "latest"
577577
}

admin/github.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,12 @@ func (s *Service) CreateManagedGitRepo(ctx context.Context, org *database.Organi
218218
return repo, nil
219219
}
220220

221-
// GetGithubInstallation returns a non zero Github installation ID if the Github App is installed on the repository
222-
// and is not in suspended state
223-
// The githubURL should be a HTTPS URL for a Github repository without the .git suffix.
224-
func (s *Service) GetGithubInstallation(ctx context.Context, githubURL string) (int64, error) {
225-
account, repo, ok := gitutil.SplitGithubURL(githubURL)
221+
// GetGithubInstallation returns a non zero Github installation ID if the Github App is installed on the repository and is not in suspended state.
222+
// The remote should be a HTTPS URL for a github.com repository with the .git suffix.
223+
func (s *Service) GetGithubInstallation(ctx context.Context, remote string) (int64, error) {
224+
account, repo, ok := gitutil.SplitGithubRemote(remote)
226225
if !ok {
227-
return 0, fmt.Errorf("invalid Github URL %q", githubURL)
226+
return 0, fmt.Errorf("invalid Github remote %q", remote)
228227
}
229228

230229
installation, resp, err := s.Github.AppClient().Apps.FindRepositoryInstallation(ctx, account, repo)
@@ -251,11 +250,11 @@ func (s *Service) GetGithubInstallation(ctx context.Context, githubURL string) (
251250
}
252251

253252
// LookupGithubRepoForUser returns a Github repository iff the Github App is installed on the repository and user is a collaborator of the project.
254-
// The githubURL should be a HTTPS URL for a Github repository without the .git suffix.
255-
func (s *Service) LookupGithubRepoForUser(ctx context.Context, installationID int64, githubURL, gitUsername string) (*github.Repository, error) {
256-
account, repo, ok := gitutil.SplitGithubURL(githubURL)
253+
// The remote should be a HTTPS URL for a github.com repository with the .git suffix.
254+
func (s *Service) LookupGithubRepoForUser(ctx context.Context, installationID int64, remote, gitUsername string) (*github.Repository, error) {
255+
account, repo, ok := gitutil.SplitGithubRemote(remote)
257256
if !ok {
258-
return nil, fmt.Errorf("invalid Github URL %q", githubURL)
257+
return nil, fmt.Errorf("invalid Github remote %q", remote)
259258
}
260259

261260
if gitUsername == "" {
@@ -305,7 +304,7 @@ func (s *Service) ProcessGithubEvent(ctx context.Context, rawEvent any) error {
305304
func (s *Service) processGithubPush(ctx context.Context, event *github.PushEvent) error {
306305
// Find Rill project matching the repo that was pushed to
307306
repo := event.GetRepo()
308-
projects, err := s.DB.FindProjectsByGithubURL(ctx, *repo.CloneURL)
307+
projects, err := s.DB.FindProjectsByGitRemote(ctx, *repo.CloneURL)
309308
if err != nil {
310309
if errors.Is(err, database.ErrNotFound) {
311310
// App is installed on repo not currently deployed. Do nothing.

admin/jobs/river/delete_unused_github_repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (w *deleteUnusedGithubReposWorker) deleteUnusedGithubRepos(ctx context.Cont
5656
repo := repo
5757
ids = append(ids, repo.ID)
5858
group.Go(func() error {
59-
account, name, ok := gitutil.SplitGithubURL(repo.Remote)
59+
account, name, ok := gitutil.SplitGithubRemote(repo.Remote)
6060
if !ok {
6161
w.logger.Error("invalid github url", zap.String("remote", repo.Remote), zap.String("repo_id", repo.ID))
6262
}

admin/pkg/gitutil/gitutil.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"github.com/go-git/go-git/v5/plumbing/transport"
88
)
99

10-
func SplitGithubURL(githubURL string) (account, repo string, ok bool) {
11-
githubURL = strings.TrimSuffix(githubURL, ".git")
12-
ep, err := transport.NewEndpoint(githubURL)
10+
// SplitGithubRemote takes a GitHub HTTPS remote URL and extracts the Github account and repository name.
11+
func SplitGithubRemote(remote string) (account, repo string, ok bool) {
12+
ep, err := transport.NewEndpoint(remote)
1313
if err != nil {
1414
return "", "", false
1515
}
@@ -20,6 +20,7 @@ func SplitGithubURL(githubURL string) (account, repo string, ok bool) {
2020

2121
account, repo = path.Split(ep.Path)
2222
account = strings.Trim(account, "/")
23+
repo = strings.TrimSuffix(repo, ".git")
2324
if account == "" || repo == "" || strings.Contains(account, "/") {
2425
return "", "", false
2526
}

admin/projects.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (s *Service) CreateProject(ctx context.Context, org *database.Organization,
8484

8585
// Check if the project has an archive or git info
8686
hasArchive := opts.ArchiveAssetID != nil
87-
hasGitInfo := opts.GithubURL != nil && opts.GithubInstallationID != nil && opts.ProdBranch != ""
87+
hasGitInfo := opts.GitRemote != nil && opts.GithubInstallationID != nil && opts.ProdBranch != ""
8888
if !hasArchive && !hasGitInfo {
8989
return nil, fmt.Errorf("failed to deploy project: either an archive or git info must be provided")
9090
}
@@ -112,7 +112,7 @@ func (s *Service) CreateProject(ctx context.Context, org *database.Organization,
112112
Description: proj.Description,
113113
Public: proj.Public,
114114
ArchiveAssetID: proj.ArchiveAssetID,
115-
GithubURL: proj.GithubURL,
115+
GitRemote: proj.GitRemote,
116116
GithubInstallationID: proj.GithubInstallationID,
117117
GithubRepoID: proj.GithubRepoID,
118118
ManagedGitRepoID: proj.ManagedGitRepoID,
@@ -164,7 +164,7 @@ func (s *Service) UpdateProject(ctx context.Context, proj *database.Project, opt
164164
(proj.Subpath != opts.Subpath) ||
165165
(proj.ProdBranch != opts.ProdBranch) ||
166166
!reflect.DeepEqual(proj.Annotations, opts.Annotations) ||
167-
!reflect.DeepEqual(proj.GithubURL, opts.GithubURL) ||
167+
!reflect.DeepEqual(proj.GitRemote, opts.GitRemote) ||
168168
!reflect.DeepEqual(proj.GithubInstallationID, opts.GithubInstallationID) ||
169169
!reflect.DeepEqual(proj.ArchiveAssetID, opts.ArchiveAssetID)
170170

@@ -347,7 +347,7 @@ func (s *Service) RedeployProject(ctx context.Context, proj *database.Project, p
347347
Public: proj.Public,
348348
Provisioner: proj.Provisioner,
349349
ArchiveAssetID: proj.ArchiveAssetID,
350-
GithubURL: proj.GithubURL,
350+
GitRemote: proj.GitRemote,
351351
GithubInstallationID: proj.GithubInstallationID,
352352
GithubRepoID: proj.GithubRepoID,
353353
ManagedGitRepoID: proj.ManagedGitRepoID,
@@ -395,7 +395,7 @@ func (s *Service) HibernateProject(ctx context.Context, proj *database.Project)
395395
Public: proj.Public,
396396
Provisioner: proj.Provisioner,
397397
ArchiveAssetID: proj.ArchiveAssetID,
398-
GithubURL: proj.GithubURL,
398+
GitRemote: proj.GitRemote,
399399
GithubInstallationID: proj.GithubInstallationID,
400400
GithubRepoID: proj.GithubRepoID,
401401
ManagedGitRepoID: proj.ManagedGitRepoID,

0 commit comments

Comments
 (0)