Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix repository delete by name #2941

Merged
merged 1 commit into from
Apr 4, 2024
Merged
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
4 changes: 2 additions & 2 deletions database/query/repositories.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SELECT * FROM repositories WHERE repo_id = $1;
-- name: GetRepositoryByRepoName :one
SELECT * FROM repositories
WHERE repo_owner = $1 AND repo_name = $2 AND project_id = $3
AND lower(provider) = lower(sqlc.narg('provider')::text) OR sqlc.narg('provider')::text IS NULL;
AND (lower(provider) = lower(sqlc.narg('provider')::text) OR sqlc.narg('provider')::text IS NULL);

-- avoid using this, where possible use GetRepositoryByIDAndProject instead
-- name: GetRepositoryByID :one
Expand All @@ -42,7 +42,7 @@ LIMIT sqlc.narg('limit')::bigint;
-- name: ListRegisteredRepositoriesByProjectIDAndProvider :many
SELECT * FROM repositories
WHERE project_id = $1 AND webhook_id IS NOT NULL
AND lower(provider) = lower(sqlc.narg('provider')::text) OR sqlc.narg('provider')::text IS NULL
AND (lower(provider) = lower(sqlc.narg('provider')::text) OR sqlc.narg('provider')::text IS NULL)
ORDER BY repo_name;

-- name: DeleteRepository :exec
Expand Down
4 changes: 2 additions & 2 deletions internal/db/repositories.sql.go

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

63 changes: 63 additions & 0 deletions internal/db/repositories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,38 @@ func TestGetRepositoryByRepoName(t *testing.T) {
require.Equal(t, repo1.UpdatedAt, repo2.UpdatedAt)
}

func TestGetRepositoryByRepoNameNoProvider(t *testing.T) {
t.Parallel()

org := createRandomOrganization(t)
project := createRandomProject(t, org.ID)
prov := createRandomProvider(t, project.ID)
createRandomRepository(t, project.ID, prov)
repo1 := createRandomRepository(t, project.ID, prov)

repo2, err := testQueries.GetRepositoryByRepoName(context.Background(), GetRepositoryByRepoNameParams{
RepoOwner: repo1.RepoOwner,
RepoName: repo1.RepoName,
ProjectID: project.ID,
})
require.NoError(t, err)
require.NotEmpty(t, repo2)

require.Equal(t, repo1.ID, repo2.ID)
require.Equal(t, repo1.Provider, repo2.Provider)
require.Equal(t, repo1.ProjectID, repo2.ProjectID)
require.Equal(t, repo1.RepoOwner, repo2.RepoOwner)
require.Equal(t, repo1.RepoName, repo2.RepoName)
require.Equal(t, repo1.RepoID, repo2.RepoID)
require.Equal(t, repo1.IsPrivate, repo2.IsPrivate)
require.Equal(t, repo1.IsFork, repo2.IsFork)
require.Equal(t, repo1.WebhookID, repo2.WebhookID)
require.Equal(t, repo1.WebhookUrl, repo2.WebhookUrl)
require.Equal(t, repo1.DeployUrl, repo2.DeployUrl)
require.Equal(t, repo1.CreatedAt, repo2.CreatedAt)
require.Equal(t, repo1.UpdatedAt, repo2.UpdatedAt)
}

func TestListRepositoriesByProjectID(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -188,6 +220,37 @@ func TestListRepositoriesByProjectID(t *testing.T) {
}
}

func TestListRepositoriesByProjectIDAndProvider(t *testing.T) {
t.Parallel()

org := createRandomOrganization(t)
otherProject := createRandomProject(t, org.ID)
project := createRandomProject(t, org.ID)
otherProv := createRandomProvider(t, otherProject.ID)
prov := createRandomProvider(t, project.ID)
createRandomRepository(t, project.ID, otherProv)
createRandomRepository(t, otherProject.ID, prov)

for i := 1001; i < 1020; i++ {
createRandomRepository(t, project.ID, prov, func(r *CreateRepositoryParams) {
r.RepoID = int64(i)
})
}

arg := ListRegisteredRepositoriesByProjectIDAndProviderParams{
ProjectID: project.ID,
}

repos, err := testQueries.ListRegisteredRepositoriesByProjectIDAndProvider(context.Background(), arg)
require.NoError(t, err)
require.NotEmpty(t, repos)

for _, repo := range repos {
require.NotEmpty(t, repo)
require.Equal(t, arg.ProjectID, repo.ProjectID)
}
}

func TestDeleteRepository(t *testing.T) {
t.Parallel()

Expand Down
Loading