Skip to content

Commit bcc7729

Browse files
authored
get schema audit log event 'fields' (#49769)
1 parent 18f7487 commit bcc7729

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

src/audit-logs/lib/index.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ export function getAuditLogEvents(page, version, categorized = false) {
6767
categorizedEvents[category] = []
6868
}
6969

70-
categorizedEvents[category].push({
71-
action: event.action,
72-
description: event.description,
73-
})
70+
categorizedEvents[category].push(event)
7471
})
7572

7673
return categorizedEvents
@@ -106,6 +103,7 @@ export function filterByAllowlistValues(
106103
action: event.action,
107104
description: event.description,
108105
docs_reference_links: event.docs_reference_links,
106+
fields: event.fields,
109107
}
110108

111109
if (
@@ -173,6 +171,7 @@ export function filterAndUpdateGhesDataByAllowlistValues(
173171
action: event.action,
174172
description: event.description,
175173
docs_reference_links: event.docs_reference_links,
174+
fields: event.ghes[ghesVersion].fields,
176175
}
177176

178177
if (ghesVersionAllowlists.includes(allowListValue)) {

src/audit-logs/tests/unit/filter-events.js

+34-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
} from '../../lib/index.js'
55

66
describe('audit log event fitering', () => {
7-
it('match single allowlist value', () => {
7+
it('matches single allowlist value', () => {
88
const eventsToProcess = [
99
{
1010
action: 'repo.create',
@@ -17,7 +17,7 @@ describe('audit log event fitering', () => {
1717
expect(filteredEvents[0].action).toEqual('repo.create')
1818
})
1919

20-
it('match multiple allowlist values', () => {
20+
it('matches multiple allowlist values', () => {
2121
const eventsToProcess = [
2222
{
2323
action: 'repo.create',
@@ -36,7 +36,7 @@ describe('audit log event fitering', () => {
3636
expect(filteredEvents.length).toEqual(2)
3737
})
3838

39-
it('non-match allowlist value', () => {
39+
it('does not match non-matching allowlist value', () => {
4040
const eventsToProcess = [
4141
{
4242
action: 'repo.create',
@@ -49,7 +49,7 @@ describe('audit log event fitering', () => {
4949
expect(filteredEvents.length).toBe(0)
5050
})
5151

52-
it('ghes filter and update multiple ghes versions', () => {
52+
it('ghes filters and updates multiple ghes versions', () => {
5353
const eventsToProcess = [
5454
{
5555
action: 'repo.create',
@@ -100,4 +100,34 @@ describe('audit log event fitering', () => {
100100
expect(getActions('ghes-3.11').includes('repo.create')).toBe(true)
101101
expect(auditLogPage in currentEvents['ghes-3.12']).toBeFalsy()
102102
})
103+
104+
it('gets the correct event fields data', () => {
105+
const eventsToProcess = [
106+
{
107+
action: 'repo.create',
108+
_allowlists: ['user'],
109+
description: 'repo was created',
110+
fields: ['beep'],
111+
ghes: {
112+
'3.10': {
113+
_allowlists: ['user'],
114+
fields: ['boop'],
115+
},
116+
},
117+
},
118+
]
119+
const filteredEvents = filterByAllowlistValues(eventsToProcess, 'user')
120+
expect(filteredEvents[0].fields).toContain('beep')
121+
122+
const currentEvents = {}
123+
const auditLogPage = 'user'
124+
filterAndUpdateGhesDataByAllowlistValues(
125+
eventsToProcess,
126+
'user',
127+
currentEvents,
128+
{},
129+
auditLogPage,
130+
)
131+
expect(currentEvents['ghes-3.10'].user[0].fields).toContain('boop')
132+
})
103133
})

0 commit comments

Comments
 (0)