From bef27e3d2b15ad902d3f586a10ab9927cdee6fcf Mon Sep 17 00:00:00 2001 From: Gary Lee <105310278+gl-srgr@users.noreply.github.com> Date: Wed, 12 Jul 2023 12:16:02 -0700 Subject: [PATCH] Allow for null revision resolver when using repo embeddings job's empty revision string (#54879) This [PR](https://github.com/sourcegraph/sourcegraph/pull/54804) fixed an issue with job scheduling/execution in the backend. The interim fix of this PR relies on allowing for empty string `revision` values written with a repo embedding job when the repo is empty or some other issue occurs when fetching the repo's default branch (e.g. empty repo). Empty revision value causes issues with graphql query repoEmbeddingJobs when [querying for Revision](https://sourcegraph.com/github.com/sourcegraph/sourcegraph/-/blob/client/web/src/enterprise/site-admin/cody/backend.ts?L32-35) as our site admin jobs panel does. `Panic occurred: runtime error: slice bounds out of range [:7] with length 0` This PR updates the embedding job resolver to consider empty revision string acceptable and not call constructor for git commit resolver. Also site admin jobs list will now show repo name if repo is non-null and revision is null. sg manual test (cherry picked from commit 1dd6db4e2d507be7a8c41cec3882290100383e0c) --- .../enterprise/site-admin/cody/RepoEmbeddingJobNode.tsx | 2 ++ .../internal/embeddings/resolvers/repo_embedding_jobs.go | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/client/web/src/enterprise/site-admin/cody/RepoEmbeddingJobNode.tsx b/client/web/src/enterprise/site-admin/cody/RepoEmbeddingJobNode.tsx index f91c2b532a3..531be81c35e 100644 --- a/client/web/src/enterprise/site-admin/cody/RepoEmbeddingJobNode.tsx +++ b/client/web/src/enterprise/site-admin/cody/RepoEmbeddingJobNode.tsx @@ -50,6 +50,8 @@ export const RepoEmbeddingJobNode: FC = ({ {repo.name}@{revision.abbreviatedOID} + ) : repo ? ( + <>{repo.name} ) : (
Unknown repository
)} diff --git a/enterprise/cmd/frontend/internal/embeddings/resolvers/repo_embedding_jobs.go b/enterprise/cmd/frontend/internal/embeddings/resolvers/repo_embedding_jobs.go index 2eea5d215c7..efc45484c38 100644 --- a/enterprise/cmd/frontend/internal/embeddings/resolvers/repo_embedding_jobs.go +++ b/enterprise/cmd/frontend/internal/embeddings/resolvers/repo_embedding_jobs.go @@ -214,9 +214,16 @@ func (r *repoEmbeddingJobResolver) Revision(ctx context.Context) (*graphqlbacken if err != nil { return nil, err } - if repoResolver == nil { + + // An empty revision value can accompany a valid repository if gitserver cannot resolve the default branch or latest revision during job scheduling. + // The job will always fail in this case and must be displayed in site admin despite the gitserver error. + // Site admin will only provide the job's failure_message in this case. + invalidRevision := r.job.Revision == "" + + if repoResolver == nil || invalidRevision { return nil, nil } + return graphqlbackend.NewGitCommitResolver(r.db, r.gitserverClient, repoResolver, r.job.Revision, nil), nil }