Skip to content

Commit

Permalink
Merge pull request #27 from secure-dashboards/feat/add-gh-response-va…
Browse files Browse the repository at this point in the history
…lidation
  • Loading branch information
UlisesGascon authored Dec 5, 2024
2 parents d23033b + 6acb57c commit eea9838
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/schemas/githubOrganization.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,19 @@
]
},
"name": {
"type": "string",
"type": [
"string",
"null"
],
"examples": [
"github"
]
},
"company": {
"type": "string",
"type": [
"string",
"null"
],
"examples": [
"GitHub"
]
Expand All @@ -101,13 +107,19 @@
]
},
"location": {
"type": "string",
"type": [
"string",
"null"
],
"examples": [
"San Francisco"
]
},
"email": {
"type": "string",
"type": [
"string",
"null"
],
"format": "email",
"examples": [
"[email protected]"
Expand Down
3 changes: 2 additions & 1 deletion src/schemas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const validateGithubOrg = (data) => {
const validate = ajv.compile(githubOrganizationSchema)
const valid = validate(data)
if (!valid) {
throw new Error(validate.errors.map((error) => error.message).join('\n'))
const readableErrors = validate.errors.map((error) => `[ERROR: ${error.keyword}]${error.schemaPath}: ${error.message}`).join('\n')
throw new Error(`Error when validating the Github org response from API: ${readableErrors}`)
}
return null
}
Expand Down
3 changes: 3 additions & 0 deletions src/workflows/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { simplifyObject } = require('@ulisesgascon/simplify-object')
const { github } = require('../providers')
const { initializeStore } = require('../store')
const { logger } = require('../utils')
const { validateGithubOrg } = require('../schemas')

const mapOrgData = (data) => {
const mappedData = simplifyObject(data, {
Expand Down Expand Up @@ -47,6 +48,8 @@ const updateGithubOrgs = async (knex) => {
await Promise.all(organizations.map(async (org) => {
debug(`Fetching details for org (${org.login})`)
const data = await github.fetchOrgByLogin(org.login)
debug('Validating data')
validateGithubOrg(data)
debug('Transforming data')
const mappedData = mapOrgData(data)
debug('Updating organization in database')
Expand Down

0 comments on commit eea9838

Please sign in to comment.