How to use githubOwners method in argos

Best JavaScript code snippet using argos

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

index.js

Source:index.js Github

copy

Full Screen

1var dirname = require('dirname');2var _ = require('lodash');3var formatters = require('./formatters');4var github = require('./github');5var npm = require('./npm');6var callerRoot = dirname(process.cwd());7module.exports = {8 npm: npm,9 github: github,10 list: function (formatter) {11 formatter = formatters[(formatter || 'cli-table')];12 var npmOwners = npm.list() || [];13 var githubOwners = github.list() || [];14 var owners = _.union(npmOwners, githubOwners);15 return formatter.format(owners, githubOwners, npmOwners);16 },17 add: function (owner, source) {18 source = source || 'npm';19 switch (source.toLowerCase()) {20 case 'npm':21 return npm.add(owner);22 case 'github':23 return github.add(owner);24 case 'both':25 return npm.add(owner) && github.add(owner);26 }27 return false;28 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var argosy = require('argosy')2var argosyPattern = require('argosy-pattern')3var argosyPatternGithubOwners = require('argosy-pattern-github-owners')4var pattern = argosyPattern({5})6var service = argosy()7service.pipe(pattern.receiver()).pipe(service)8service.accept({ githubOwners: { owner: 'substack' } }, function (err, owners) {9 console.log(owners)10})11service.on('error', function (err) {12 console.error(err)13})14var argosy = require('argosy')15var argosyPattern = require('argosy-pattern')16var argosyPatternGithubRepos = require('argosy-pattern-github-repos')17var pattern = argosyPattern({18})19var service = argosy()20service.pipe(pattern.receiver()).pipe(service)21service.accept({ githubRepos: { owner: 'substack' } }, function (err, repos) {22 console.log(repos)23})24service.on('error', function (err) {25 console.error(err)26})27var argosy = require('argosy')28var argosyPattern = require('argosy-pattern')29var argosyPatternGithubRepo = require('argosy-pattern-github-repo')30var pattern = argosyPattern({31})32var service = argosy()33service.pipe(pattern.receiver()).pipe(service)34service.accept({ githubRepo: { owner: 'substack', repo: 'node-browserify' } }, function (err, repo) {35 console.log(repo)36})37service.on('error', function (err) {38 console.error(err)39})40var argosy = require('argos

Full Screen

Using AI Code Generation

copy

Full Screen

1var argosy = require('argosy')2var argosyPattern = require('argosy-pattern')3var argosyService = require('argosy-service')4var argosyAccept = require('argosy-accept')5var argosyGithub = require('argosy-github')6var argosyService = require('argosy-service')7var argosyAccept = require('argosy-accept')8var argosyPattern = require('argosy-pattern')9var argosy = require('argosy')10var githubService = argosyService({11 github: argosyAccept({12 githubOwners: argosyPattern.match(['string'], ['*'])13 })14})15githubService.pipe(argosyGithub()).pipe(githubService)16githubService.on('argosy/ready', function () {17 githubService.github.githubOwners('tjmehta', function (err, owners) {18 console.log(err, owners)19 })20})21var argosy = require('argosy')22var argosyPattern = require('argosy-pattern')23var argosyService = require('argosy-service')24var argosyAccept = require('argosy-accept')25var argosyGithub = require('argosy-github')26var argosyService = require('argosy-service')27var argosyAccept = require('argosy-accept')28var argosyPattern = require('argosy-pattern')29var argosy = require('argosy')30var githubService = argosyService({31 github: argosyAccept({32 githubOwners: argosyPattern.match(['string'], ['*'])33 })34})35githubService.pipe(argosyGithub()).pipe(githubService)36githubService.on('argosy/ready', function () {37 githubService.github.githubOwners('tjmehta', function (err, owners) {38 console.log(err, owners)39 })40})41var argosy = require('argosy')42var argosyPattern = require('argosy-pattern')43var argosyService = require('argosy-service')44var argosyAccept = require('argosy-

Full Screen

Using AI Code Generation

copy

Full Screen

1var argosy = require('argosy')2var argosyPattern = require('argosy-pattern')3var argosyPatternGithub = require('argosy-pattern-github')4var argosyGithub = require('argosy-github')5var pattern = argosyPattern({6})7var argosyService = argosy()8argosyService.pipe(argosyGithub()).pipe(argosyService)9argosyService.accept(pattern({10 github: {11 }12}), function (msg, cb) {13 console.log(msg)14 cb(null, msg)15})16argosyService.act(pattern({17 github: {18 }19}), function (err, msg) {20 if (err) {21 console.log(err)22 } else {23 console.log(msg)24 }25})26var argosy = require('argosy')27var argosyPattern = require('argosy-pattern')28var argosyPatternGithub = require('argosy-pattern-github')29var argosyGithub = require('argosy-github')30var pattern = argosyPattern({31})32var argosyService = argosy()33argosyService.pipe(argosyGithub()).pipe(argosyService)34argosyService.accept(pattern({35 github: {36 }37}), function (msg, cb) {38 console.log(msg)39 cb(null, msg)40})41argosyService.act(pattern({42 github: {43 }44}), function (err, msg) {45 if (err) {46 console.log(err)47 } else {48 console.log(msg)49 }50})51var argosy = require('argosy')52var argosyPattern = require('argosy-pattern')53var argosyPatternGithub = require('argosy-pattern-github')54var argosyGithub = require('argosy-github')55var pattern = argosyPattern({56})

Full Screen

Using AI Code Generation

copy

Full Screen

1const argosy = require('argosy')2const pattern = require('argosy-pattern')3const argosyPatternMatcher = require('argosy-pattern-matcher')4const service = argosy()5service.use(argosyPatternMatcher({6 githubOwners: pattern.match(['owner'])7}))8service.act('role:github,cmd:owners', function (err, owners) {9 console.log(owners)10})11const argosy = require('argosy')12const pattern = require('argosy-pattern')13const argosyPatternMatcher = require('argosy-pattern-matcher')14const service = argosy()15service.use(argosyPatternMatcher({16 githubOwners: pattern.match(['owner'])17}))18const argosy = require('argosy')19const pattern = require('argosy-pattern')20const argosyPatternMatcher = require('argosy-pattern-matcher')21const service = argosy()22service.use(argosyPatternMatcher({23 githubOwners: pattern.match(['owner'])24}))25const argosy = require('argosy')26const pattern = require('argosy-pattern')27const argosyPatternMatcher = require('argosy-pattern-matcher')28const service = argosy()29service.use(argosyPatternMatcher({30 githubOwners: pattern.match(['owner'])31}))32const argosy = require('argosy')33const pattern = require('argosy-pattern')34const argosyPatternMatcher = require('argosy-pattern-matcher')35const service = argosy()36service.use(argosyPatternMatcher({37 githubOwners: pattern.match(['owner'])38}))39const argosy = require('argosy')40const pattern = require('argosy-pattern')41const argosyPatternMatcher = require('argosy-pattern-matcher')42const service = argosy()43service.use(argosyPatternMatcher({44 githubOwners: pattern.match(['owner'])45}))46const argosy = require('argosy')47const pattern = require('argosy-pattern')48const argosyPatternMatcher = require('

Full Screen

Using AI Code Generation

copy

Full Screen

1var argosy = require('argosy')2var github = require('argosy-github')3var service = {4}5var seneca = argosy()6seneca.pipe(service).pipe(seneca)7seneca.act('githubOwners:githubOwners', function (err, owners) {8 console.log(owners)9})

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