def run(self): if self.GITHUB_TOKEN is None: logging.critical('No github OAuth token defined in the GITHUB_TOKEN env variable') sys.exit(1) if self.SSH_PKEY is None: logging.critical('SSH_KEY not configured, please set it to you private SSH key file') sys.exit(1) github = Github(self.GITHUB_TOKEN) ssh = SSHClient() ssh.load_system_host_keys() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) self.SSH_PKEY = os.path.expanduser(self.SSH_PKEY) orga = github.get_organization('nuxeo') # type: Organization repo = orga.get_repo('nuxeo.com') # type: Repository opened_pulls = [('/var/www/nuxeo.com/pr-%d.' % pull.number) + self.PREVIEW_DOMAIN for pull in repo.get_pulls()] try: proxy = ProxyCommand(('ssh -i %s -W 10.10.0.63:22 ' % self.SSH_PKEY) + self.BASTION_IP) ssh.connect('10.10.0.63', username='******', sock=proxy, key_filename=self.SSH_PKEY) _, stdout, _ = ssh.exec_command('ls -d /var/www/nuxeo.com/pr-*') [ssh.exec_command('rm -rf ' + line.strip()) for line in stdout.readlines() if line.strip() not in opened_pulls] ssh.close() except SSHException, e: logging.critical('Could work on remote: %s', e) sys.exit(1)
def run(self): if self.GITHUB_TOKEN is None: logging.critical('No github OAuth token defined in the GITHUB_TOKEN env variable') sys.exit(1) github = Github(self.GITHUB_TOKEN) captain_hooks = CaptainHooksClient(self.GITHUB_TOKEN) logging.info('Fetching organization %s', self.ORGANIZATION) orga = github.get_organization(self.ORGANIZATION) # type: Organization logging.info('Fetching organization repositories') for repo in orga.get_repos(): # type: Repository for hook in repo.get_hooks(): # type: Hook logging.info('%s/%s:backup: ' + json.dumps(hook.raw_data), orga.login, repo.name) logging.info('%s/%s:updating', orga.login, repo.name) try: captain_hooks.setup_webhooks(orga.login, repo.name, { 'absent': [ {'url': 'http://qapreprod.in.nuxeo.com/jenkins/github-webhook/'}, {'url': 'https://qa.nuxeo.org/githooks/send-email'}, # {'url': 'https://app.review.ninja/github/webhook'}, ], 'present': [ { 'name': 'web', 'config': { 'content_type': 'json', 'url': 'https://hooks.nuxeo.org/hook/' }, 'events': ['push'], 'active': True }, ] }) logging.info('%s/%s:done', orga.login, repo.name) except CaptainHooksClientException, e: logging.warn('%s/%s:failed: %s', orga.login, repo.name, e)