Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": [
"octocat@github.com"
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