Skip to content

Commit 5e9e708

Browse files
bcomnesvoxpelli
andauthored
Make github options nullable (#5)
* Make github options nullable This way, users can opt into global/org defaults. This was a woops. Here is the pattern: collections default to 0 vale, concrete values should be nullable. * Minor tweak Co-authored-by: Pelle Wessman <[email protected]>
1 parent f5ae0c3 commit 5e9e708

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

index.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ const { socketYmlSchemaV1 } = require('./lib/v1')
1010

1111
/**
1212
* @typedef SocketYmlGitHub
13-
* @property {boolean} enabled enable/disable the Socket.dev GitHub app entirely
14-
* @property {boolean} projectReportsEnabled enable/disable Github app project report checks
15-
* @property {boolean} pullRequestAlertsEnabled enable/disable GitHub app pull request alert checks
13+
* @property {boolean} [enabled] enable/disable the Socket.dev GitHub app entirely
14+
* @property {boolean} [projectReportsEnabled] enable/disable Github app project report checks
15+
* @property {boolean} [pullRequestAlertsEnabled] enable/disable GitHub app pull request alert checks
1616
*/
1717

1818
/**
@@ -43,13 +43,13 @@ const socketYmlSchema = {
4343
githubApp: {
4444
type: 'object',
4545
properties: {
46-
enabled: { type: 'boolean', default: true },
47-
projectReportsEnabled: { type: 'boolean', default: true },
48-
pullRequestAlertsEnabled: { type: 'boolean', default: true },
46+
enabled: { type: 'boolean', nullable: true },
47+
projectReportsEnabled: { type: 'boolean', nullable: true },
48+
pullRequestAlertsEnabled: { type: 'boolean', nullable: true },
4949
},
5050
required: [],
5151
additionalProperties: false,
52-
default: { enabled: true, projectReportsEnabled: true, pullRequestAlertsEnabled: true }
52+
default: {}
5353
},
5454
},
5555
required: ['version'],
@@ -180,11 +180,12 @@ async function parseV1SocketConfig (parsedV1Content) {
180180
projectIgnorePaths: parsedV1Content?.ignore ?? [],
181181
issueRules: parsedV1Content?.issues ?? {},
182182
githubApp: {
183-
enabled: Boolean(parsedV1Content?.enabled),
184-
pullRequestAlertsEnabled: Boolean(parsedV1Content?.pullRequestAlertsEnabled),
185-
projectReportsEnabled: Boolean(parsedV1Content?.projectReportsEnabled)
183+
...('enabled' in parsedV1Content ? { enabled: parsedV1Content.enabled } : {}),
184+
...('pullRequestAlertsEnabled' in parsedV1Content ? { pullRequestAlertsEnabled: parsedV1Content.pullRequestAlertsEnabled } : {}),
185+
...('projectReportsEnabled' in parsedV1Content ? { projectReportsEnabled: parsedV1Content.projectReportsEnabled } : {}),
186186
}
187187
}
188+
188189
return v2
189190
}
190191

test/parse.spec.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ chai.use(chaiAsPromised)
1515
chai.should()
1616

1717
const defaults = {
18-
'githubApp': {
19-
'enabled': true,
20-
'projectReportsEnabled': true,
21-
'pullRequestAlertsEnabled': true,
22-
},
18+
'githubApp': {},
2319
'issueRules': {},
2420
'projectIgnorePaths': [],
2521
}

0 commit comments

Comments
 (0)