Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function getOwner({ login }) {
let owner = await Organization.query()
.where({ login })
.limit(1)
.first()
if (owner) {
owner.type = OWNER_TYPES.organization
return owner
}
owner = await User.query()
.where({ login })
.limit(1)
.first()
if (owner) {
owner.type = OWNER_TYPES.user
return owner
}
return null
}
async synchronizeUser(githubUser) {
const data = { githubId: githubUser.id, login: githubUser.login }
let user = await User.query()
.where({ githubId: githubUser.id })
.limit(1)
.first()
if (user) {
await user.$query().patchAndFetch(data)
} else {
user = await User.query().insert(data)
}
return user
}
async synchronizeUser(githubUser) {
const data = { githubId: githubUser.id, login: githubUser.login }
let user = await User.query()
.where({ githubId: githubUser.id })
.limit(1)
.first()
if (user) {
await user.$query().patchAndFetch(data)
} else {
user = await User.query().insert(data)
}
return user
}
export async function getOwner({ login }) {
let owner = await Organization.query()
.where({ login })
.limit(1)
.first()
if (owner) {
owner.type = 'organization'
return owner
}
owner = await User.query()
.where({ login })
.limit(1)
.first()
if (owner) {
owner.type = 'user'
return owner
}
return null
}
accessToken,
previousAccessToken: user.accessToken,
privateSync,
})
user = await user.$query().patchAndFetch({
...authorizationState,
privateSync,
...getDataFromProfile(profile),
})
} else {
const privateSync = type === 'private'
const authorizationState = await getUserAuthorizationState({
accessToken,
privateSync,
})
user = await User.query().insert({
...authorizationState,
privateSync,
...getDataFromProfile(profile),
})
}
syncFromUserId(user.id)
done(null, user)
} catch (err) {
Sentry.captureException(err)
done(err)
}
},
),
static getUsers(buildId) {
return User.query()
.select('users.*')
.join(
'user_repository_rights',
'users.id',
'=',
'user_repository_rights.userId',
)
.join(
'repositories',
'user_repository_rights.repositoryId',
'=',
'repositories.id',
)
.join('builds', 'repositories.id', '=', 'builds.repositoryId')
.where('builds.id', buildId)
}
passport.deserializeUser(async (id, done) => {
try {
done(null, await User.query().findById(id))
} catch (err) {
Sentry.captureException(err)
done(err)
}
})
}
async owners(rootObj, args, context) {
const organizations = await context.user.$relatedQuery('organizations')
const users = await User.query()
.distinct('users.id')
.select('users.*')
.innerJoin('repositories', 'repositories.userId', 'users.id')
.innerJoin(
'user_repository_rights',
'user_repository_rights.repositoryId',
'repositories.id',
)
.where('user_repository_rights.userId', context.user.id)
return [
...organizations.map(organization => ({
...organization,
type: OWNER_TYPES.organization,
})),
...users.map(user => ({ ...user, type: OWNER_TYPES.user })),