Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(soup): filter GitHub pull requests with a ghprf filter tree (#7105)

dev-rb9d67b2c9626e
diff --git a/.sqlx/query-16c98d8bb484fd33da108a68411a99403d8ccdceb35347b7bb07e1f44a5561c5.json b/.sqlx/query-16c98d8bb484fd33da108a68411a99403d8ccdceb35347b7bb07e1f44a5561c5.json
deleted file mode 100644
index 0956e6c1f7..0000000000
--- a/.sqlx/query-16c98d8bb484fd33da108a68411a99403d8ccdceb35347b7bb07e1f44a5561c5.json
+++ /dev/null
@@ -1,74 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n WITH source_ids AS (\n SELECT DISTINCT stored_for_id, stored_for_auth_entity\n FROM UNNEST($1::text[], $2::text[])\n AS source_rows(stored_for_id, stored_for_auth_entity)\n ),\n deduped AS (\n SELECT DISTINCT ON (fe.foreign_entity_source, fe.foreign_entity_id)\n fe.id,\n fe.foreign_entity_id,\n fe.foreign_entity_source,\n fe.metadata,\n fe.stored_for_id,\n fe.stored_for_auth_entity,\n fe.created_at,\n fe.updated_at,\n CASE $3::text\n WHEN 'created_at' THEN fe.created_at\n ELSE fe.updated_at\n END AS sort_at\n FROM foreign_entity fe\n WHERE fe.foreign_entity_source = $11::text\n AND EXISTS (\n SELECT 1\n FROM source_ids s\n WHERE s.stored_for_id = fe.stored_for_id\n AND s.stored_for_auth_entity = fe.stored_for_auth_entity\n )\n AND (\n $4::text IS NULL\n OR jsonb_path_match(\n jsonb_build_object(\n 'id', fe.id::text,\n 'foreignEntityId', fe.foreign_entity_id,\n 'foreignEntitySource', fe.foreign_entity_source\n ),\n ($4::text)::jsonpath\n )\n )\n AND (\n $8::text[] IS NULL\n OR (fe.metadata -> 'participantGithubUserIds') ?| $8::text[]\n )\n AND (\n $9::int[] IS NULL\n OR ($10::text IS NOT NULL AND (\n SELECT COALESCE(bit_or(CASE un.state\n WHEN 'unseen' THEN 1 WHEN 'seen' THEN 2 WHEN 'done' THEN 4 END), 0)\n FROM notification n\n JOIN user_notification un ON un.notification_id = n.id\n WHERE un.user_id = $10::text\n AND un.deleted_at IS NULL\n AND n.event_item_type = 'foreign_entity'\n AND n.event_item_id = fe.id::text\n ) = ANY($9::int[]))\n )\n ORDER BY fe.foreign_entity_source, fe.foreign_entity_id, sort_at DESC, fe.id DESC\n )\n SELECT\n id as \"id!: Uuid\",\n foreign_entity_id as \"foreign_entity_id!: String\",\n foreign_entity_source as \"foreign_entity_source!: String\",\n metadata as \"metadata!: serde_json::Value\",\n stored_for_id as \"stored_for_id!: String\",\n stored_for_auth_entity as \"stored_for_auth_entity!: String\",\n created_at as \"created_at!: DateTime<Utc>\",\n updated_at as \"updated_at!: DateTime<Utc>\"\n FROM deduped\n WHERE $5::timestamptz IS NULL\n OR (sort_at, id) < ($5::timestamptz, $6::uuid)\n ORDER BY sort_at DESC, id DESC\n LIMIT $7\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "id!: Uuid",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "foreign_entity_id!: String",
- "type_info": "Text"
- },
- {
- "ordinal": 2,
- "name": "foreign_entity_source!: String",
- "type_info": "Text"
- },
- {
- "ordinal": 3,
- "name": "metadata!: serde_json::Value",
- "type_info": "Jsonb"
- },
- {
- "ordinal": 4,
- "name": "stored_for_id!: String",
- "type_info": "Text"
- },
- {
- "ordinal": 5,
- "name": "stored_for_auth_entity!: String",
- "type_info": "Text"
- },
- {
- "ordinal": 6,
- "name": "created_at!: DateTime<Utc>",
- "type_info": "Timestamptz"
- },
- {
- "ordinal": 7,
- "name": "updated_at!: DateTime<Utc>",
- "type_info": "Timestamptz"
- }
- ],
- "parameters": {
- "Left": [
- "TextArray",
- "TextArray",
- "Text",
- "Text",
- "Timestamptz",
- "Uuid",
- "Int8",
- "TextArray",
- "Int4Array",
- "Text",
- "Text"
- ]
- },
- "nullable": [
- false,
- false,
- false,
- false,
- false,
- false,
- false,
- false
- ]
- },
- "hash": "16c98d8bb484fd33da108a68411a99403d8ccdceb35347b7bb07e1f44a5561c5"
-}
diff --git a/.sqlx/query-75ae44e1f1bf0d633a1e1ee896cd23178455849db387d141f7486727cbe967be.json b/.sqlx/query-75ae44e1f1bf0d633a1e1ee896cd23178455849db387d141f7486727cbe967be.json
new file mode 100644
index 0000000000..781591a07c
--- /dev/null
+++ b/.sqlx/query-75ae44e1f1bf0d633a1e1ee896cd23178455849db387d141f7486727cbe967be.json
@@ -0,0 +1,75 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n WITH source_ids AS (\n SELECT DISTINCT stored_for_id, stored_for_auth_entity\n FROM UNNEST($1::text[], $2::text[])\n AS source_rows(stored_for_id, stored_for_auth_entity)\n ),\n deduped AS (\n SELECT DISTINCT ON (fe.foreign_entity_source, fe.foreign_entity_id)\n fe.id,\n fe.foreign_entity_id,\n fe.foreign_entity_source,\n fe.metadata,\n fe.stored_for_id,\n fe.stored_for_auth_entity,\n fe.created_at,\n COALESCE(gpr.github_updated_at, fe.updated_at) AS updated_at,\n CASE $3::text\n WHEN 'created_at' THEN fe.created_at\n ELSE COALESCE(gpr.github_updated_at, fe.updated_at)\n END AS sort_at\n FROM foreign_entity fe\n LEFT JOIN github_pull_request gpr ON gpr.github_key = fe.foreign_entity_id\n WHERE fe.foreign_entity_source = $11::text\n AND EXISTS (\n SELECT 1\n FROM source_ids s\n WHERE s.stored_for_id = fe.stored_for_id\n AND s.stored_for_auth_entity = fe.stored_for_auth_entity\n )\n AND (\n $4::text IS NULL\n OR jsonb_path_match(\n jsonb_build_object(\n 'id', fe.id::text,\n 'foreignEntityId', fe.foreign_entity_id,\n 'foreignEntitySource', fe.foreign_entity_source\n ),\n ($4::text)::jsonpath\n )\n )\n AND (\n $8::text[] IS NULL\n OR (fe.metadata -> 'participantGithubUserIds') ?| $8::text[]\n )\n AND (\n $12::text IS NULL\n OR (gpr.github_key IS NOT NULL AND jsonb_path_match(\n jsonb_build_object(\n 'repositoryId', gpr.repository_id,\n 'authorId', gpr.author_github_user_id,\n 'status', gpr.status,\n 'draft', gpr.draft,\n 'requestedReviewers', to_jsonb(gpr.requested_reviewer_github_user_ids),\n 'participants', to_jsonb(gpr.participant_github_user_ids)\n ),\n ($12::text)::jsonpath\n ))\n )\n AND (\n $9::int[] IS NULL\n OR ($10::text IS NOT NULL AND (\n SELECT COALESCE(bit_or(CASE un.state\n WHEN 'unseen' THEN 1 WHEN 'seen' THEN 2 WHEN 'done' THEN 4 END), 0)\n FROM notification n\n JOIN user_notification un ON un.notification_id = n.id\n WHERE un.user_id = $10::text\n AND un.deleted_at IS NULL\n AND n.event_item_type = 'foreign_entity'\n AND n.event_item_id = fe.id::text\n ) = ANY($9::int[]))\n )\n ORDER BY\n fe.foreign_entity_source,\n fe.foreign_entity_id,\n sort_at DESC,\n fe.updated_at DESC,\n fe.id DESC\n )\n SELECT\n id as \"id!: Uuid\",\n foreign_entity_id as \"foreign_entity_id!: String\",\n foreign_entity_source as \"foreign_entity_source!: String\",\n metadata as \"metadata!: serde_json::Value\",\n stored_for_id as \"stored_for_id!: String\",\n stored_for_auth_entity as \"stored_for_auth_entity!: String\",\n created_at as \"created_at!: DateTime<Utc>\",\n updated_at as \"updated_at!: DateTime<Utc>\"\n FROM deduped\n WHERE $5::timestamptz IS NULL\n OR (sort_at, id) < ($5::timestamptz, $6::uuid)\n ORDER BY sort_at DESC, id DESC\n LIMIT $7\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id!: Uuid",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "foreign_entity_id!: String",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 2,
+ "name": "foreign_entity_source!: String",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 3,
+ "name": "metadata!: serde_json::Value",
+ "type_info": "Jsonb"
+ },
+ {
+ "ordinal": 4,
+ "name": "stored_for_id!: String",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 5,
+ "name": "stored_for_auth_entity!: String",
+ "type_info": "Text"
+ },
+ {
+ "ordinal": 6,
+ "name": "created_at!: DateTime<Utc>",
+ "type_info": "Timestamptz"
+ },
+ {
+ "ordinal": 7,
+ "name": "updated_at!: DateTime<Utc>",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "TextArray",
+ "TextArray",
+ "Text",
+ "Text",
+ "Timestamptz",
+ "Uuid",
+ "Int8",
+ "TextArray",
+ "Int4Array",
+ "Text",
+ "Text",
+ "Text"
+ ]
+ },
+ "nullable": [
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ null
+ ]
+ },
+ "hash": "75ae44e1f1bf0d633a1e1ee896cd23178455849db387d141f7486727cbe967be"
+}
diff --git a/apps/web/src/features/soup/filters/facets/compile.test.ts b/apps/web/src/features/soup/filters/facets/compile.test.ts
index c091c954b7..e3780be8ff 100644
--- a/apps/web/src/features/soup/filters/facets/compile.test.ts
+++ b/apps/web/src/features/soup/filters/facets/compile.test.ts
@@ -150,3 +150,47 @@ describe('facet compiler', () => {
});
});
});
+
+describe('GitHub repository ID precision', () => {
+ const compileRepository = (value: unknown) =>
+ compileFacets(
+ { repository: ['selected'] },
+ [
+ {
+ id: 'repository',
+ mode: 'or',
+ options: [
+ {
+ id: 'selected',
+ clause: {
+ ghprf: clause.eq('githubPullRequestRepositoryId', value),
+ },
+ },
+ ],
+ },
+ ],
+ undefined
+ );
+
+ it.each(['42', 42, '9007199254740991'])(
+ 'preserves a safely representable ID: %s',
+ (id) => {
+ expect(compileRepository(id)).toEqual({
+ ghprf: { l: { repo: Number(id) } },
+ });
+ }
+ );
+
+ it.each([
+ '9007199254740993',
+ '9223372036854775807',
+ 9007199254740992,
+ '1.5',
+ '',
+ null,
+ ])('rejects IDs instead of silently rounding or coercing: %s', (id) => {
+ expect(() => compileRepository(id)).toThrow(
+ 'GitHub repository ID must be a positive safe integer'
+ );
+ });
+});
diff --git a/apps/web/src/features/soup/filters/facets/constants.ts b/apps/web/src/features/soup/filters/facets/constants.ts
index b806d27c1a..924dbf37ac 100644
--- a/apps/web/src/features/soup/filters/facets/constants.ts
+++ b/apps/web/src/features/soup/filters/facets/constants.ts
@@ -25,6 +25,24 @@ export type FilterFieldMeta = {
domain?: unknown[];
};
+function githubRepositoryId(value: unknown): number {
+ if (
+ (typeof value !== 'string' || !/^\d+$/.test(value)) &&
+ typeof value !== 'number'
+ ) {
+ throw new RangeError(
+ 'GitHub repository ID must be a positive safe integer'
+ );
+ }
+ const id = Number(value);
+ if (!Number.isSafeInteger(id) || id <= 0) {
+ throw new RangeError(
+ 'GitHub repository ID must be a positive safe integer'
+ );
+ }
+ return id;
+}
+
/*
* When adding a filter, update FILTER_TARGETS and FilterTargetsMeta. New
* targets also require TARGETS; entity targets additionally require
@@ -181,6 +199,19 @@ export const FILTER_TARGETS = {
foreignEntityIncludesMe: { backend: 'me', compile: 'unit' },
},
+ // ghprf — GitHub pull requests, narrowing fef to pull request records
+ ghprf: {
+ githubPullRequestRepositoryId: {
+ backend: 'repo',
+ formatValue: githubRepositoryId,
+ },
+ githubPullRequestAuthorId: { backend: 'au' },
+ githubPullRequestStatus: { backend: 'st' },
+ githubPullRequestInvolves: { backend: 'inv' },
+ githubPullRequestReviewRequested: { backend: 'rr' },
+ githubPullRequestDraft: { backend: 'draft', domain: [true, false] },
+ },
+
// ccf — crm companies
ccf: {
crmCompanyId: { backend: 'id' },
@@ -307,6 +338,20 @@ type FilterTargetsMeta = {
foreignEntityIncludesMe: boolean;
};
+ // ghprf — GitHub pull requests
+ ghprf: {
+ /** Numeric GitHub repository id. */
+ githubPullRequestRepositoryId: string[];
+ /** Numeric GitHub user id of the author. */
+ githubPullRequestAuthorId: string[];
+ githubPullRequestStatus: ('open' | 'closed' | 'merged')[];
+ /** Numeric GitHub user id of someone involved. */
+ githubPullRequestInvolves: string[];
+ /** Numeric GitHub user id of a requested reviewer. */
+ githubPullRequestReviewRequested: string[];
+ githubPullRequestDraft: boolean;
+ };
+
// ccf — crm companies
ccf: {
crmCompanyId: string[];
@@ -357,6 +402,7 @@ export const TARGETS: Target[] = [
'pf',
'callf',
'fef',
+ 'ghprf',
'ccf',
'asf',
'remf',
@@ -369,7 +415,7 @@ export type FieldKey = {
[T in Target]: FieldsForTarget<T>;
}[Target];
-export type EntityTarget = Exclude<Target, 'propf'>;
+export type EntityTarget = Exclude<Target, 'propf' | 'ghprf'>;
export const ENTITY_TARGETS: EntityTarget[] = [
'df',
diff --git a/apps/web/src/lib/queries/soup/graphql/ast.ts b/apps/web/src/lib/queries/soup/graphql/ast.ts
index 24a4185cd5..cad2cbbe17 100644
--- a/apps/web/src/lib/queries/soup/graphql/ast.ts
+++ b/apps/web/src/lib/queries/soup/graphql/ast.ts
@@ -14,6 +14,8 @@ import type {
GraphqlEmailValue as GraphqlEmailValueInput,
GraphqlEntityFilterAst as GraphqlEntityFilterAstInput,
GraphqlForeignEntityLiteral as GraphqlForeignEntityLiteralInput,
+ GraphqlGithubPullRequestLiteral as GraphqlGithubPullRequestLiteralInput,
+ GraphqlGithubPullRequestState,
GraphqlGroupByInput,
GroupedSoupContinuationInput as GraphqlGroupedSoupContinuationInput,
GroupedSoupInput as GraphqlGroupedSoupInput,
@@ -61,6 +63,7 @@ type TargetAstKey =
| 'callf'
| 'ccf'
| 'fef'
+ | 'ghprf'
| 'asf'
| 'remf'
| 'propf';
@@ -520,6 +523,43 @@ function mapForeignEntityLiteral(
}
}
+function mapGithubPullRequestState(
+ value: unknown
+): GraphqlGithubPullRequestState {
+ const state = mapString(value, 'status');
+ if (state === 'open') return 'OPEN';
+ if (state === 'closed') return 'CLOSED';
+ if (state === 'merged') return 'MERGED';
+ unsupported(`unsupported pull request status ${state}`);
+}
+
+function mapGithubPullRequestLiteral(
+ literal: unknown
+): GraphqlGithubPullRequestLiteralInput {
+ const [field, value] = singleLiteralField(literal);
+ switch (field) {
+ case 'repo':
+ return {
+ repositoryId:
+ typeof value === 'number'
+ ? String(value)
+ : mapString(value, 'repositoryId'),
+ };
+ case 'au':
+ return { author: mapString(value, 'author') };
+ case 'st':
+ return { status: mapGithubPullRequestState(value) };
+ case 'inv':
+ return { involves: mapString(value, 'involves') };
+ case 'rr':
+ return { reviewRequested: mapString(value, 'reviewRequested') };
+ case 'draft':
+ return { draft: mapBoolean(value, 'draft') };
+ default:
+ unsupported(`github pull request literal ${field}`);
+ }
+}
+
function mapReminderLiteral(literal: unknown): GraphqlReminderLiteralInput {
const [field, value] = singleLiteralField(literal);
switch (field) {
@@ -660,6 +700,12 @@ function makeGraphqlFilters(body: AstBody): GraphqlEntityFilterAstInput {
mapForeignEntityLiteral
);
}
+ if (body.ghprf) {
+ filters.githubPullRequestFilter = compileExpr(
+ body.ghprf,
+ mapGithubPullRequestLiteral
+ );
+ }
if (body.asf) {
filters.agentSessionFilter = compileExpr(
body.asf,
diff --git a/apps/web/src/lib/service-clients/service-storage/generated/schemas/apiEntityFilterAst.ts b/apps/web/src/lib/service-clients/service-storage/generated/schemas/apiEntityFilterAst.ts
index 197fd54320..1a5ee81d39 100644
--- a/apps/web/src/lib/service-clients/service-storage/generated/schemas/apiEntityFilterAst.ts
+++ b/apps/web/src/lib/service-clients/service-storage/generated/schemas/apiEntityFilterAst.ts
@@ -48,6 +48,8 @@ unlike the materialized [`EntityFilterAst`] used for cursors. */
favorites_only?: ApiEntityFilterAstFavoritesOnly;
/** the filters that should be applied to foreign entity records */
fef?: unknown;
+ /** the filters that should be applied to GitHub pull request records, on top of `fef` */
+ ghprf?: unknown;
/** the filters that should be applied to the project entity */
pf?: unknown;
/** the filters that should be applied based on entity properties */
diff --git a/apps/web/src/lib/service-clients/service-storage/generated/zod.ts b/apps/web/src/lib/service-clients/service-storage/generated/zod.ts
index 722c84efff..175a6958f5 100644
--- a/apps/web/src/lib/service-clients/service-storage/generated/zod.ts
+++ b/apps/web/src/lib/service-clients/service-storage/generated/zod.ts
@@ -23376,6 +23376,12 @@ export const postItemsSoupAstBody = zod
.unknown()
.optional()
.describe('the filters that should be applied to foreign entity records'),
+ ghprf: zod
+ .unknown()
+ .optional()
+ .describe(
+ 'the filters that should be applied to GitHub pull request records, on top of `fef`'
+ ),
pf: zod
.unknown()
.optional()
@@ -27553,6 +27559,12 @@ export const postItemsSoupAstGroupedBody = zod
.describe(
'the filters that should be applied to foreign entity records'
),
+ ghprf: zod
+ .unknown()
+ .optional()
+ .describe(
+ 'the filters that should be applied to GitHub pull request records, on top of `fef`'
+ ),
pf: zod
.unknown()
.optional()
@@ -27727,6 +27739,12 @@ export const postItemsSoupAstGroupedBody = zod
.describe(
'the filters that should be applied to foreign entity records'
),
+ ghprf: zod
+ .unknown()
+ .optional()
+ .describe(
+ 'the filters that should be applied to GitHub pull request records, on top of `fef`'
+ ),
pf: zod
.unknown()
.optional()
diff --git a/apps/web/src/lib/service-clients/service-storage/graphql/generated/graphql.ts b/apps/web/src/lib/service-clients/service-storage/graphql/generated/graphql.ts
index 1eef1d6729..23ab89b75b 100644
--- a/apps/web/src/lib/service-clients/service-storage/graphql/generated/graphql.ts
+++ b/apps/web/src/lib/service-clients/service-storage/graphql/generated/graphql.ts
@@ -655,6 +655,8 @@ export type GraphqlEntityFilterAst = {
favoritesOnly?: boolean | null | undefined;
/** The foreign entity filter to apply. */
foreignEntityFilter?: GraphqlForeignEntityExpr | null | undefined;
+ /** The GitHub pull request filter to apply, on top of the foreign entity filter. */
+ githubPullRequestFilter?: GraphqlGithubPullRequestExpr | null | undefined;
/** The initiative filter to apply. Initiatives are opt-in. */
initiativeFilter?: GraphqlInitiativeExpr | null | undefined;
/** The project filter to apply. */
@@ -855,6 +857,49 @@ export type GraphqlGithubPrReviewState =
/** Review left comments without an approval decision. */
| 'COMMENTED';
+/** The two operands of a recursive `GithubPullRequestFilterExpr` binary expression. */
+export type GraphqlGithubPullRequestBinaryExpr = {
+ /** Left expression. */
+ left: GraphqlGithubPullRequestExpr;
+ /** Right expression. */
+ right: GraphqlGithubPullRequestExpr;
+};
+
+/** A recursive `GithubPullRequestFilterExpr` filter expression. */
+export type GraphqlGithubPullRequestExpr =
+ { /** Both expressions must match. */
+ and: GraphqlGithubPullRequestBinaryExpr; literal?: never; not?: never; or?: never; }
+ | { and?: never; /** Match a literal. */
+ literal: GraphqlGithubPullRequestLiteral; not?: never; or?: never; }
+ | { and?: never; literal?: never; /** Negate an expression. */
+ not: GraphqlGithubPullRequestExpr; or?: never; }
+ | { and?: never; literal?: never; not?: never; /** Either expression may match. */
+ or: GraphqlGithubPullRequestBinaryExpr; };
+
+/** GraphQL input representing a GitHub pull request literal. */
+export type GraphqlGithubPullRequestLiteral =
+ { /** The author's numeric GitHub user id option. */
+ author: string; draft?: never; involves?: never; repositoryId?: never; reviewRequested?: never; status?: never; }
+ | { author?: never; /** The draft option. */
+ draft: boolean; involves?: never; repositoryId?: never; reviewRequested?: never; status?: never; }
+ | { author?: never; draft?: never; /** The numeric GitHub user id of someone involved in the pull request. */
+ involves: string; repositoryId?: never; reviewRequested?: never; status?: never; }
+ | { author?: never; draft?: never; involves?: never; /** The numeric GitHub repository id option. */
+ repositoryId: string; reviewRequested?: never; status?: never; }
+ | { author?: never; draft?: never; involves?: never; repositoryId?: never; /** The numeric GitHub user id of a requested reviewer. */
+ reviewRequested: string; status?: never; }
+ | { author?: never; draft?: never; involves?: never; repositoryId?: never; reviewRequested?: never; /** The pull request state option. */
+ status: GraphqlGithubPullRequestState; };
+
+/** GraphQL input representing a GitHub pull request state. */
+export type GraphqlGithubPullRequestState =
+ /** The closed option. */
+ | 'CLOSED'
+ /** The merged option. */
+ | 'MERGED'
+ /** The open option. */
+ | 'OPEN';
+
/** Grouping modes supported by grouped Soup. */
export type GraphqlGroupByField =
/** Group into date buckets. */
diff --git a/apps/web/src/lib/service-clients/service-storage/openapi.json b/apps/web/src/lib/service-clients/service-storage/openapi.json
index b4487fdd30..1042243b6f 100644
--- a/apps/web/src/lib/service-clients/service-storage/openapi.json
+++ b/apps/web/src/lib/service-clients/service-storage/openapi.json
@@ -17323,6 +17323,9 @@
"fef": {
"description": "the filters that should be applied to foreign entity records"
},
+ "ghprf": {
+ "description": "the filters that should be applied to GitHub pull request records, on top of `fef`"
+ },
"pf": {
"description": "the filters that should be applied to the project entity"
},
diff --git a/crates/databases_sql/src/row_source.rs b/crates/databases_sql/src/row_source.rs
index 3eafd0a5a4..511c13e4f1 100644
--- a/crates/databases_sql/src/row_source.rs
+++ b/crates/databases_sql/src/row_source.rs
@@ -383,6 +383,7 @@ fn rows_filter(
call_filter: Some(Arc::new(Expr::val(CallLiteral::CallId(Uuid::nil())))),
crm_company_filter: Some(Arc::new(Expr::val(CrmCompanyLiteral::Id(Uuid::nil())))),
foreign_entity_filter: Some(Arc::new(Expr::val(ForeignEntityLiteral::Id(Uuid::nil())))),
+ github_pull_request_filter: None,
// Reminders, agent sessions and initiatives are opt-in: left empty,
// they are excluded.
reminder_filter: None,
diff --git a/crates/databases_sql/src/row_source/test.rs b/crates/databases_sql/src/row_source/test.rs
index 0a41dde8a6..5ddcba0832 100644
--- a/crates/databases_sql/src/row_source/test.rs
+++ b/crates/databases_sql/src/row_source/test.rs
@@ -414,6 +414,7 @@ async fn a_table_read_is_its_rows_and_nothing_else() {
"callf": {"l": {"CallId": Uuid::nil()}},
"ccf": {"l": {"id": Uuid::nil()}},
"fef": {"l": {"id": Uuid::nil()}},
+ "ghprf": null,
"remf": null,
"asf": null,
"if": null,
diff --git a/crates/frecency/src/outbound/postgres.rs b/crates/frecency/src/outbound/postgres.rs
index 27c871fd41..d389386f2e 100644
--- a/crates/frecency/src/outbound/postgres.rs
+++ b/crates/frecency/src/outbound/postgres.rs
@@ -43,6 +43,9 @@ pub enum FrecencyStorageErr {
/// failed to deserialize a type from json
#[error(transparent)]
Serde(#[from] serde_json::Error),
+ /// The dynamic frecency query cannot represent a GitHub pull request filter.
+ #[error("GitHub pull request filters are not supported by frecency queries")]
+ UnsupportedGithubPullRequestFilter,
}
impl FrecencyPgStorage {
@@ -257,6 +260,12 @@ impl AggregateFrecencyStorage for FrecencyPgStorage {
limit,
filters,
} = req;
+ if filters
+ .as_ref()
+ .is_some_and(|filter| filter.github_pull_request_filter.is_some())
+ {
+ return Err(FrecencyStorageErr::UnsupportedGithubPullRequestFilter);
+ }
match filters {
None => {
self.static_get_top_entities(user_id, from_score, limit)
diff --git a/crates/frecency/src/outbound/postgres/dynamic_tests.rs b/crates/frecency/src/outbound/postgres/dynamic_tests.rs
index 9df37d5cbc..d1b0297d38 100644
--- a/crates/frecency/src/outbound/postgres/dynamic_tests.rs
+++ b/crates/frecency/src/outbound/postgres/dynamic_tests.rs
@@ -16,6 +16,30 @@ use std::collections::VecDeque;
use std::sync::Arc;
use uuid::Uuid;
+#[tokio::test]
+async fn pull_request_filters_fail_explicitly_before_database_access() {
+ let pool = PgPool::connect_lazy("postgres://[email protected]:1/unused").unwrap();
+ let storage = FrecencyPgStorage::new(pool);
+ let filter = EntityFilterAst {
+ github_pull_request_filter: Some(Arc::new(Expr::Literal(
+ item_filters::ast::github_pull_request::GithubPullRequestLiteral::Draft(false),
+ ))),
+ ..Default::default()
+ };
+ let result = storage
+ .get_top_entities(FrecencyPageRequest {
+ user_id: MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap(),
+ from_score: None,
+ limit: 10,
+ filters: Some(filter),
+ })
+ .await;
+ assert!(matches!(
+ result,
+ Err(FrecencyStorageErr::UnsupportedGithubPullRequestFilter)
+ ));
+}
+
#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
async fn test_dynamic_filter_by_document_ids(pool: PgPool) {
let storage = FrecencyPgStorage::new(pool.clone());
@@ -966,6 +990,7 @@ async fn test_dynamic_filter_document_date_created_at_gt(pool: PgPool) {
call_filter: None,
crm_company_filter: None,
foreign_entity_filter: None,
+ github_pull_request_filter: None,
reminder_filter: None,
initiative_filter: None,
database_row_filter: None,
@@ -1066,6 +1091,7 @@ async fn test_dynamic_filter_document_date_created_at_lt(pool: PgPool) {
call_filter: None,
crm_company_filter: None,
foreign_entity_filter: None,
+ github_pull_request_filter: None,
reminder_filter: None,
initiative_filter: None,
database_row_filter: None,
@@ -1162,6 +1188,7 @@ async fn test_dynamic_filter_document_date_updated_at_gt(pool: PgPool) {
call_filter: None,
crm_company_filter: None,
foreign_entity_filter: None,
+ github_pull_request_filter: None,
reminder_filter: None,
initiative_filter: None,
database_row_filter: None,
@@ -1263,6 +1290,7 @@ async fn test_dynamic_filter_document_date_updated_at_lt(pool: PgPool) {
call_filter: None,
crm_company_filter: None,
foreign_entity_filter: None,
+ github_pull_request_filter: None,
reminder_filter: None,
initiative_filter: None,
database_row_filter: None,
diff --git a/crates/github_pull_requests/Cargo.toml b/crates/github_pull_requests/Cargo.toml
index 436bd37ec5..d52d470132 100644
--- a/crates/github_pull_requests/Cargo.toml
+++ b/crates/github_pull_requests/Cargo.toml
@@ -8,12 +8,11 @@ version = "0.1.0"
default = ["outbound", "ports", "service"]
outbound = [
"dep:filter_ast",
- "dep:item_filters",
"dep:models_pagination",
"dep:sqlx",
"ports",
]
-ports = ["foreign_entity/ports"]
+ports = ["dep:item_filters", "foreign_entity/ports"]
schema = ["dep:utoipa"]
service = ["ports"]
diff --git a/crates/github_pull_requests/src/domain/ports.rs b/crates/github_pull_requests/src/domain/ports.rs
index 257063dfa4..153929793d 100644
--- a/crates/github_pull_requests/src/domain/ports.rs
+++ b/crates/github_pull_requests/src/domain/ports.rs
@@ -6,6 +6,7 @@ use foreign_entity::domain::{
models::{ForeignEntity, SourceId},
ports::ForeignEntityListQuery,
};
+use item_filters::ast::{LiteralTree, github_pull_request::GithubPullRequestLiteral};
use super::models::{
EnrichedGithubPullRequest, GithubPullRequestError, GithubPullRequestRow,
@@ -93,12 +94,15 @@ pub trait GithubPullRequestListing: Send + Sync + 'static {
/// Up to `limit` pull request records stored for one of `source_ids` and matching `query`,
/// one per pull request, in the query's sort order. `requesting_user` scopes the
/// participant and notification-state filters; without one they match nothing.
+ /// `github_pull_request_filter` keeps only pull requests whose typed columns match it.
+ /// "Updated" sorts by, and reports, GitHub's updated time when the pull request has one.
fn list_pull_requests(
&self,
requesting_user: Option<String>,
source_ids: Vec<SourceId>,
limit: u32,
query: ForeignEntityListQuery,
+ github_pull_request_filter: LiteralTree<GithubPullRequestLiteral>,
) -> impl Future<Output = Result<Vec<ForeignEntity>, GithubPullRequestError>> + Send;
}
@@ -107,13 +111,14 @@ pub trait GithubPullRequestListingRepository: Send + Sync + 'static {
/// Error type returned by repository operations.
type Err: Into<anyhow::Error> + Send + std::fmt::Debug;
- /// Up to `limit` pull request records stored for one of `source_ids` and matching `query`,
- /// one per pull request, in the query's sort order.
+ /// Up to `limit` pull request records stored for one of `source_ids` and matching `query`
+ /// and `github_pull_request_filter`, one per pull request, in the query's sort order.
fn list_pull_requests(
&self,
requesting_user: Option<String>,
source_ids: Vec<SourceId>,
limit: u32,
query: ForeignEntityListQuery,
+ github_pull_request_filter: LiteralTree<GithubPullRequestLiteral>,
) -> impl Future<Output = Result<Vec<ForeignEntity>, Self::Err>> + Send;
}
diff --git a/crates/github_pull_requests/src/domain/service.rs b/crates/github_pull_requests/src/domain/service.rs
index 3ea7118c60..fd8968f4d5 100644
--- a/crates/github_pull_requests/src/domain/service.rs
+++ b/crates/github_pull_requests/src/domain/service.rs
@@ -7,6 +7,7 @@ use foreign_entity::domain::{
models::{CreateForeignEntity, ForeignEntity, PatchForeignEntity, SourceId},
ports::{ForeignEntityListQuery, ForeignEntityService},
};
+use item_filters::ast::{LiteralTree, github_pull_request::GithubPullRequestLiteral};
use super::{
models::{
@@ -274,13 +275,14 @@ where
F: ForeignEntityService,
R: GithubPullRequestListingRepository,
{
- #[tracing::instrument(err, skip(self, source_ids, query))]
+ #[tracing::instrument(err, skip(self, source_ids, query, github_pull_request_filter))]
async fn list_pull_requests(
&self,
requesting_user: Option<String>,
source_ids: Vec<SourceId>,
limit: u32,
query: ForeignEntityListQuery,
+ github_pull_request_filter: LiteralTree<GithubPullRequestLiteral>,
) -> Result<Vec<ForeignEntity>, GithubPullRequestError> {
if source_ids.is_empty() {
return Ok(Vec::new());
@@ -296,6 +298,7 @@ where
source_ids,
limit,
query,
+ github_pull_request_filter,
)
.await
.map_err(repository_error)
diff --git a/crates/github_pull_requests/src/domain/service/test.rs b/crates/github_pull_requests/src/domain/service/test.rs
index f39a374323..098dce1adc 100644
--- a/crates/github_pull_requests/src/domain/service/test.rs
+++ b/crates/github_pull_requests/src/domain/service/test.rs
@@ -3,12 +3,14 @@ use std::sync::{Arc, Mutex};
use chrono::{DateTime, Utc};
use entity_access::domain::models::{EntityAccessReceipt, ViewAccessLevel};
+use filter_ast::Expr;
use foreign_entity::domain::{
models::{
CreateForeignEntity, ForeignEntity, ForeignEntityError, PatchForeignEntity, SourceId,
},
ports::{ForeignEntityListQuery, ForeignEntityService},
};
+use item_filters::ast::{LiteralTree, github_pull_request::GithubPullRequestLiteral};
use models_pagination::{Cursor, CursorVal, Query, SimpleSortMethod};
use uuid::Uuid;
@@ -174,6 +176,7 @@ struct ListingCall {
sort_method: String,
cursor_id: Option<Uuid>,
cursor_value: Option<DateTime<Utc>>,
+ github_pull_request_filter: Option<String>,
}
impl StubPullRequestRows {
@@ -258,6 +261,7 @@ impl GithubPullRequestListingRepository for StubPullRequestRows {
source_ids: Vec<SourceId>,
limit: u32,
query: ForeignEntityListQuery,
+ github_pull_request_filter: LiteralTree<GithubPullRequestLiteral>,
) -> Result<Vec<ForeignEntity>, Self::Err> {
if *self.fail_listings.lock().unwrap() {
anyhow::bail!("listing failed");
@@ -270,6 +274,8 @@ impl GithubPullRequestListingRepository for StubPullRequestRows {
sort_method: query.sort_method().to_string(),
cursor_id: cursor_id.copied(),
cursor_value: cursor_value.copied(),
+ github_pull_request_filter: github_pull_request_filter
+ .map(|filter| format!("{filter:?}")),
});
Ok(Vec::new())
}
@@ -694,7 +700,13 @@ async fn listing_without_sources_skips_the_repository() {
let service = service(&StubForeignEntityService::default(), &rows);
let listed = service
- .list_pull_requests(Some(USER_ID.to_string()), Vec::new(), 10, listing_query())
+ .list_pull_requests(
+ Some(USER_ID.to_string()),
+ Vec::new(),
+ 10,
+ listing_query(),
+ None,
+ )
.await
.unwrap();
@@ -703,11 +715,12 @@ async fn listing_without_sources_skips_the_repository() {
}
#[tokio::test]
-async fn listing_forwards_the_caller_sources_limit_and_query() {
+async fn listing_forwards_the_caller_sources_limit_query_and_pull_request_filter() {
let rows = StubPullRequestRows::default();
let service = service(&StubForeignEntityService::default(), &rows);
let cursor_id = Uuid::new_v4();
let cursor_value = Utc::now();
+ let draft = Arc::new(Expr::val(GithubPullRequestLiteral::Draft(true)));
service
.list_pull_requests(
@@ -723,6 +736,7 @@ async fn listing_forwards_the_caller_sources_limit_and_query() {
},
filter: None,
}),
+ Some(draft.clone()),
)
.await
.unwrap();
@@ -736,6 +750,7 @@ async fn listing_forwards_the_caller_sources_limit_and_query() {
sort_method: "created_at".to_string(),
cursor_id: Some(cursor_id),
cursor_value: Some(cursor_value),
+ github_pull_request_filter: Some(format!("{draft:?}")),
}]
);
}
@@ -746,7 +761,13 @@ async fn listing_rejects_blank_sources() {
let service = service(&StubForeignEntityService::default(), &rows);
let error = service
- .list_pull_requests(None, vec![SourceId::new(" ", "user")], 10, listing_query())
+ .list_pull_requests(
+ None,
+ vec![SourceId::new(" ", "user")],
+ 10,
+ listing_query(),
+ None,
+ )
.await
.unwrap_err();
@@ -767,7 +788,7 @@ async fn listing_reports_repository_failures() {
let service = service(&StubForeignEntityService::default(), &rows);
let error = service
- .list_pull_requests(None, vec![user()], 10, listing_query())
+ .list_pull_requests(None, vec![user()], 10, listing_query(), None)
.await
.unwrap_err();
diff --git a/crates/github_pull_requests/src/outbound/pg_github_pull_request_repo/listing.rs b/crates/github_pull_requests/src/outbound/pg_github_pull_request_repo/listing.rs
index c4b83dd491..9b3d90c72b 100644
--- a/crates/github_pull_requests/src/outbound/pg_github_pull_request_repo/listing.rs
+++ b/crates/github_pull_requests/src/outbound/pg_github_pull_request_repo/listing.rs
@@ -9,7 +9,10 @@ use foreign_entity::domain::{
models::{ForeignEntity, SourceId},
ports::ForeignEntityListQuery,
};
-use item_filters::ast::foreign_entity::ForeignEntityLiteral;
+use item_filters::ast::{
+ LiteralTree, foreign_entity::ForeignEntityLiteral,
+ github_pull_request::GithubPullRequestLiteral,
+};
use models_pagination::SimpleSortMethod;
use uuid::Uuid;
@@ -33,6 +36,8 @@ struct ListingQuery<'a> {
cursor_id: Option<Uuid>,
cursor_value: Option<DateTime<Utc>>,
limit: i64,
+ /// Keeps only pull requests whose typed columns match this jsonpath.
+ github_pull_request_jsonpath: Option<&'a str>,
}
fn source_id_parts(source_ids: &[SourceId]) -> (Vec<String>, Vec<String>) {
@@ -195,6 +200,42 @@ fn foreign_entity_literal_jsonpath(literal: &ForeignEntityLiteral) -> String {
}
}
+fn github_pull_request_expr_jsonpath(expr: &Expr<GithubPullRequestLiteral>) -> String {
+ match expr {
+ Expr::And(left, right) => format!(
+ "({} && {})",
+ github_pull_request_expr_jsonpath(left),
+ github_pull_request_expr_jsonpath(right)
+ ),
+ Expr::Or(left, right) => format!(
+ "({} || {})",
+ github_pull_request_expr_jsonpath(left),
+ github_pull_request_expr_jsonpath(right)
+ ),
+ Expr::Not(inner) => format!("(!{})", github_pull_request_expr_jsonpath(inner)),
+ Expr::Literal(literal) => github_pull_request_literal_jsonpath(literal),
+ }
+}
+
+fn github_pull_request_literal_jsonpath(literal: &GithubPullRequestLiteral) -> String {
+ match literal {
+ GithubPullRequestLiteral::RepositoryId(id) => format!("($.repositoryId == {id})"),
+ GithubPullRequestLiteral::Author(id) => jsonpath_text_eq("authorId", id),
+ GithubPullRequestLiteral::Status(state) => jsonpath_text_eq("status", state.as_str()),
+ GithubPullRequestLiteral::Involves(id) => jsonpath_array_contains("participants", id),
+ GithubPullRequestLiteral::ReviewRequested(id) => {
+ jsonpath_array_contains("requestedReviewers", id)
+ }
+ GithubPullRequestLiteral::Draft(draft) => format!("($.draft == {draft})"),
+ }
+}
+
+fn jsonpath_array_contains(field_name: &str, expected_value: &str) -> String {
+ let expected_value = serde_json::to_string(expected_value)
+ .expect("serializing a string literal to JSON should not fail");
+ format!("($.{field_name}[*] == {expected_value})")
+}
+
fn jsonpath_text_eq(field_name: &str, expected_value: &str) -> String {
let expected_value = serde_json::to_string(expected_value)
.expect("serializing a string literal to JSON should not fail");
@@ -217,6 +258,7 @@ impl PgGithubPullRequestRepo {
cursor_id,
cursor_value,
limit,
+ github_pull_request_jsonpath,
} = query;
let sort_method = sort_method.to_string();
@@ -237,12 +279,13 @@ impl PgGithubPullRequestRepo {
fe.stored_for_id,
fe.stored_for_auth_entity,
fe.created_at,
- fe.updated_at,
+ COALESCE(gpr.github_updated_at, fe.updated_at) AS updated_at,
CASE $3::text
WHEN 'created_at' THEN fe.created_at
- ELSE fe.updated_at
+ ELSE COALESCE(gpr.github_updated_at, fe.updated_at)
END AS sort_at
FROM foreign_entity fe
+ LEFT JOIN github_pull_request gpr ON gpr.github_key = fe.foreign_entity_id
WHERE fe.foreign_entity_source = $11::text
AND EXISTS (
SELECT 1
@@ -265,6 +308,20 @@ impl PgGithubPullRequestRepo {
$8::text[] IS NULL
OR (fe.metadata -> 'participantGithubUserIds') ?| $8::text[]
)
+ AND (
+ $12::text IS NULL
+ OR (gpr.github_key IS NOT NULL AND jsonb_path_match(
+ jsonb_build_object(
+ 'repositoryId', gpr.repository_id,
+ 'authorId', gpr.author_github_user_id,
+ 'status', gpr.status,
+ 'draft', gpr.draft,
+ 'requestedReviewers', to_jsonb(gpr.requested_reviewer_github_user_ids),
+ 'participants', to_jsonb(gpr.participant_github_user_ids)
+ ),
+ ($12::text)::jsonpath
+ ))
+ )
AND (
$9::int[] IS NULL
OR ($10::text IS NOT NULL AND (
@@ -278,7 +335,12 @@ impl PgGithubPullRequestRepo {
AND n.event_item_id = fe.id::text
) = ANY($9::int[]))
)
- ORDER BY fe.foreign_entity_source, fe.foreign_entity_id, sort_at DESC, fe.id DESC
+ ORDER BY
+ fe.foreign_entity_source,
+ fe.foreign_entity_id,
+ sort_at DESC,
+ fe.updated_at DESC,
+ fe.id DESC
)
SELECT
id as "id!: Uuid",
@@ -306,6 +368,7 @@ impl PgGithubPullRequestRepo {
notification_sets,
notification_user_id,
GITHUB_PULL_REQUEST_FOREIGN_ENTITY_SOURCE,
+ github_pull_request_jsonpath,
)
.fetch_all(&self.pool)
.await
@@ -331,13 +394,14 @@ impl PgGithubPullRequestRepo {
impl GithubPullRequestListingRepository for PgGithubPullRequestRepo {
type Err = sqlx::Error;
- #[tracing::instrument(err, skip(self, source_ids, query))]
+ #[tracing::instrument(err, skip(self, source_ids, query, github_pull_request_filter))]
async fn list_pull_requests(
&self,
requesting_user: Option<String>,
source_ids: Vec<SourceId>,
limit: u32,
query: ForeignEntityListQuery,
+ github_pull_request_filter: LiteralTree<GithubPullRequestLiteral>,
) -> Result<Vec<ForeignEntity>, Self::Err> {
if source_ids.is_empty() || limit == 0 {
return Ok(Vec::new());
@@ -394,6 +458,9 @@ impl GithubPullRequestListingRepository for PgGithubPullRequestRepo {
let (source_ids, source_auth_entities) = source_id_parts(&source_ids);
let (cursor_id, cursor_value) = query.vals();
+ let github_pull_request_jsonpath = github_pull_request_filter
+ .as_deref()
+ .map(github_pull_request_expr_jsonpath);
self.fetch_listing(ListingQuery {
source_ids: &source_ids,
@@ -406,6 +473,7 @@ impl GithubPullRequestListingRepository for PgGithubPullRequestRepo {
cursor_id: cursor_id.copied(),
cursor_value: cursor_value.copied(),
limit: limit as i64,
+ github_pull_request_jsonpath: github_pull_request_jsonpath.as_deref(),
})
.await
}
diff --git a/crates/github_pull_requests/src/outbound/pg_github_pull_request_repo/listing/test.rs b/crates/github_pull_requests/src/outbound/pg_github_pull_request_repo/listing/test.rs
index a37e36e33c..a12c0adf33 100644
--- a/crates/github_pull_requests/src/outbound/pg_github_pull_request_repo/listing/test.rs
+++ b/crates/github_pull_requests/src/outbound/pg_github_pull_request_repo/listing/test.rs
@@ -11,7 +11,11 @@ use foreign_entity::{
},
outbound::pg_foreign_entity_repo::PgForeignEntityRepo,
};
-use item_filters::ast::{LiteralTree, foreign_entity::ForeignEntityLiteral};
+use item_filters::ast::{
+ LiteralTree,
+ foreign_entity::ForeignEntityLiteral,
+ github_pull_request::{GithubPullRequestLiteral, GithubPullRequestState},
+};
use macro_db_migrator::MACRO_DB_MIGRATIONS;
use models_pagination::{Cursor, CursorVal, Query, SimpleSortMethod};
use serde_json::json;
@@ -278,6 +282,7 @@ async fn list_returns_matching_user_and_team_sources(pool: PgPool) {
],
10,
list_query(SimpleSortMethod::UpdatedAt),
+ None,
)
.await
.expect("foreign entities should be listed for matching sources");
@@ -309,6 +314,7 @@ async fn list_empty_sources_returns_empty(pool: PgPool) {
Vec::new(),
10,
list_query(SimpleSortMethod::UpdatedAt),
+ None,
)
.await
.expect("empty source list should succeed");
@@ -365,6 +371,7 @@ async fn list_dedupes_duplicate_source_grants(pool: PgPool) {
],
10,
list_query(SimpleSortMethod::UpdatedAt),
+ None,
)
.await
.expect("duplicate foreign entity grants should be listed once");
@@ -433,6 +440,7 @@ async fn list_paginates_by_created_at(pool: PgPool) {
vec![SourceId::user("macro|[email protected]")],
2,
list_query(SimpleSortMethod::CreatedAt),
+ None,
)
.await
.expect("first created_at page should be fetched");
@@ -442,6 +450,7 @@ async fn list_paginates_by_created_at(pool: PgPool) {
vec![SourceId::user("macro|[email protected]")],
2,
cursor_query(&first_page[1], SimpleSortMethod::CreatedAt),
+ None,
)
.await
.expect("second created_at page should be fetched");
@@ -510,6 +519,7 @@ async fn list_paginates_by_updated_at(pool: PgPool) {
vec![SourceId::user("macro|[email protected]")],
2,
list_query(SimpleSortMethod::UpdatedAt),
+ None,
)
.await
.expect("first updated_at page should be fetched");
@@ -519,6 +529,7 @@ async fn list_paginates_by_updated_at(pool: PgPool) {
vec![SourceId::user("macro|[email protected]")],
2,
cursor_query(&first_page[1], SimpleSortMethod::UpdatedAt),
+ None,
)
.await
.expect("second updated_at page should be fetched");
@@ -557,6 +568,7 @@ async fn list_applies_foreign_entity_filters(pool: PgPool) {
vec![SourceId::user("macro|[email protected]")],
10,
filter_query(source_filter),
+ None,
)
.await
.expect("foreign entity source filter should be applied");
@@ -570,6 +582,7 @@ async fn list_applies_foreign_entity_filters(pool: PgPool) {
vec![SourceId::user("macro|[email protected]")],
10,
filter_query(not_linear_filter),
+ None,
)
.await
.expect("foreign entity negated filter should be applied");
@@ -596,6 +609,7 @@ async fn list_includes_me_filters_to_participant_metadata(pool: PgPool) {
vec![SourceId::user(macro_id)],
10,
filter_query(includes_me_filter()),
+ None,
)
.await
.expect("includes_me filter should be applied");
@@ -635,6 +649,7 @@ async fn list_includes_me_matches_every_linked_github_identity(pool: PgPool) {
vec![SourceId::user(macro_id)],
10,
filter_query(includes_me_filter()),
+ None,
)
.await
.expect("includes_me should match both linked identities");
@@ -657,6 +672,7 @@ async fn list_includes_me_without_github_link_returns_empty(pool: PgPool) {
vec![SourceId::user(macro_id)],
10,
filter_query(includes_me_filter()),
+ None,
)
.await
.expect("includes_me without a github link should succeed");
@@ -678,6 +694,7 @@ async fn list_includes_me_without_requesting_user_returns_empty(pool: PgPool) {
vec![SourceId::user(macro_id)],
10,
filter_query(includes_me_filter()),
+ None,
)
.await
.expect("includes_me without a requesting user should succeed");
@@ -708,6 +725,7 @@ async fn list_includes_me_composes_with_other_filters(pool: PgPool) {
vec![SourceId::user(macro_id)],
10,
filter_query(filter),
+ None,
)
.await
.expect("includes_me composed with a source filter should be applied");
@@ -733,6 +751,7 @@ async fn list_includes_me_under_not_fails_closed(pool: PgPool) {
vec![SourceId::user(macro_id)],
10,
filter_query(filter),
+ None,
)
.await
.expect("unsupported includes_me placement should fail closed");
@@ -778,6 +797,7 @@ async fn list_notification_done_filters_by_done_state(pool: PgPool) {
filter_query(notification_states_filter(&[
item_filters::NotificationState::Done,
])),
+ None,
)
.await
.expect("done=true filter should be applied");
@@ -791,6 +811,7 @@ async fn list_notification_done_filters_by_done_state(pool: PgPool) {
item_filters::NotificationState::Unseen,
item_filters::NotificationState::Seen,
])),
+ None,
)
.await
.expect("done=false filter should be applied");
@@ -829,6 +850,7 @@ async fn list_notification_seen_filters_by_seen_state(pool: PgPool) {
item_filters::NotificationState::Seen,
item_filters::NotificationState::Done,
])),
+ None,
)
.await
.expect("seen=true filter should be applied");
@@ -841,6 +863,7 @@ async fn list_notification_seen_filters_by_seen_state(pool: PgPool) {
filter_query(notification_states_filter(&[
item_filters::NotificationState::Unseen,
])),
+ None,
)
.await
.expect("seen=false filter should be applied");
@@ -885,6 +908,7 @@ async fn list_notification_done_composes_with_source(pool: PgPool) {
vec![SourceId::user(macro_id)],
10,
filter_query(filter),
+ None,
)
.await
.expect("source AND notification done filter should be applied");
@@ -918,6 +942,7 @@ async fn list_notification_done_scopes_to_requesting_user(pool: PgPool) {
filter_query(notification_states_filter(&[
item_filters::NotificationState::Done,
])),
+ None,
)
.await
.expect("notification filter scoped to requesting user should be applied");
@@ -944,6 +969,7 @@ async fn list_notification_filter_without_requesting_user_returns_empty(pool: Pg
filter_query(notification_states_filter(&[
item_filters::NotificationState::Done,
])),
+ None,
)
.await
.expect("notification filter without a requesting user should succeed");
@@ -971,6 +997,7 @@ async fn list_notification_state_and_requires_each_witness(pool: PgPool) {
filter_query(notification_states_filter(&[
item_filters::NotificationState::Done,
])),
+ None,
)
.await
.expect("done=true filter should be applied");
@@ -997,6 +1024,7 @@ async fn list_notification_state_and_requires_each_witness(pool: PgPool) {
vec![SourceId::user(macro_id)],
10,
filter_query(contradiction),
+ None,
)
.await
.expect("contradictory notification filter should be applied");
@@ -1025,9 +1053,233 @@ async fn list_excludes_other_foreign_entity_sources(pool: PgPool) {
vec![SourceId::user(macro_id)],
10,
list_query(SimpleSortMethod::UpdatedAt),
+ None,
)
.await
.expect("listing should succeed");
assert_eq!(entities, vec![pull_request]);
}
+
+struct PullRequestRow<'a> {
+ github_key: &'a str,
+ repository_id: i64,
+ number: i64,
+ status: &'a str,
+ author: &'a str,
+ requested_reviewers: &'a [&'a str],
+ participants: &'a [&'a str],
+ github_updated_minutes_ago: i32,
+}
+
+async fn insert_pull_request_row(pool: &PgPool, row: PullRequestRow<'_>) {
+ sqlx::query(
+ r#"
+ INSERT INTO github_pull_request (
+ github_key, repository_id, number, owner, repo, status, author_github_user_id,
+ requested_reviewer_github_user_ids, participant_github_user_ids, github_updated_at
+ )
+ VALUES ($1, $2, $3, 'macro', 'app', $4, $5, $6, $7, NOW() - make_interval(mins => $8::int))
+ "#,
+ )
+ .bind(row.github_key)
+ .bind(row.repository_id)
+ .bind(row.number)
+ .bind(row.status)
+ .bind(row.author)
+ .bind(owned(row.requested_reviewers))
+ .bind(owned(row.participants))
+ .bind(row.github_updated_minutes_ago)
+ .execute(pool)
+ .await
+ .expect("pull request row should be inserted");
+}
+
+fn owned(ids: &[&str]) -> Vec<String> {
+ ids.iter().map(|id| (*id).to_owned()).collect()
+}
+
+async fn list_filtered(
+ listing: &PgGithubPullRequestRepo,
+ github_pull_request_filter: LiteralTree<GithubPullRequestLiteral>,
+) -> Vec<ForeignEntity> {
+ listing
+ .list_pull_requests(
+ None,
+ vec![SourceId::user("macro|[email protected]")],
+ 10,
+ list_query(SimpleSortMethod::UpdatedAt),
+ github_pull_request_filter,
+ )
+ .await
+ .expect("listing should succeed")
+}
+
+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
+async fn list_pull_request_filters_match_the_typed_columns(pool: PgPool) {
+ let repo = PgForeignEntityRepo::new(pool.clone());
+ let listing = PgGithubPullRequestRepo::new(pool.clone());
+ let user = "macro|[email protected]";
+ let open_for_me = insert_foreign_entity_for_source(
+ &repo,
+ "macro/app/pull/1",
+ "github_pull_request",
+ user,
+ "user",
+ )
+ .await;
+ insert_pull_request_row(
+ &pool,
+ PullRequestRow {
+ github_key: "macro/app/pull/1",
+ repository_id: 99,
+ number: 1,
+ status: "open",
+ author: "7",
+ requested_reviewers: &["42"],
+ participants: &["7", "42"],
+ github_updated_minutes_ago: 1,
+ },
+ )
+ .await;
+ let merged = insert_foreign_entity_for_source(
+ &repo,
+ "macro/app/pull/2",
+ "github_pull_request",
+ user,
+ "user",
+ )
+ .await;
+ insert_pull_request_row(
+ &pool,
+ PullRequestRow {
+ github_key: "macro/app/pull/2",
+ repository_id: 99,
+ number: 2,
+ status: "merged",
+ author: "42",
+ requested_reviewers: &[],
+ participants: &["42"],
+ github_updated_minutes_ago: 2,
+ },
+ )
+ .await;
+ let without_row = insert_foreign_entity_for_source(
+ &repo,
+ "macro/app/pull/3",
+ "github_pull_request",
+ user,
+ "user",
+ )
+ .await;
+ let three_minutes_ago = Utc::now() - chrono::Duration::minutes(3);
+ let without_row = set_timestamps(
+ &pool,
+ &repo,
+ &without_row,
+ three_minutes_ago,
+ three_minutes_ago,
+ )
+ .await;
+ let filter = |expr| Some(Arc::new(expr));
+
+ assert_eq!(
+ ids(&list_filtered(
+ &listing,
+ filter(Expr::val(GithubPullRequestLiteral::ReviewRequested(
+ "42".to_owned()
+ )))
+ )
+ .await),
+ vec![open_for_me.id]
+ );
+ assert_eq!(
+ ids(&list_filtered(
+ &listing,
+ filter(Expr::val(GithubPullRequestLiteral::Status(
+ GithubPullRequestState::Merged
+ )))
+ )
+ .await),
+ vec![merged.id]
+ );
+ assert_eq!(
+ ids(&list_filtered(
+ &listing,
+ filter(Expr::and(
+ Expr::val(GithubPullRequestLiteral::RepositoryId(99)),
+ Expr::is_not(Expr::val(GithubPullRequestLiteral::Author("42".to_owned()))),
+ ))
+ )
+ .await),
+ vec![open_for_me.id]
+ );
+ assert_eq!(
+ ids(&list_filtered(
+ &listing,
+ filter(Expr::val(GithubPullRequestLiteral::Involves(
+ "42".to_owned()
+ )))
+ )
+ .await),
+ vec![open_for_me.id, merged.id]
+ );
+ assert_eq!(
+ ids(&list_filtered(&listing, None).await),
+ vec![open_for_me.id, merged.id, without_row.id]
+ );
+}
+
+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]
+async fn list_updated_sort_uses_githubs_updated_at_when_known(pool: PgPool) {
+ let repo = PgForeignEntityRepo::new(pool.clone());
+ let listing = PgGithubPullRequestRepo::new(pool.clone());
+ let user = "macro|[email protected]";
+ let recently_synced = insert_foreign_entity_for_source(
+ &repo,
+ "macro/app/pull/1",
+ "github_pull_request",
+ user,
+ "user",
+ )
+ .await;
+ insert_pull_request_row(
+ &pool,
+ PullRequestRow {
+ github_key: "macro/app/pull/1",
+ repository_id: 99,
+ number: 1,
+ status: "open",
+ author: "7",
+ requested_reviewers: &[],
+ participants: &[],
+ github_updated_minutes_ago: 60,
+ },
+ )
+ .await;
+ let recently_updated = insert_foreign_entity_for_source(
+ &repo,
+ "macro/app/pull/2",
+ "github_pull_request",
+ user,
+ "user",
+ )
+ .await;
+ let thirty_minutes_ago = Utc::now() - chrono::Duration::minutes(30);
+ let recently_updated = set_timestamps(
+ &pool,
+ &repo,
+ &recently_updated,
+ thirty_minutes_ago,
+ thirty_minutes_ago,
+ )
+ .await;
+
+ let listed = list_filtered(&listing, None).await;
+
+ assert_eq!(ids(&listed), vec![recently_updated.id, recently_synced.id]);
+ assert!(
+ listed[1].updated_at < recently_synced.updated_at - chrono::Duration::minutes(59),
+ "the pull request reports GitHub's updated time"
+ );
+}
diff --git a/crates/github_pull_requests/src/outbound/pg_github_pull_request_repo/listing/test/notification_state.rs b/crates/github_pull_requests/src/outbound/pg_github_pull_request_repo/listing/test/notification_state.rs
index a4fcc2da34..34b38fbeac 100644
--- a/crates/github_pull_requests/src/outbound/pg_github_pull_request_repo/listing/test/notification_state.rs
+++ b/crates/github_pull_requests/src/outbound/pg_github_pull_request_repo/listing/test/notification_state.rs
@@ -57,6 +57,7 @@ async fn notification_boolean_filters_match_every_present_state_set(pool: PgPool
vec![SourceId::user(user)],
100,
filter_query(Some(Arc::new(expr))),
+ None,
)
.await
.unwrap()
@@ -78,6 +79,7 @@ async fn notification_boolean_filters_match_every_present_state_set(pool: PgPool
vec![SourceId::user(user)],
100,
filter_query(Some(Arc::new(Expr::is_not(leaf(Done))))),
+ None,
)
.await
.unwrap();
diff --git a/crates/graphql_soup/src/loaders.rs b/crates/graphql_soup/src/loaders.rs
index d9ebf416d4..8cb4253480 100644
--- a/crates/graphql_soup/src/loaders.rs
+++ b/crates/graphql_soup/src/loaders.rs
@@ -419,6 +419,7 @@ fn entity_filter_ast(entities: &[Entity<'static>]) -> Result<EntityFilterAst, So
foreign_entities,
ForeignEntityLiteral::Id(nil),
)),
+ github_pull_request_filter: None,
reminder_filter: Some(literal_tree(reminders, ReminderLiteral::Id(nil))),
agent_session_filter: Some(literal_tree(agent_sessions, AgentSessionLiteral::Id(nil))),
initiative_filter: Some(literal_tree(initiatives, InitiativeLiteral::Id(nil))),
diff --git a/crates/graphql_soup_filter_input/src/lib.rs b/crates/graphql_soup_filter_input/src/lib.rs
index 3bd837bde2..d8326e89ce 100644
--- a/crates/graphql_soup_filter_input/src/lib.rs
+++ b/crates/graphql_soup_filter_input/src/lib.rs
@@ -31,6 +31,7 @@ use item_filters::{
document::DocumentLiteral,
email::{Email, EmailLiteral},
foreign_entity::ForeignEntityLiteral,
+ github_pull_request::{GithubPullRequestLiteral, GithubPullRequestState},
initiative::InitiativeLiteral,
project::ProjectLiteral,
properties::{EntityRefId, PropertiesLiteral, PropertyEntityType, PropertyMatchValue},
@@ -377,6 +378,8 @@ pub struct GraphqlEntityFilterAst {
crm_company_filter: Option<GraphqlCrmCompanyExpr>,
/// The foreign entity filter to apply.
foreign_entity_filter: Option<GraphqlForeignEntityExpr>,
+ /// The GitHub pull request filter to apply, on top of the foreign entity filter.
+ github_pull_request_filter: Option<GraphqlGithubPullRequestExpr>,
/// The reminder filter to apply.
reminder_filter: Option<GraphqlReminderExpr>,
/// The agent session filter to apply.
@@ -417,6 +420,7 @@ impl GraphqlEntityFilterAst {
call_filter: optional_tree(self.call_filter)?,
crm_company_filter: optional_tree(self.crm_company_filter)?,
foreign_entity_filter: optional_tree(self.foreign_entity_filter)?,
+ github_pull_request_filter: optional_tree(self.github_pull_request_filter)?,
reminder_filter: optional_tree(self.reminder_filter)?,
agent_session_filter: optional_tree(self.agent_session_filter)?,
properties_filter: optional_tree(self.properties_filter)?,
@@ -538,6 +542,13 @@ filter_expr_input!(
ForeignEntityLiteral,
"ForeignEntityFilterExpr"
);
+filter_expr_input!(
+ GraphqlGithubPullRequestExpr,
+ GraphqlGithubPullRequestBinaryExpr,
+ GraphqlGithubPullRequestLiteral,
+ GithubPullRequestLiteral,
+ "GithubPullRequestFilterExpr"
+);
filter_expr_input!(
GraphqlReminderExpr,
GraphqlReminderBinaryExpr,
@@ -1264,6 +1275,46 @@ impl IntoFilterExpr<ForeignEntityLiteral> for GraphqlForeignEntityLiteral {
}
}
+/// GraphQL input representing a GitHub pull request literal.
+#[cfg_attr(feature = "server", derive(async_graphql::OneofObject))]
+#[derive(Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
+enum GraphqlGithubPullRequestLiteral {
+ /// The numeric GitHub repository id option.
+ RepositoryId(String),
+ /// The author's numeric GitHub user id option.
+ Author(String),
+ /// The pull request state option.
+ Status(GraphqlGithubPullRequestState),
+ /// The numeric GitHub user id of someone involved in the pull request.
+ Involves(String),
+ /// The numeric GitHub user id of a requested reviewer.
+ ReviewRequested(String),
+ /// The draft option.
+ Draft(bool),
+}
+
+impl IntoFilterExpr<GithubPullRequestLiteral> for GraphqlGithubPullRequestLiteral {
+ /// Convert this value into the expr representation.
+ fn into_expr(self) -> InputResult<Expr<GithubPullRequestLiteral>> {
+ let literal = match self {
+ Self::RepositoryId(id) => {
+ GithubPullRequestLiteral::RepositoryId(id.parse().map_err(|_| {
+ InputError::new(format!(
+ "GithubPullRequestLiteral.repositoryId must be a number, got `{id}`"
+ ))
+ })?)
+ }
+ Self::Author(id) => GithubPullRequestLiteral::Author(id),
+ Self::Status(status) => GithubPullRequestLiteral::Status(status.into_model()),
+ Self::Involves(id) => GithubPullRequestLiteral::Involves(id),
+ Self::ReviewRequested(id) => GithubPullRequestLiteral::ReviewRequested(id),
+ Self::Draft(draft) => GithubPullRequestLiteral::Draft(draft),
+ };
+ Ok(Expr::val(literal))
+ }
+}
+
filter_expr_input!(
GraphqlInitiativeExpr,
GraphqlInitiativeBinaryExpr,
@@ -1337,3 +1388,27 @@ impl IntoFilterExpr<DatabaseRowLiteral> for GraphqlDatabaseRowLiteral {
}))
}
}
+
+/// GraphQL input representing a GitHub pull request state.
+#[cfg_attr(feature = "server", derive(async_graphql::Enum))]
+#[derive(Copy, Clone, Eq, PartialEq, Serialize, Deserialize)]
+#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
+enum GraphqlGithubPullRequestState {
+ /// The open option.
+ Open,
+ /// The closed option.
+ Closed,
+ /// The merged option.
+ Merged,
+}
+
+impl GraphqlGithubPullRequestState {
+ /// Convert this GraphQL state into the filter model.
+ fn into_model(self) -> GithubPullRequestState {
+ match self {
+ Self::Open => GithubPullRequestState::Open,
+ Self::Closed => GithubPullRequestState::Closed,
+ Self::Merged => GithubPullRequestState::Merged,
+ }
+ }
+}
diff --git a/crates/item_filter_index/src/lib.rs b/crates/item_filter_index/src/lib.rs
index 81190cfa58..7d22128cd8 100644
--- a/crates/item_filter_index/src/lib.rs
+++ b/crates/item_filter_index/src/lib.rs
@@ -390,6 +390,10 @@ fn check_soup_flat(
}
}
+ if ast.github_pull_request_filter.is_some() {
+ return Eligibility::Unsupported(UnsupportedReason::Partition("githubPullRequest"));
+ }
+
// These opt-in partitions are empty when omitted. The UI's confine()
// also excludes them with a positive nil ID. Accept only proven emptiness,
// not arbitrary trees over partitions that have no local index.
diff --git a/crates/item_filters/src/ast.rs b/crates/item_filters/src/ast.rs
index 4039d0dae0..b68ddb0a85 100644
--- a/crates/item_filters/src/ast.rs
+++ b/crates/item_filters/src/ast.rs
@@ -15,6 +15,7 @@ use crate::{
database_row::DatabaseRowLiteral,
email::EmailLiteral,
foreign_entity::ForeignEntityLiteral,
+ github_pull_request::GithubPullRequestLiteral,
initiative::InitiativeLiteral,
project::ProjectLiteral,
properties::PropertiesLiteral,
@@ -50,6 +51,8 @@ pub mod document;
pub mod email;
/// contains the ast literal value for foreign entities
pub mod foreign_entity;
+/// contains the ast literal value for GitHub pull requests
+pub mod github_pull_request;
/// Initiative filter literals.
pub mod initiative;
/// contains the ast literal value for projects
@@ -237,6 +240,11 @@ pub struct EntityFilterAst {
#[serde(default, rename = "fef")]
#[cfg_attr(feature = "schema", schema(value_type = serde_json::Value))]
pub foreign_entity_filter: LiteralTree<ForeignEntityLiteral>,
+ /// the filters that should be applied to GitHub pull request records, on top of the foreign
+ /// entity filter
+ #[serde(default, rename = "ghprf")]
+ #[cfg_attr(feature = "schema", schema(value_type = serde_json::Value))]
+ pub github_pull_request_filter: LiteralTree<GithubPullRequestLiteral>,
/// the filters that should be applied to reminders
#[serde(default, rename = "remf")]
#[cfg_attr(feature = "schema", schema(value_type = serde_json::Value))]
@@ -303,6 +311,7 @@ impl EntityFilterAst {
entity_filter.foreign_entity_filters,
)?
.map(Arc::new),
+ github_pull_request_filter: None,
reminder_filter: ReminderFilters::expand_ast(entity_filter.reminder_filters)?
.map(Arc::new),
agent_session_filter: AgentSessionFilters::expand_ast(
@@ -352,6 +361,7 @@ impl EntityFilterAst {
call_filter: None,
crm_company_filter: None,
foreign_entity_filter: None,
+ github_pull_request_filter: None,
reminder_filter: None,
agent_session_filter: None,
initiative_filter: None,
@@ -390,6 +400,7 @@ impl IsEmpty for EntityFilterAst {
call_filter,
crm_company_filter,
foreign_entity_filter,
+ github_pull_request_filter,
reminder_filter,
agent_session_filter,
initiative_filter,
@@ -407,6 +418,7 @@ impl IsEmpty for EntityFilterAst {
&& call_filter.is_none()
&& crm_company_filter.is_none()
&& foreign_entity_filter.is_none()
+ && github_pull_request_filter.is_none()
&& reminder_filter.is_none()
&& agent_session_filter.is_none()
&& initiative_filter.is_none()
diff --git a/crates/item_filters/src/ast/github_pull_request.rs b/crates/item_filters/src/ast/github_pull_request.rs
new file mode 100644
index 0000000000..8be97eec23
--- /dev/null
+++ b/crates/item_filters/src/ast/github_pull_request.rs
@@ -0,0 +1,50 @@
+use serde::{Deserialize, Serialize};
+
+/// The possible literal values in a GitHub pull request filter AST. Every literal matches the
+/// pull request's typed columns, so a record without them never matches.
+#[derive(Debug, Serialize, Deserialize, Clone)]
+pub enum GithubPullRequestLiteral {
+ /// The pull request's repository has this numeric GitHub id, which survives renames and
+ /// transfers.
+ #[serde(rename = "repo")]
+ RepositoryId(i64),
+ /// The pull request was opened by the GitHub user with this numeric id.
+ #[serde(rename = "au")]
+ Author(String),
+ /// The pull request is in this state.
+ #[serde(rename = "st")]
+ Status(GithubPullRequestState),
+ /// The GitHub user with this numeric id takes part in the pull request: author, requested
+ /// reviewer, reviewer, assignee, or commenter.
+ #[serde(rename = "inv")]
+ Involves(String),
+ /// A review is requested from the GitHub user with this numeric id.
+ #[serde(rename = "rr")]
+ ReviewRequested(String),
+ /// Whether the pull request is a draft.
+ #[serde(rename = "draft")]
+ Draft(bool),
+}
+
+/// The lifecycle state of a GitHub pull request.
+#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
+#[serde(rename_all = "lowercase")]
+pub enum GithubPullRequestState {
+ /// The pull request is open.
+ Open,
+ /// The pull request was closed without being merged.
+ Closed,
+ /// The pull request was merged.
+ Merged,
+}
+
+impl GithubPullRequestState {
+ /// The state as stored in the `github_pull_request.status` column.
+ pub fn as_str(self) -> &'static str {
+ match self {
+ Self::Open => "open",
+ Self::Closed => "closed",
+ Self::Merged => "merged",
+ }
+ }
+}
diff --git a/crates/skills/src/outbound/soup_skill_lister.rs b/crates/skills/src/outbound/soup_skill_lister.rs
index 0d99bda1ad..0a32f56ed1 100644
--- a/crates/skills/src/outbound/soup_skill_lister.rs
+++ b/crates/skills/src/outbound/soup_skill_lister.rs
@@ -69,6 +69,7 @@ fn skill_only_filter() -> EntityFilterAst {
foreign_entity_filter: Some(Arc::new(Expr::val(ForeignEntityLiteral::Id(Uuid::nil())))),
calendar_event_filter: Some(Arc::new(Expr::val(CalendarEventLiteral::Id(Uuid::nil())))),
// Reminders are opt-in: leaving the filter empty excludes them.
+ github_pull_request_filter: None,
reminder_filter: None,
initiative_filter: None,
// Agent sessions and database rows are opt-in as well.
diff --git a/crates/soup/src/domain/models.rs b/crates/soup/src/domain/models.rs
index 08c0752d99..6363d191b9 100644
--- a/crates/soup/src/domain/models.rs
+++ b/crates/soup/src/domain/models.rs
@@ -18,11 +18,12 @@ use github_pull_requests::domain::models::GithubPullRequestError;
use item_filters::{
EntityFilters,
ast::{
- EntityFilterAst, ExpandErr,
+ EntityFilterAst, ExpandErr, LiteralTree,
calendar_event::CalendarEventLiteral,
call::CallLiteral,
crm_company::CrmCompanyLiteral,
email::EmailLiteral,
+ github_pull_request::GithubPullRequestLiteral,
properties::{
PropertiesLiteral, PropertyEntityType, properties_filter_can_apply_to,
properties_filter_matches_propertyless,
@@ -833,6 +834,12 @@ impl SoupRequest<Option<EntityFilterAst>> {
}
}
+ /// The request's GitHub pull request filter, which narrows its foreign entity leg.
+ pub(crate) fn build_github_pull_request_filter(&self) -> LiteralTree<GithubPullRequestLiteral> {
+ self.entity_ast()
+ .and_then(|ast| ast.github_pull_request_filter.clone())
+ }
+
pub(crate) fn build_foreign_entity_source_ids(
&self,
team_receipt: Option<&EntityAccessReceipt<MemberTeamRole>>,
diff --git a/crates/soup/src/domain/service.rs b/crates/soup/src/domain/service.rs
index 7f1bdceb7e..a76aaac738 100644
--- a/crates/soup/src/domain/service.rs
+++ b/crates/soup/src/domain/service.rs
@@ -36,10 +36,11 @@ use frecency::domain::{
};
use github_pull_requests::domain::ports::GithubPullRequestListing;
use item_filters::ast::{
- EntityFilterAst,
+ EntityFilterAst, LiteralTree,
channel::{ChannelLiteral, ChannelThreadLiteral},
email::EmailLiteral,
foreign_entity::ForeignEntityLiteral,
+ github_pull_request::GithubPullRequestLiteral,
};
use macro_user_id::user_id::MacroUserIdStr;
use model_entity::{Entity, EntityType};
@@ -117,6 +118,8 @@ struct NotifiedHydrationLegs {
comms: Option<GetChannelsRequest>,
comms_threads: Option<GetThreadReplyRowsRequest>,
foreign_entities: Option<(Vec<SourceId>, ForeignEntityListQuery)>,
+ /// Narrows the foreign entity leg to matching GitHub pull requests.
+ github_pull_request_filter: LiteralTree<GithubPullRequestLiteral>,
reminders: Option<GetRemindersRequest<'static>>,
}
@@ -1066,6 +1069,7 @@ where
foreign_entity_sources,
foreign_entity_ids.len() as u32,
foreign_entity_query,
+ legs.github_pull_request_filter.clone(),
),
self.handle_reminder_request(reminder_request),
);
@@ -1288,13 +1292,14 @@ where
Ok(Either::Right(items.into_iter().map(SoupCandidate::plain)))
}
- #[tracing::instrument(err, skip(self, source_ids, query))]
+ #[tracing::instrument(err, skip(self, source_ids, query, github_pull_request_filter))]
async fn handle_foreign_entity_request(
&self,
requesting_user: Option<String>,
source_ids: Vec<SourceId>,
limit: u32,
query: Option<ForeignEntityListQuery>,
+ github_pull_request_filter: LiteralTree<GithubPullRequestLiteral>,
) -> Result<impl Iterator<Item = SoupCandidate>, SoupErr> {
let Some(query) = query else {
return Ok(Either::Left(None.into_iter()));
@@ -1302,7 +1307,13 @@ where
Ok(Either::Right(
self.github_pull_request_service
- .list_pull_requests(requesting_user, source_ids, limit, query)
+ .list_pull_requests(
+ requesting_user,
+ source_ids,
+ limit,
+ query,
+ github_pull_request_filter,
+ )
.await?
.into_iter()
.map(|entity| SoupCandidate::plain(foreign_entity_to_soup_item(entity))),
@@ -1581,6 +1592,7 @@ where
let metadata_source_ids = foreign_entity_source_ids.clone();
let metadata_user = req.user.to_string();
let foreign_entity_query = req.build_foreign_entity_query();
+ let github_pull_request_filter = req.build_github_pull_request_filter();
let email_request = req.build_email_request(team_receipt);
let comms_request = req.build_comms_request();
let comms_thread_request = req.build_comms_thread_request();
@@ -1628,6 +1640,7 @@ where
foreign_entity_source_ids,
limit as u32,
foreign_entity_query,
+ github_pull_request_filter,
);
let (
@@ -1717,6 +1730,7 @@ where
comms_threads: comms_thread_request,
foreign_entities: foreign_entity_query
.map(|query| (foreign_entity_source_ids, query)),
+ github_pull_request_filter,
reminders: reminder_request,
};
let (candidates, next) = self
diff --git a/crates/soup/src/domain/service/agent_metadata.rs b/crates/soup/src/domain/service/agent_metadata.rs
index b1ceb4ad47..a4f2aeb73b 100644
--- a/crates/soup/src/domain/service/agent_metadata.rs
+++ b/crates/soup/src/domain/service/agent_metadata.rs
@@ -79,6 +79,7 @@ pub(super) async fn enrich<F: GithubPullRequestListing>(
sources,
keys.len() as u32,
Query::new(None, SimpleSortMethod::UpdatedAt, Some(ids)),
+ None,
)
.await
.map_err(anyhow::Error::from)
diff --git a/crates/soup/src/domain/service/tests.rs b/crates/soup/src/domain/service/tests.rs
index 4cf70db0b5..0a260f1390 100644
--- a/crates/soup/src/domain/service/tests.rs
+++ b/crates/soup/src/domain/service/tests.rs
@@ -23,7 +23,10 @@ use frecency::{domain::models::AggregateFrecency, outbound::mock::MockFrecencySt
use github_pull_requests::domain::models::GithubPullRequestError;
use item_filters::{
ChannelThreadFilters, EntityFilters, ForeignEntityFilters,
- ast::{EntityFilterAst, foreign_entity::ForeignEntityLiteral},
+ ast::{
+ EntityFilterAst, LiteralTree, foreign_entity::ForeignEntityLiteral,
+ github_pull_request::GithubPullRequestLiteral,
+ },
};
use model_entity::EntityType;
use model_owner::Owner;
@@ -271,6 +274,7 @@ impl GithubPullRequestListing for NoopPullRequestListing {
_source_ids: Vec<SourceId>,
_limit: u32,
_query: ForeignEntityListQuery,
+ _github_pull_request_filter: LiteralTree<GithubPullRequestLiteral>,
) -> Result<Vec<ForeignEntity>, GithubPullRequestError> {
Ok(Vec::new())
}
@@ -292,6 +296,7 @@ struct RecordedPullRequestListingCall {
source_ids: Vec<SourceId>,
limit: u32,
query: ForeignEntityListQuery,
+ github_pull_request_filter: LiteralTree<GithubPullRequestLiteral>,
}
fn foreign_entity_matches_filter(
@@ -355,6 +360,7 @@ impl GithubPullRequestListing for RecordingPullRequestListing {
source_ids: Vec<SourceId>,
limit: u32,
query: ForeignEntityListQuery,
+ github_pull_request_filter: LiteralTree<GithubPullRequestLiteral>,
) -> Result<Vec<ForeignEntity>, GithubPullRequestError> {
let filter = query.filter().clone();
@@ -367,6 +373,7 @@ impl GithubPullRequestListing for RecordingPullRequestListing {
source_ids: source_ids.clone(),
limit,
query,
+ github_pull_request_filter,
});
Ok(self
@@ -775,6 +782,58 @@ async fn simple_soup_includes_foreign_entities() {
assert!(calls[0].query.filter().is_none());
}
+#[tokio::test]
+async fn simple_soup_passes_the_github_pull_request_filter_to_the_listing() {
+ let user = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
+ let pull_request_listing = RecordingPullRequestListing::new(Vec::new());
+ let mut soup_mock = MockSoupRepo::new();
+ soup_mock
+ .expect_unexpanded_generic_cursor_soup()
+ .times(1)
+ .returning(|_params| Box::pin(async move { Ok(Vec::new()) }));
+ let draft = Arc::new(Expr::val(GithubPullRequestLiteral::Draft(true)));
+
+ SoupImpl::new(
+ soup_mock,
+ FrecencyQueryServiceImpl::new(MockFrecencyStorage::new()),
+ NoopEmailPreviewService,
+ NoopCommsService,
+ NoopCallRecordQueryService,
+ NoOpCrmService,
+ pull_request_listing.clone(),
+ NoOpRemindersService,
+ )
+ .get_user_soup(
+ SoupRequest {
+ sort_direction: SoupSortDirection::default(),
+ email_preview_view: PreviewView::StandardLabel(
+ email::domain::models::PreviewViewStandardLabel::Inbox,
+ ),
+ link_ids: vec![],
+ soup_type: SoupType::UnExpanded,
+ limit: 20,
+ cursor: SoupQuery::new_sort_simple(
+ SimpleSortMethod::UpdatedAt,
+ EntityFilterAst {
+ github_pull_request_filter: Some(draft.clone()),
+ ..EntityFilterAst::mock_empty()
+ },
+ ),
+ user: user.clone(),
+ },
+ None,
+ )
+ .await
+ .unwrap();
+
+ let calls = pull_request_listing.calls();
+ assert_eq!(calls.len(), 1);
+ assert_eq!(
+ format!("{:?}", calls[0].github_pull_request_filter),
+ format!("{:?}", Some(draft))
+ );
+}
+
#[tokio::test]
async fn frecency_soup_does_not_query_foreign_entities() {
let user = MacroUserIdStr::parse_from_str("macro|[email protected]").unwrap();
diff --git a/crates/soup/src/inbound/axum_router.rs b/crates/soup/src/inbound/axum_router.rs
index d49f466d00..8f02d374af 100644
--- a/crates/soup/src/inbound/axum_router.rs
+++ b/crates/soup/src/inbound/axum_router.rs
@@ -44,6 +44,7 @@ use item_filters::{
document::DocumentLiteral,
email::EmailLiteral,
foreign_entity::ForeignEntityLiteral,
+ github_pull_request::GithubPullRequestLiteral,
project::ProjectLiteral,
properties::{PropertiesLiteral, PropertyEntityType},
reminder::ReminderLiteral,
@@ -1225,6 +1226,10 @@ pub struct ApiEntityFilterAst {
#[serde(default, rename = "fef")]
#[schema(value_type = serde_json::Value)]
pub foreign_entity_filter: LiteralTree<ForeignEntityLiteral>,
+ /// the filters that should be applied to GitHub pull request records, on top of `fef`
+ #[serde(default, rename = "ghprf")]
+ #[schema(value_type = serde_json::Value)]
+ pub github_pull_request_filter: LiteralTree<GithubPullRequestLiteral>,
/// the filters that should be applied to the call entity
#[serde(default, rename = "callf")]
#[schema(value_type = serde_json::Value)]
@@ -1345,6 +1350,7 @@ impl ApiEntityFilterAst {
channel_filter,
channel_thread_filter,
foreign_entity_filter,
+ github_pull_request_filter,
call_filter,
crm_company_filter,
reminder_filter,
@@ -1417,6 +1423,7 @@ impl ApiEntityFilterAst {
call_filter,
crm_company_filter,
foreign_entity_filter,
+ github_pull_request_filter,
reminder_filter,
agent_session_filter,
properties_filter,
diff --git a/crates/soup/src/inbound/toolset/list_entities.rs b/crates/soup/src/inbound/toolset/list_entities.rs
index 6aa54ed994..837f9eda83 100644
--- a/crates/soup/src/inbound/toolset/list_entities.rs
+++ b/crates/soup/src/inbound/toolset/list_entities.rs
@@ -576,6 +576,7 @@ impl ListEntities {
foreign_entity_filter: self.foreign_entity_filter.clone(),
// Reminders are opt-in in Soup, so leaving this unset is already
// what keeps them out of the tool surface — no force-filter needed.
+ github_pull_request_filter: None,
reminder_filter: None,
// Agent sessions are opt-in too; unset keeps them off the tool surface.
agent_session_filter: None,
@@ -656,6 +657,7 @@ impl ListEntities {
Some(Arc::new(Expr::val(ForeignEntityLiteral::Id(Uuid::nil()))))
},
// Same as CrmCompany — no ItemType::Reminder to toggle against.
+ github_pull_request_filter: None,
reminder_filter: ast.reminder_filter,
agent_session_filter: ast.agent_session_filter,
initiative_filter: None,
diff --git a/crates/soup/src/outbound/pg_soup_repo/expanded/tests.rs b/crates/soup/src/outbound/pg_soup_repo/expanded/tests.rs
index b8d5c85c8a..103116c3d9 100644
--- a/crates/soup/src/outbound/pg_soup_repo/expanded/tests.rs
+++ b/crates/soup/src/outbound/pg_soup_repo/expanded/tests.rs
@@ -5908,6 +5908,7 @@ fn mock_empty_ast() -> EntityFilterAst {
call_filter: None,
crm_company_filter: None,
foreign_entity_filter: None,
+ github_pull_request_filter: None,
reminder_filter: None,
agent_session_filter: None,
initiative_filter: None,
diff --git a/packages/sdk/generated/storage/types.gen.ts b/packages/sdk/generated/storage/types.gen.ts
index 54d9b53a7a..67eecc99a5 100644
--- a/packages/sdk/generated/storage/types.gen.ts
+++ b/packages/sdk/generated/storage/types.gen.ts
@@ -771,6 +771,10 @@ export type ApiEntityFilterAst = {
* the filters that should be applied to foreign entity records
*/
fef?: unknown;
+ /**
+ * the filters that should be applied to GitHub pull request records, on top of `fef`
+ */
+ ghprf?: unknown;
/**
* the filters that should be applied to the project entity
*/
diff --git a/packages/sdk/specs/storage.json b/packages/sdk/specs/storage.json
index b4487fdd30..1042243b6f 100644
--- a/packages/sdk/specs/storage.json
+++ b/packages/sdk/specs/storage.json
@@ -17323,6 +17323,9 @@
"fef": {
"description": "the filters that should be applied to foreign entity records"
},
+ "ghprf": {
+ "description": "the filters that should be applied to GitHub pull request records, on top of `fef`"
+ },
"pf": {
"description": "the filters that should be applied to the project entity"
},
diff --git a/static_assets/schema.graphql b/static_assets/schema.graphql
index 4994cdc5e5..e014723147 100644
--- a/static_assets/schema.graphql
+++ b/static_assets/schema.graphql
@@ -2381,6 +2381,10 @@ input GraphqlEntityFilterAst {
"""
foreignEntityFilter: GraphqlForeignEntityExpr
"""
+ The GitHub pull request filter to apply, on top of the foreign entity filter.
+ """
+ githubPullRequestFilter: GraphqlGithubPullRequestExpr
+ """
The reminder filter to apply.
"""
reminderFilter: GraphqlReminderExpr
@@ -3224,6 +3228,90 @@ type GraphqlGithubPrStatusChangedMetadata {
mergedAt: String
}
+"""
+The two operands of a recursive `GithubPullRequestFilterExpr` binary expression.
+"""
+input GraphqlGithubPullRequestBinaryExpr {
+ """
+ Left expression.
+ """
+ left: GraphqlGithubPullRequestExpr!
+ """
+ Right expression.
+ """
+ right: GraphqlGithubPullRequestExpr!
+}
+
+"""
+A recursive `GithubPullRequestFilterExpr` filter expression.
+"""
+input GraphqlGithubPullRequestExpr @oneOf {
+ """
+ Both expressions must match.
+ """
+ and: GraphqlGithubPullRequestBinaryExpr
+ """
+ Either expression may match.
+ """
+ or: GraphqlGithubPullRequestBinaryExpr
+ """
+ Negate an expression.
+ """
+ not: GraphqlGithubPullRequestExpr
+ """
+ Match a literal.
+ """
+ literal: GraphqlGithubPullRequestLiteral
+}
+
+"""
+GraphQL input representing a GitHub pull request literal.
+"""
+input GraphqlGithubPullRequestLiteral @oneOf {
+ """
+ The numeric GitHub repository id option.
+ """
+ repositoryId: String
+ """
+ The author's numeric GitHub user id option.
+ """
+ author: String
+ """
+ The pull request state option.
+ """
+ status: GraphqlGithubPullRequestState
+ """
+ The numeric GitHub user id of someone involved in the pull request.
+ """
+ involves: String
+ """
+ The numeric GitHub user id of a requested reviewer.
+ """
+ reviewRequested: String
+ """
+ The draft option.
+ """
+ draft: Boolean
+}
+
+"""
+GraphQL input representing a GitHub pull request state.
+"""
+enum GraphqlGithubPullRequestState {
+ """
+ The open option.
+ """
+ OPEN
+ """
+ The closed option.
+ """
+ CLOSED
+ """
+ The merged option.
+ """
+ MERGED
+}
+
"""
Metadata for a GitHub pull-request review request.
"""