Skip to content

Commit

Permalink
repositories: Add clone URL to data we track
Browse files Browse the repository at this point in the history
This will help us make better decisions if we decide to support a git ingestor.

The idea is that we'll be able to get (and not guess) a supported git cloning
URL so we could fetch the data.
  • Loading branch information
JAORMX committed Aug 31, 2023
1 parent 36b6062 commit 5aa218d
Show file tree
Hide file tree
Showing 10 changed files with 1,730 additions and 1,670 deletions.
1 change: 1 addition & 0 deletions database/migrations/000001_init.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ CREATE TABLE repositories (
webhook_id INTEGER,
webhook_url TEXT NOT NULL,
deploy_url TEXT NOT NULL,
clone_url TEXT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW()
);
Expand Down
5 changes: 4 additions & 1 deletion database/query/repositories.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ INSERT INTO repositories (
is_fork,
webhook_id,
webhook_url,
deploy_url) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING *;
deploy_url,
clone_url) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING *;

-- name: GetRepositoryByID :one
SELECT * FROM repositories WHERE id = $1;
Expand Down Expand Up @@ -59,6 +60,7 @@ webhook_id = $8,
webhook_url = $9,
deploy_url = $10,
provider = $11,
clone_url = $12,
updated_at = NOW()
WHERE id = $1 RETURNING *;

Expand All @@ -73,6 +75,7 @@ webhook_id = $7,
webhook_url = $8,
deploy_url = $9,
provider = $10,
clone_url = $11,
updated_at = NOW()
WHERE repo_id = $1 RETURNING *;

Expand Down
8 changes: 5 additions & 3 deletions docs/docs/protodocs/proto.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions internal/gh/queries/sync_repo_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func SyncRepositoriesWithDB(ctx context.Context,
RepoID: int32(*repo.ID),
IsPrivate: bool(*repo.Private), // Needs a value from GraphQL data
IsFork: bool(*repo.Fork),
CloneUrl: string(*repo.CloneURL),
})
if err != nil {
fmt.Println("failed to create repository for repo ID: with repo Name: ", *repo.ID, *repo.Name)
Expand All @@ -97,6 +98,7 @@ func SyncRepositoriesWithDB(ctx context.Context,
IsPrivate: bool(*repo.Private), // Needs a value from GraphQL data
IsFork: bool(*repo.Fork),
ID: existingRepo.ID,
CloneUrl: string(*repo.CloneURL),
})
if err != nil {
return fmt.Errorf("failed to update repository: %w", err)
Expand Down
3 changes: 3 additions & 0 deletions pkg/controlplane/handlers_repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func (s *Server) ListRepositories(ctx context.Context,
IsFork: repo.IsFork,
HookUrl: repo.WebhookUrl,
DeployUrl: repo.DeployUrl,
CloneUrl: repo.CloneUrl,
CreatedAt: timestamppb.New(repo.CreatedAt),
UpdatedAt: timestamppb.New(repo.UpdatedAt),
})
Expand Down Expand Up @@ -286,6 +287,7 @@ func (s *Server) GetRepositoryById(ctx context.Context,
IsFork: repo.IsFork,
HookUrl: repo.WebhookUrl,
DeployUrl: repo.DeployUrl,
CloneUrl: repo.CloneUrl,
CreatedAt: createdAt,
UpdatedAt: updatedat,
}}, nil
Expand Down Expand Up @@ -334,6 +336,7 @@ func (s *Server) GetRepositoryByName(ctx context.Context,
IsFork: repo.IsFork,
HookUrl: repo.WebhookUrl,
DeployUrl: repo.DeployUrl,
CloneUrl: repo.CloneUrl,
CreatedAt: createdAt,
UpdatedAt: updatedat,
}}, nil
Expand Down
1 change: 1 addition & 0 deletions pkg/db/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 31 additions & 11 deletions pkg/db/repositories.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 15 additions & 9 deletions pkg/generated/openapi/mediator/v1/mediator.swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5aa218d

Please sign in to comment.