CorfedoCorfedoDocs

Search and read over HTTP

Pick the operation for your goal, search code, follow a result to exact lines at the same commit and read every page.

The read operations search code, read files and look up dependencies and security findings. This page shows which one to use and how results lead to each other. The API reference has every parameter.

Before you begin

A credential with Search and read code, and Dependencies or Security findings for those reads. The examples use the TypeScript SDK with an open client. The other SDKs have the same operations.

Choose the operation

GoalOperationTypeScript
Find code by a description, a name, exact text or a patternPOST /searchclient.search.search
Read a file, whole or by linesPOST /code/fileclient.code.readFile
List a directory, or the declarations in a filePOST /code/tree, POST /code/symbolsclient.code.listTree, client.code.listSymbols
Find where a name is declaredPOST /symbols/lookupclient.symbols.lookup
List the repositories the credential can readGET /repositoriesclient.repositories.list
A repository's packages, or where a package is usedPOST /dependencies, POST /packages/usesclient.dependencies, client.packages
Vulnerability findings and advisoriesPOST /security/findings, GET /security/advisories/{advisoryId}client.security

/search takes the query language in Search syntax. Results come most relevant first, a page at a time.

Search and read the result

const page = await client.search.search({
  query: 'where are webhook signatures verified',
  scope: { repositories: [{ kind: 'name', name: 'acme/payments' }] },
});
const hit = page.results.find((result) => result.kind === 'file');
if (hit) {
  const file = await client.code.readFile({
    repository: hit.repository,
    path: hit.path,
    revision: hit.revision,
    lines: { start: 1, end: 40 },
  });
  if (file.status === 'found') console.log(new TextDecoder().decode(file.content));
}

Each result names its repository, path and the commit it read as revision. Pass that revision to the read, so it reads the same code the search found. Without a revision a read uses the commit the repository serves now.

scope limits the search to repositories by name, glob, ID or saved context ID. A filter such as repo: in the query does the same.

Check: file.status is found and the content contains the lines the search matched.

Read the status

Search statusMeaning
completeEvery repository in scope was searched
partialSome repositories were not searched in time or are unavailable. repositories lists each one with its state and failure, for example staleSnapshot for a revision no longer served. coverage counts them.
unavailableNothing could be searched right now

unsearchedTexts lists the query's texts that were not searched because they have only short or common words. A type:symbol page carries declarationTotals, the matching declarations in total, per repository and per language. They are exact when complete is true and lower bounds otherwise.

Read statusMeaning
foundThe file, directory or symbols were read
notFoundThe path does not exist at that revision
staleThe read asked for a revision that is no longer served. Read again with currentRevision, or without a revision.
unavailableThe code cannot be read right now

Read every page

Pass the continuation from one page with the same request to get the next. The SDK does this for you:

for await (const page of client.pages.search({ query: '"RetryPolicy" lang:csharp' })) {
  for (const result of page.results) console.log(result.repository, result.path);
}

After 100 pages the traversal throws PaginationLimitReached. Pass { maximumPages: n } as the second argument to change the limit.

On this page