Skip to content

Commit

Permalink
scrape.js: Check if property repositories exists
Browse files Browse the repository at this point in the history
Fixes coala#160
  • Loading branch information
li-boxuan committed Oct 26, 2018
1 parent b8a3d81 commit 696579b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/scrape.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,9 @@ async function fetchLeaders(id) {
let repositoryInfo = {}
async function fetchRepositoryInfo(org) {
if (repositoryInfo[org]) return repositoryInfo[org]
const { data, errors } = await client.query(GITHUB_REPO_INFO_QUERY, { org })

const { data } = await client.query(GITHUB_REPO_INFO_QUERY, { org })

if (data) {
if (data && data.organization) {
const info = data.organization.repositories.nodes.map(node => ({
watchers: node.watchers.nodes,
stargazers: node.stargazers.nodes,
Expand All @@ -139,6 +138,11 @@ async function fetchRepositoryInfo(org) {

return info
} else {
const errorMessage =
errors && errors.length ? errors[0].message : 'unknown error'
console.warn(
`Cannot fetch org ${org} from GitHub, error message: ${errorMessage}`
)
return []
}
}
Expand Down Expand Up @@ -591,7 +595,11 @@ async function fetchOrgsWithData() {
const orgWiki = await Promise.all(fetchingWiki)

const fetchingAll = orgs.map(async (org, index) => {
await fetchRepositoryInfo(orgGitHub[index])
if (orgGitHub[index]) {
await fetchRepositoryInfo(orgGitHub[index])
} else {
console.warn(`Skip ${orgGitHub[index]} value in orgGitHub`)
}

const existingOrg = existingData.find(existing => existing.id === org.id)
const fetchingUsers = orgLeaders[index].map(async user => {
Expand Down

0 comments on commit 696579b

Please sign in to comment.