Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
worker: fix repo existence check (#37404)
Browse files Browse the repository at this point in the history
  • Loading branch information
sashaostrikov authored and BolajiOlajide committed Jun 20, 2022
1 parent 8bb79a0 commit 246fd4a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion enterprise/cmd/worker/internal/permissions/bitbucket_projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package permissions
import (
"context"
"database/sql"
"fmt"
"sort"
"time"

Expand Down Expand Up @@ -227,7 +228,7 @@ func (h *bitbucketProjectPermissionsHandler) setPermissionsForUsers(ctx context.

func (h *bitbucketProjectPermissionsHandler) setRepoPermissions(ctx context.Context, repoID api.RepoID, _ []types.UserPermission, userIDs map[int32]struct{}, pendingBindIDs []string) (err error) {
// Make sure the repo ID is valid.
if _, err := h.db.Repos().Get(ctx, repoID); err != nil {
if err := h.repoExists(ctx, repoID); err != nil {
return errcode.MakeNonRetryable(errors.Wrapf(err, "failed to query repo %d", repoID))
}

Expand Down Expand Up @@ -270,6 +271,17 @@ func (h *bitbucketProjectPermissionsHandler) setRepoPermissions(ctx context.Cont
return nil
}

func (h *bitbucketProjectPermissionsHandler) repoExists(ctx context.Context, repoID api.RepoID) (err error) {
var id int
if err := h.db.QueryRowContext(ctx, fmt.Sprintf("SELECT id FROM repo WHERE id = %d", repoID)).Scan(&id); err != nil {
if err == sql.ErrNoRows {
return errors.New("repo not found")
}
return err
}
return nil
}

// newBitbucketProjectPermissionsWorker creates a worker that reads the explicit_permissions_bitbucket_projects_jobs table and
// executes the jobs.
func newBitbucketProjectPermissionsWorker(db edb.EnterpriseDB, cfg *config, metrics bitbucketProjectPermissionsMetrics) *workerutil.Worker {
Expand Down

0 comments on commit 246fd4a

Please sign in to comment.