Skip to content

Commit 01f5710

Browse files
authored
feat(search): list a person's GitLab activity in list_my_activity (#10570)
* feat(search): list a person's GitLab activity in list_my_activity GitLab administrator sources and member GitLab accounts report the viewer's own events (issues and merge requests opened, changed, approved or commented on, and branch pushes) as activity. An administrator source reads the events of the GitLab user with the viewer's verified email, keeps only the projects and collections the source serves, and verifies every entry like a search result. * fix(search): read GitLab member activity from the user's events, map pushed, and leave diff comment text out of activity
1 parent 541a669 commit 01f5710

7 files changed

Lines changed: 415 additions & 8 deletions

File tree

‎apps/sim/lib/sim-search/live/account-session.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,12 @@ export async function openLiveAccountSession(
276276
return connectionBinding ? { ...page, documents: page.documents.map(bind) } : page
277277
},
278278
async activity(request) {
279-
if (admin || !client)
279+
if (!client)
280280
throw new NativeSearchError('unavailable', 'This source does not report activity.')
281-
const page = await activityNativeProvider(provider, client, {
282-
...request,
283-
policy: boundary.policy,
284-
signal: request.signal ?? signal,
285-
})
281+
const scoped = { ...request, policy: boundary.policy, signal: request.signal ?? signal }
282+
const page = admin
283+
? await admin.activity(scoped)
284+
: await activityNativeProvider(provider, client, scoped)
286285
if (!connectionBinding) return page
287286
return {
288287
...page,

‎apps/sim/lib/sim-search/live/activity-paging.integration.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,16 @@ it('names the connected sources it does not cover once, not as a status each', a
194194
expect(result.unsupported?.sources).toEqual(['notion', 'coda'])
195195
expect(result.sources.map(({ source }) => source)).toEqual(['slack'])
196196
})
197+
198+
it('reads a GitLab administrator source, whose entries are the viewer’s own verified events', async () => {
199+
fakes.accounts = [
200+
{
201+
account: { ...account('gitlab-source', 'gitlab'), type: 'admin_source' },
202+
items: items('gitlab', 2, 3, 5),
203+
readSize: 3,
204+
},
205+
]
206+
const result = await listMyActivity.execute({ principal, input: { organizationId } })
207+
expect(result.items.map(({ title }) => title)).toEqual(['gitlab-0', 'gitlab-1'])
208+
expect(result.unsupported).toBeUndefined()
209+
})

‎apps/sim/lib/sim-search/live/activity-providers.test.ts‎

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { describe, expect, it, vi } from 'vitest'
55
import { atlassianActivity } from '@/lib/sim-search/live/atlassian'
66
import { githubActivity } from '@/lib/sim-search/live/github'
7+
import { gitLabActivity, gitLabMemberActivity } from '@/lib/sim-search/live/gitlab-activity'
78
import { calendarActivity, driveActivity, gmailActivity } from '@/lib/sim-search/live/google'
89
import { linearActivity } from '@/lib/sim-search/live/linear'
910
import { slackActivity } from '@/lib/sim-search/live/slack'
@@ -627,3 +628,151 @@ describe('Linear activity format', () => {
627628
await expect(linearActivity(api, WINDOW)).rejects.toThrow('unsupported result format')
628629
})
629630
})
631+
632+
describe('GitLab activity', () => {
633+
const event = (id: number, at: string, project: number, fields: Record<string, unknown>) => ({
634+
id,
635+
project_id: project,
636+
created_at: at,
637+
...fields,
638+
})
639+
/** Answers the member's events a page at a time and each project's lookup. */
640+
const gitlab = (pages: Record<string, unknown>[][], projects: number[] = [42]) =>
641+
client((path, options) => {
642+
if (path === '/api/v4/user') return { id: 7 }
643+
if (path === '/api/v4/users/7/events') return pages[Number(options?.query?.page) - 1] ?? []
644+
const project = /^\/api\/v4\/projects\/(\d+)$/.exec(path)?.[1]
645+
if (project && projects.includes(Number(project)))
646+
return { web_url: `https://git.example.com/team/p${project}` }
647+
return undefined
648+
})
649+
650+
it('reports what the member opened, commented on, approved and pushed, leaving out internal notes and diff comment text', async () => {
651+
const api = gitlab([
652+
[
653+
event(5, '2026-11-07T10:00:00Z', 42, {
654+
action_name: 'opened',
655+
target_type: 'MergeRequest',
656+
target_iid: 3,
657+
target_title: 'Retry uploads',
658+
}),
659+
event(4, '2026-11-06T10:00:00Z', 42, {
660+
action_name: 'commented on',
661+
target_type: 'DiffNote',
662+
target_title: 'Retry uploads',
663+
note: { body: 'Rename this file', noteable_type: 'MergeRequest', noteable_iid: 3 },
664+
}),
665+
event(3, '2026-11-05T10:00:00Z', 42, {
666+
action_name: 'commented on',
667+
target_type: 'Note',
668+
note: { body: 'Secret', noteable_type: 'Issue', noteable_iid: 9, internal: true },
669+
}),
670+
event(2, '2026-11-04T10:00:00Z', 42, {
671+
action_name: 'approved',
672+
target_type: 'MergeRequest',
673+
target_iid: 3,
674+
}),
675+
event(1, '2026-11-03T10:00:00Z', 42, {
676+
action_name: 'pushed',
677+
push_data: { ref_type: 'branch', commit_to: 'a'.repeat(40), commit_title: 'Fix' },
678+
}),
679+
],
680+
])
681+
const [stream] = (await gitLabMemberActivity(api, WINDOW)).streams
682+
expect(
683+
stream?.events.map(({ document, action }) => [
684+
document.kind,
685+
document.id,
686+
action,
687+
document.url,
688+
])
689+
).toEqual([
690+
['merge_requests', '3', 'created', 'https://git.example.com/team/p42/-/merge_requests/3'],
691+
['merge_requests', '3', 'commented', 'https://git.example.com/team/p42/-/merge_requests/3'],
692+
['merge_requests', '3', 'involved', 'https://git.example.com/team/p42/-/merge_requests/3'],
693+
[
694+
'commits',
695+
'a'.repeat(40),
696+
'committed',
697+
`https://git.example.com/team/p42/-/commit/${'a'.repeat(40)}`,
698+
],
699+
])
700+
expect(stream?.events[1]?.document.content).not.toContain('Rename this file')
701+
expect(stream?.more).toBe(false)
702+
})
703+
704+
it('reads past events newer than the bound and reports where it stopped when it reaches none', async () => {
705+
const newer = Array.from({ length: 20 }, (_, index) =>
706+
event(
707+
100 - index,
708+
`2026-11-08T0${Math.floor(index / 10)}:00:${String(index % 10).padStart(2, '0')}Z`,
709+
42,
710+
{
711+
action_name: 'updated',
712+
target_type: 'Issue',
713+
target_iid: index,
714+
}
715+
)
716+
)
717+
const api = gitlab([newer.slice(0, 15), newer.slice(15, 20)])
718+
const [stream] = (
719+
await gitLabMemberActivity(api, { ...WINDOW, end: '2026-11-07T23:59:59.000Z', limit: 15 })
720+
).streams
721+
expect(stream?.events).toEqual([])
722+
expect(stream?.more).toBe(false)
723+
const full = gitlab([newer.slice(0, 15), newer.slice(0, 15), newer.slice(0, 15)])
724+
const [capped] = (
725+
await gitLabMemberActivity(full, { ...WINDOW, end: '2026-11-07T23:59:59.000Z', limit: 15 })
726+
).streams
727+
expect(capped?.more).toBe(true)
728+
expect(Date.parse(capped?.scannedTo ?? '')).toBeGreaterThan(Date.parse('2026-11-07T23:59:59Z'))
729+
})
730+
731+
it('stops at an event whose project it cannot look up yet, so the next page resumes there', async () => {
732+
const rows = [42, 43, 44, 45, 46, 47].map((project, index) =>
733+
event(10 - index, `2026-11-0${7 - index}T10:00:00Z`, project, {
734+
action_name: 'opened',
735+
target_type: 'Issue',
736+
target_iid: index + 1,
737+
})
738+
)
739+
const api = gitlab([rows], [42, 43, 44, 45, 46, 47])
740+
const [stream] = (await gitLabMemberActivity(api, WINDOW)).streams
741+
expect(stream?.events).toHaveLength(5)
742+
expect(stream).toMatchObject({ more: true, scannedTo: '2026-11-02T10:00:00.000Z' })
743+
})
744+
745+
it('leaves out events in projects or collections an administrator source does not serve', async () => {
746+
const api = client((path) =>
747+
path === '/api/v4/users/7/events'
748+
? [
749+
event(3, '2026-11-06T10:00:00Z', 42, {
750+
action_name: 'opened',
751+
target_type: 'Issue',
752+
target_iid: 1,
753+
}),
754+
event(2, '2026-11-05T10:00:00Z', 99, {
755+
action_name: 'opened',
756+
target_type: 'MergeRequest',
757+
target_iid: 2,
758+
}),
759+
event(1, '2026-11-04T10:00:00Z', 42, {
760+
action_name: 'opened',
761+
target_type: 'MergeRequest',
762+
target_iid: 3,
763+
}),
764+
]
765+
: undefined
766+
)
767+
const [stream] = (
768+
await gitLabActivity(api, WINDOW, {
769+
path: '/api/v4/users/7/events',
770+
kinds: new Set(['merge_requests']),
771+
projectUrl: async (id) => (id === '42' ? 'https://git.example.com/team/p42' : undefined),
772+
})
773+
).streams
774+
expect(stream?.events.map(({ document }) => [document.container, document.id])).toEqual([
775+
['42', '3'],
776+
])
777+
})
778+
})

‎apps/sim/lib/sim-search/live/activity.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ export const listMyActivity = defineAuthorizedKnowledgeUseCase({
266266
const readable = (account: LiveAccount) =>
267267
supportsActivity(account.provider) &&
268268
account.type !== 'managed_mcp' &&
269-
account.type !== 'admin_source'
269+
/** GitLab's administrator sources read the viewer's own events, verified per project. */
270+
(account.type !== 'admin_source' || account.provider === 'gitlab')
270271
const eligible = accounts.filter(readable)
271272
const selected = cursor
272273
? eligible.filter((account) => cursor.accounts[account.id])

0 commit comments

Comments
 (0)