Skip to content

Commit 2d062a6

Browse files
heiskrCopilot
andauthored
🧹 Filter audit-log sync to only supported GHES versions (#61110)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3aec09b commit 2d062a6

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

‎src/audit-logs/lib/index.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import path from 'path'
22

33
import { readCompressedJsonFileFallback } from '@/frame/lib/read-json-file'
44
import { getOpenApiVersion } from '@/versions/lib/all-versions'
5+
import { supported as supportedGhesReleases } from '@/versions/lib/enterprise-server-releases'
56
import findPage from '@/frame/lib/find-page'
67
import type { Context, Page } from '@/types'
78
import type {
@@ -300,6 +301,7 @@ export async function filterAndUpdateGhesDataByAllowlistValues({
300301
auditLogPage,
301302
titleContext,
302303
globalFields = [],
304+
supportedGhesVersions = supportedGhesReleases,
303305
}: {
304306
eventsToCheck: RawAuditLogEventT[]
305307
allowListValue: string
@@ -308,9 +310,17 @@ export async function filterAndUpdateGhesDataByAllowlistValues({
308310
auditLogPage: string
309311
titleContext?: TitleResolutionContext
310312
globalFields?: string[]
313+
supportedGhesVersions?: string[]
311314
}) {
312315
if (!currentGhesEvents) currentGhesEvents = {}
313316

317+
// Upstream `audit-log-allowlists/data/schema.json` lags docs's deprecation
318+
// schedule, so events still list `ghes` keys for versions we've already
319+
// dropped from `supported` in `enterprise-server-releases.ts`. Without this
320+
// filter, the nightly sync would re-add `src/audit-logs/data/ghes-X.Y/`
321+
// dirs for those deprecated versions. See docs-engineering#6562.
322+
const supportedGhesVersionSet = new Set(supportedGhesVersions)
323+
314324
const seenByGhesVersion = new Map()
315325
for (const [ghesVersion, events] of Object.entries(currentGhesEvents)) {
316326
if (!events[auditLogPage]) continue
@@ -320,6 +330,7 @@ export async function filterAndUpdateGhesDataByAllowlistValues({
320330

321331
for (const event of eventsToCheck) {
322332
for (const ghesVersion of Object.keys(event.ghes)) {
333+
if (!supportedGhesVersionSet.has(ghesVersion)) continue
323334
const ghesVersionAllowlists = event.ghes[ghesVersion]._allowlists
324335
const fullGhesVersion = `ghes-${ghesVersion}`
325336

‎src/audit-logs/tests/unit/filter-events.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,50 @@ describe('audit log event filtering', () => {
223223
appendedDescriptions: {},
224224
},
225225
auditLogPage,
226+
supportedGhesVersions: ['3.10', '3.11', '3.12'],
226227
})
227228
const getActions = (version: string) =>
228229
currentEvents[version][auditLogPage].map((event) => event.action)
229230
expect(getActions('ghes-3.10').includes('repo.create')).toBe(true)
230231
expect(getActions('ghes-3.11').includes('repo.create')).toBe(true)
231232
expect(auditLogPage in currentEvents['ghes-3.12']).toBeFalsy()
232233
})
234+
235+
test('ghes skips versions not in the supported list', async () => {
236+
const eventsToProcess: RawAuditLogEventT[] = [
237+
{
238+
action: 'repo.create',
239+
description: 'repo was created',
240+
docs_reference_links: '',
241+
_allowlists: [],
242+
ghes: {
243+
'3.14': {
244+
_allowlists: ['user'],
245+
},
246+
'3.15': {
247+
_allowlists: ['user'],
248+
},
249+
},
250+
},
251+
]
252+
253+
const currentEvents: VersionedAuditLogData = {}
254+
const auditLogPage = 'user'
255+
256+
await filterAndUpdateGhesDataByAllowlistValues({
257+
eventsToCheck: eventsToProcess,
258+
allowListValue: 'user',
259+
currentGhesEvents: currentEvents,
260+
pipelineConfig: {
261+
sha: '',
262+
appendedDescriptions: {},
263+
},
264+
auditLogPage,
265+
supportedGhesVersions: ['3.15'],
266+
})
267+
expect(currentEvents['ghes-3.14']).toBeUndefined()
268+
expect(currentEvents['ghes-3.15'][auditLogPage].map((event) => event.action)).toContain(
269+
'repo.create',
270+
)
271+
})
233272
})

0 commit comments

Comments
 (0)