How to use organizationStillExists method in argos

Best JavaScript code snippet using argos

github.js

Source:github.js Github

copy

Full Screen

1/* eslint-disable no-await-in-loop */2import {3 getAuthorizationOctokit,4 getUserOctokit,5 getInstallationOctokit,6} from 'modules/github/client'7import {8 Installation,9 Organization,10 Repository,11 User,12 UserOrganizationRight,13 UserRepositoryRight,14 UserInstallationRight,15 InstallationRepositoryRight,16} from 'models'17import config from 'config'18export async function getOrCreateInstallation(payload) {19 const installation = await Installation.query()20 .where({ githubId: payload.githubId })21 .first()22 if (installation) return installation23 return Installation.query().insertAndFetch(payload)24}25async function checkAccessTokenValidity(accessToken) {26 try {27 await getAuthorizationOctokit().oauthAuthorizations.checkAuthorization({28 access_token: accessToken,29 client_id: config.get('github.clientId'),30 })31 } catch (error) {32 if (error.status === 404) {33 return false34 }35 throw error36 }37 return true38}39const OWNER_ORGANIZATION = 'Organization'40const OWNER_USER = 'User'41export class GitHubSynchronizer {42 constructor(synchronization) {43 this.synchronization = synchronization44 this.repositories = []45 this.organizationIds = []46 }47 async synchronizeAppRepositories(installationId) {48 const options = this.octokit.apps.listRepos.endpoint.DEFAULTS49 const githubRepositories = await this.octokit.paginate(options)50 const { repositories, organizations } = await this.synchronizeRepositories(51 githubRepositories,52 )53 await this.synchronizeInstallationRepositoryRights(54 repositories,55 installationId,56 )57 return { repositories, organizations }58 }59 async synchronizeUserInstallationRepositories(installation) {60 const options = this.octokit.apps.listInstallationReposForAuthenticatedUser.endpoint.merge(61 { installation_id: installation.githubId },62 )63 const githubRepositories = await this.octokit.paginate(options)64 const { repositories, organizations } = await this.synchronizeRepositories(65 githubRepositories,66 )67 await this.synchronizeInstallationRepositoryRights(68 repositories,69 installation.id,70 )71 return { repositories, organizations }72 }73 async synchronizeRepositories(githubRepositories) {74 const [75 {76 owners: organizations,77 ownerIdByRepositoryId: organizationIdByRepositoryId,78 },79 { ownerIdByRepositoryId: userIdByRepositoryId },80 ] = await Promise.all([81 this.synchronizeOwners(githubRepositories, OWNER_ORGANIZATION),82 this.synchronizeOwners(githubRepositories, OWNER_USER),83 ])84 const repositories = await Promise.all(85 githubRepositories.map(async githubRepository => {86 const data = {87 githubId: githubRepository.id,88 name: githubRepository.name,89 organizationId: organizationIdByRepositoryId[githubRepository.id],90 userId: userIdByRepositoryId[githubRepository.id],91 private: githubRepository.private,92 }93 let [repository] = await Repository.query().where({94 githubId: githubRepository.id,95 })96 if (githubRepository.archived) {97 data.archived = true98 }99 if (repository) {100 await repository.$query().patchAndFetch(data)101 } else {102 repository = await Repository.query().insert({103 ...data,104 baselineBranch: githubRepository.default_branch,105 config: {106 files: [{ test: '*.js', maxSize: '10 mB' }],107 },108 })109 }110 return repository111 }),112 )113 return { repositories, organizations }114 }115 async synchronizeOwners(githubRepositories, type) {116 const githubOwners = githubRepositories.reduce(117 (githubOwners, githubRepository) => {118 if (githubRepository.owner.type !== type) {119 return githubOwners120 }121 let githubOwner = githubOwners.find(122 ({ id }) => id === githubRepository.owner.id,123 )124 if (!githubOwner) {125 githubOwner = githubRepository.owner126 githubOwners.push(githubRepository.owner)127 }128 return githubOwners129 },130 [],131 )132 let owners133 switch (type) {134 case OWNER_ORGANIZATION:135 owners = await Promise.all(136 githubOwners.map(githubOwner =>137 this.synchronizeOrganization(githubOwner),138 ),139 )140 break141 case OWNER_USER:142 owners = await Promise.all(143 githubOwners.map(githubOwner => this.synchronizeUser(githubOwner)),144 )145 break146 default:147 throw new Error(`Unsupported type ${type}`)148 }149 return {150 owners,151 ownerIdByRepositoryId: githubRepositories.reduce(152 (ownerIdByRepositoryId, githubRepository) => {153 if (githubRepository.owner.type === type) {154 ownerIdByRepositoryId[githubRepository.id] = owners.find(155 owner => owner.githubId === githubRepository.owner.id,156 ).id157 }158 return ownerIdByRepositoryId159 },160 {},161 ),162 }163 }164 // eslint-disable-next-line class-methods-use-this165 async synchronizeOrganization(githubOrganization) {166 const organizationData = await this.octokit.orgs.get({167 org: githubOrganization.login,168 })169 githubOrganization = organizationData.data170 let [organization] = await Organization.query().where({171 githubId: githubOrganization.id,172 })173 const data = {174 githubId: githubOrganization.id,175 name: githubOrganization.name,176 login: githubOrganization.login,177 }178 if (organization) {179 await organization.$query().patchAndFetch(data)180 } else {181 organization = await Organization.query().insert(data)182 }183 return organization184 }185 // eslint-disable-next-line class-methods-use-this186 async synchronizeUser(githubUser) {187 const data = { githubId: githubUser.id, login: githubUser.login }188 let user = await User.query()189 .where({ githubId: githubUser.id })190 .first()191 if (user) {192 await user.$query().patchAndFetch(data)193 } else {194 user = await User.query().insert(data)195 }196 return user197 }198 async synchronizeInstallationRepositoryRights(repositories, installationId) {199 const installationRepositoryRights = await InstallationRepositoryRight.query().where(200 {201 installationId,202 },203 )204 await Promise.all(205 repositories.map(async repository => {206 const hasRights = installationRepositoryRights.some(207 ({ repositoryId }) => repositoryId === repository.id,208 )209 if (!hasRights) {210 await InstallationRepositoryRight.query().insert({211 installationId,212 repositoryId: repository.id,213 })214 }215 }),216 )217 await Promise.all(218 installationRepositoryRights.map(async installationRepositoryRight => {219 const repositoryStillExists = repositories.find(220 ({ id }) => id === installationRepositoryRight.repositoryId,221 )222 if (!repositoryStillExists) {223 await installationRepositoryRight.$query().delete()224 }225 }),226 )227 }228 async synchronizeRepositoryRights(repositories, userId) {229 const userRepositoryRights = await UserRepositoryRight.query().where({230 userId,231 })232 await Promise.all(233 repositories.map(async repository => {234 const hasRights = userRepositoryRights.some(235 ({ repositoryId }) => repositoryId === repository.id,236 )237 if (!hasRights) {238 await UserRepositoryRight.query().insert({239 userId,240 repositoryId: repository.id,241 })242 }243 }),244 )245 await Promise.all(246 userRepositoryRights.map(async userRepositoryRight => {247 const repositoryStillExists = repositories.find(248 ({ id }) => id === userRepositoryRight.repositoryId,249 )250 if (!repositoryStillExists) {251 await userRepositoryRight.$query().delete()252 }253 }),254 )255 }256 async synchronizeOrganizationRights(organizations, userId) {257 const userOrganizationRights = await UserOrganizationRight.query().where({258 userId,259 })260 await Promise.all(261 organizations.map(async organization => {262 const hasRights = userOrganizationRights.some(263 ({ organizationId }) => organizationId === organization.id,264 )265 if (!hasRights) {266 await UserOrganizationRight.query().insert({267 userId,268 organizationId: organization.id,269 })270 }271 }),272 )273 await Promise.all(274 userOrganizationRights.map(async userOrganizationRight => {275 const organizationStillExists = organizations.find(276 ({ id }) => id === userOrganizationRight.organizationId,277 )278 if (!organizationStillExists) {279 await userOrganizationRight.$query().delete()280 }281 }),282 )283 }284 async synchronizeUserInstallations() {285 const options = this.octokit.apps.listInstallationsForAuthenticatedUser286 .endpoint.DEFAULTS287 const githubInstallations = await this.octokit.paginate(options)288 return Promise.all(289 githubInstallations.map(async githubInstallation => {290 return getOrCreateInstallation({291 githubId: githubInstallation.id,292 deleted: false,293 })294 }),295 )296 }297 async synchronizeUserInstallationRights(installations, userId) {298 const userInstallationRights = await UserInstallationRight.query().where({299 userId,300 })301 await Promise.all(302 installations.map(async installation => {303 const exists = userInstallationRights.some(304 ({ installationId }) => installationId === installation.id,305 )306 if (!exists) {307 await UserInstallationRight.query().insertAndFetch({308 userId,309 installationId: installation.id,310 })311 }312 }),313 )314 await Promise.all(315 userInstallationRights.map(async userInstallationRight => {316 const installationStillExists = installations.find(317 ({ id }) => id === userInstallationRight.installationId,318 )319 if (!installationStillExists) {320 await userInstallationRight.$query().delete()321 }322 }),323 )324 return installations325 }326 async synchronize() {327 this.synchronization = await this.synchronization.$query()328 switch (this.synchronization.type) {329 case 'installation':330 return this.synchronizeFromInstallation(331 this.synchronization.installationId,332 )333 case 'user':334 return this.synchronizeFromUser(this.synchronization.userId)335 default:336 throw new Error(337 `Unknown synchronization type "${this.synchronization.type}"`,338 )339 }340 }341 async synchronizeFromInstallation(installationId) {342 const installation = await Installation.query()343 .findById(installationId)344 .eager('users')345 if (installation.deleted) {346 await Promise.all(347 installation.users.map(async user => this.synchronizeFromUser(user.id)),348 )349 await this.synchronizeInstallationRepositoryRights([], installationId)350 return351 }352 this.octokit = getInstallationOctokit(installation)353 await this.synchronizeAppRepositories(installationId)354 await Promise.all(355 installation.users.map(async user => this.synchronizeFromUser(user.id)),356 )357 }358 async synchronizeFromUser(userId) {359 const user = await User.query().findById(userId)360 const tokenValid = await checkAccessTokenValidity(user.accessToken)361 if (!tokenValid) {362 await this.synchronizeUserInstallationRights([], userId)363 await Promise.all([364 this.synchronizeRepositoryRights([], userId),365 this.synchronizeOrganizationRights([], userId),366 ])367 return368 }369 this.octokit = getUserOctokit(user)370 const installations = await this.synchronizeUserInstallations(userId)371 await this.synchronizeUserInstallationRights(installations, userId)372 const results = await Promise.all(373 installations.map(installation =>374 this.synchronizeUserInstallationRepositories(installation),375 ),376 )377 const { repositories, organizations } = results.reduce(378 (all, result) => {379 all.repositories = [...all.repositories, ...result.repositories]380 all.organizations = [...all.organizations, ...result.organizations]381 return all382 },383 { repositories: [], organizations: [] },384 )385 await Promise.all([386 this.synchronizeRepositoryRights(repositories, userId),387 this.synchronizeOrganizationRights(organizations, userId),388 ])389 }...

Full Screen

Full Screen

GitHubSynchronizer.js

Source:GitHubSynchronizer.js Github

copy

Full Screen

1import GitHubAPI from 'github'2import config from 'config'3import Organization from 'server/models/Organization'4import Repository from 'server/models/Repository'5import User from 'server/models/User'6import UserOrganizationRight from 'server/models/UserOrganizationRight'7import UserRepositoryRight from 'server/models/UserRepositoryRight'8const OWNER_ORGANIZATION = 'Organization'9const OWNER_USER = 'User'10class GitHubSynchronizer {11 constructor(synchronization) {12 this.synchronization = synchronization13 this.github = new GitHubAPI({ debug: config.get('env') === 'development' })14 this.repositories = []15 this.organizationIds = []16 }17 async synchronizeRepositories({ page = 1 } = {}) {18 const githubRepositories = await this.github.repos.getAll({ page, per_page: 100 })19 const [20 { owners: organizations, ownerIdByRepositoryId: organizationIdByRepositoryId },21 { ownerIdByRepositoryId: userIdByRepositoryId },22 ] = await Promise.all([23 this.synchronizeOwners(githubRepositories, OWNER_ORGANIZATION),24 this.synchronizeOwners(githubRepositories, OWNER_USER),25 ])26 const repositories = await Promise.all(27 githubRepositories.data.map(async githubRepository => {28 const data = {29 githubId: githubRepository.id,30 name: githubRepository.name,31 organizationId: organizationIdByRepositoryId[githubRepository.id],32 userId: userIdByRepositoryId[githubRepository.id],33 private: githubRepository.private,34 }35 let [repository] = await Repository.query().where({ githubId: githubRepository.id })36 if (repository) {37 await repository.$query().patchAndFetch(data)38 } else {39 repository = await Repository.query().insert({40 ...data,41 baselineBranch: 'master',42 enabled: false,43 })44 }45 return repository46 })47 )48 if (this.github.hasNextPage(githubRepositories)) {49 const nextPageData = await this.synchronizeRepositories({ page: page + 1 })50 nextPageData.repositories.forEach(repository => {51 if (!repositories.find(({ id }) => id === repository.id)) {52 repositories.push(repository)53 }54 })55 nextPageData.organizations.forEach(organization => {56 if (!organizations.find(({ id }) => id === organization.id)) {57 organizations.push(organization)58 }59 })60 }61 return { repositories, organizations }62 }63 async synchronizeOwners(githubRepositories, type) {64 const githubOwners = githubRepositories.data.reduce((githubOwners, githubRepository) => {65 if (githubRepository.owner.type !== type) {66 return githubOwners67 }68 let githubOwner = githubOwners.find(({ id }) => id === githubRepository.owner.id)69 if (!githubOwner) {70 githubOwner = githubRepository.owner71 githubOwners.push(githubRepository.owner)72 }73 return githubOwners74 }, [])75 let owners76 switch (type) {77 case OWNER_ORGANIZATION:78 owners = await Promise.all(79 githubOwners.map(githubOwner => this.synchronizeOrganization(githubOwner))80 )81 break82 case OWNER_USER:83 owners = await Promise.all(84 githubOwners.map(githubOwner => this.synchronizeUser(githubOwner))85 )86 break87 default:88 throw new Error(`Unsupported type ${type}`)89 }90 return {91 owners,92 ownerIdByRepositoryId: githubRepositories.data.reduce(93 (ownerIdByRepositoryId, githubRepository) => {94 if (githubRepository.owner.type === type) {95 ownerIdByRepositoryId[githubRepository.id] = owners.find(96 owner => owner.githubId === githubRepository.owner.id97 ).id98 }99 return ownerIdByRepositoryId100 },101 {}102 ),103 }104 }105 // eslint-disable-next-line class-methods-use-this106 async synchronizeOrganization(githubOrganization) {107 const organizationData = await this.github.orgs.get({ org: githubOrganization.login })108 githubOrganization = organizationData.data109 let [organization] = await Organization.query().where({ githubId: githubOrganization.id })110 const data = {111 githubId: githubOrganization.id,112 name: githubOrganization.name,113 login: githubOrganization.login,114 }115 if (organization) {116 await organization.$query().patchAndFetch(data)117 } else {118 organization = await Organization.query().insert(data)119 }120 return organization121 }122 // eslint-disable-next-line class-methods-use-this123 async synchronizeUser(githubUser) {124 const data = { githubId: githubUser.id, login: githubUser.login }125 let user = await User.query()126 .where({ githubId: githubUser.id })127 .limit(1)128 .first()129 if (user) {130 await user.$query().patchAndFetch(data)131 } else {132 user = await User.query().insert(data)133 }134 return user135 }136 async synchronizeRepositoryRights(repositories) {137 const userRepositoryRights = await UserRepositoryRight.query().where({138 userId: this.synchronization.user.id,139 })140 await Promise.all(141 repositories.map(async repository => {142 const hasRights = userRepositoryRights.some(143 ({ repositoryId }) => repositoryId === repository.id144 )145 if (!hasRights) {146 await UserRepositoryRight.query().insert({147 userId: this.synchronization.user.id,148 repositoryId: repository.id,149 })150 }151 })152 )153 await Promise.all(154 userRepositoryRights.map(async userRepositoryRight => {155 const repositoryStillExists = repositories.find(156 ({ id }) => id === userRepositoryRight.repositoryId157 )158 if (!repositoryStillExists) {159 await userRepositoryRight.$query().delete()160 }161 })162 )163 }164 async synchronizeOrganizationRights(organizations) {165 const userOrganizationRights = await UserOrganizationRight.query().where({166 userId: this.synchronization.user.id,167 })168 await Promise.all(169 organizations.map(async organization => {170 const hasRights = userOrganizationRights.some(171 ({ organizationId }) => organizationId === organization.id172 )173 if (!hasRights) {174 await UserOrganizationRight.query().insert({175 userId: this.synchronization.user.id,176 organizationId: organization.id,177 })178 }179 })180 )181 await Promise.all(182 userOrganizationRights.map(async userOrganizationRight => {183 const organizationStillExists = organizations.find(184 ({ id }) => id === userOrganizationRight.organizationId185 )186 if (!organizationStillExists) {187 await userOrganizationRight.$query().delete()188 }189 })190 )191 }192 async synchronize() {193 this.synchronization = await this.synchronization.$query().eager('user')194 this.github.authenticate({195 type: 'oauth',196 token: this.synchronization.user.accessToken,197 })198 await this.synchronization.$relatedQuery('user')199 const { repositories, organizations } = await this.synchronizeRepositories()200 await this.synchronizeRepositoryRights(repositories)201 await this.synchronizeOrganizationRights(organizations)202 }203}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var Organization = require('argos-sdk/Models/Organization');2var org = new Organization();3var orgId = 1;4org.organizationStillExists(orgId).then(function (exists) {5 console.log(exists);6});7var Organization = require(‘argos-sdk/Models/Organization’);8var org = new Organization();9var orgId = 1;10var userId = 1;11org.isUserManager(orgId, userId).then(function (exists) {12console.log(exists);13});14var Organization = require(‘argos-sdk/Models/Organization’);15var org = new Organization();16var orgId = 1;17var userId = 1;18org.isUserManager(orgId, userId).then(function (exists) {19console.log(exists);20});

Full Screen

Using AI Code Generation

copy

Full Screen

1var account = App.ModelManager.getModel('Account', MODEL_TYPES.SDATA);2account.organizationStillExists('test', function(err, exists) {3 if (err) {4 console.log('err', err);5 } else {6 console.log('exists', exists);7 }8});9{10}

Full Screen

Using AI Code Generation

copy

Full Screen

1var accountModel = App.ModelManager.getModel('Account', 'detail');2var account = new accountModel();3account.set('AccountName', 'Test Account');4account.organizationStillExists()5 .then(function (result) {6 console.log('Organization exists: ' + result);7 })8 .catch(function (error) {9 console.log('Error: ' + error);10 });11var accountEditView = App.getView('account_edit');12var accountEdit = new accountEditView();13accountEdit.organizationStillExists()14 .then(function (result) {15 console.log('Organization exists: ' + result);16 })17 .catch(function (error) {18 console.log('Error: ' + error);19 });

Full Screen

Using AI Code Generation

copy

Full Screen

1const sdk = require('argos-sdk');2sdk.organizationStillExists('organizationId')3.then((result) => {4 console.log(result);5})6.catch((error) => {7 console.log(error);8});9const sdk = require('argos-sdk-middleware');10sdk.organizationStillExists('organizationId')11.then((result) => {12 console.log(result);13})14.catch((error) => {15 console.log(error);16});17{ message: 'Organization does not exist' }

Full Screen

Using AI Code Generation

copy

Full Screen

1require([‘argos/Utility’], function (Utility) {2Utility.organizationStillExists().then(function (exists) {3console.log(‘Organization still exists: ’ + exists);4});5});6Utility.userIsLoggedIn().then(function (isLoggedIn) {7console.log(‘User is logged in: ’ + isLoggedIn);8});9Utility.userHasAccessToEntity(‘Account’).then(function (hasAccess) {10console.log(‘User has access to Account: ’ + hasAccess);11});12Utility.userHasAccessToEntity(‘Account’).then(function (hasAccess) {13console.log(‘User has access to Account: ’ + hasAccess);14});15Utility.userHasAccessToEntity(‘Account’).then(function (hasAccess) {16console.log(‘User has access to Account: ’ + hasAccess);17});

Full Screen

Using AI Code Generation

copy

Full Screen

1var organizationModel = Sage.Platform.Mobile.ModelFactory.get('organization');2if (organizationModel) {3 organizationModel.organizationStillExists(function (result) {4 if (result) {5 alert('Organization is active');6 } else {7 alert('Organization is inactive');8 }9 });10}11var organizationModel = Sage.Platform.Mobile.ModelFactory.get('organization');12if (organizationModel) {13 alert('Organization id: ' + organizationModel.get('organizationId'));14 alert('Organization name: ' + organizationModel.get('organizationName'));15}16var organizationModel = Sage.Platform.Mobile.ModelFactory.get('organization');17if (organizationModel) {18 alert('Organization id: ' + organizationModel.get('organizationId'));19 alert('Organization name: ' + organizationModel.get('organizationName'));20}

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run argos automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful