Applying Filters to Included Attributes
Automatically apply repository search filters to included user attributes using field mapping.
When searching repositories, you can include user attributes (such as DevRank data) in the results via includeAttributes. By default, your repo filters only apply to the repository search itself. With applyFiltersToIncludeAttributes, the API automatically converts your repo filters into equivalent user filters and applies them to the included user data.
Why This Exists
Section titled “Why This Exists”Repository and user data live in separate tables with different field names. For example, ownerLogin on a repo corresponds to login on the user table. When you search for repos owned by developers in San Francisco and want to include contributor data, you’d normally need to write a second set of filters targeting the user table. applyFiltersToIncludeAttributes handles this conversion for you.
Field Mapping
Section titled “Field Mapping”The API maps repo filter fields to their user table equivalents:
| Repo Filter Field | User Field |
|---|---|
ownerLogin | login |
ownerLocation | location |
login | login |
location | location |
company | company |
displayName | displayName |
bio | bio |
resolvedCountry | resolvedCountry |
resolvedState | resolvedState |
resolvedCity | resolvedCity |
Repo-only fields like stargazerCount, language, or totalIssuesOpen have no user equivalent and are ignored when filtering included attributes.
Example
Section titled “Example”Find popular Python repos with San Francisco contributors, and include DevRank data only for contributors who match the location filter:
const response = await client.searchRepos.search({ query: "machine learning", filters: { op: "And", filters: [ { field: "language", op: "Eq", value: "Python" }, { field: "stargazerCount", op: "Gte", value: 1000 }, { field: "resolvedCity", op: "ContainsAllTokens", value: "San Francisco", }, ], }, includeAttributes: { devrank: true, }, applyFiltersToIncludeAttributes: true,});
// The resolvedCity filter is mapped and applied to contributors,// so only San Francisco-based contributors have DevRank data included.// language and stargazerCount have no user equivalent and are skipped.When to Use This
Section titled “When to Use This”- You want contributor/owner data that matches the same geographic or identity constraints as your repo search.
- You want to avoid a separate user search call to filter the included attributes yourself.