Exemplo n.º 1
0
    def test_register_webhook_already_registered_updates_db(self, GitHub):
        ps = PackageSource.objects.create(
            series_id=1,
            git_url='https://github.com/owner/repo',
            branch='master',
            last_built_name='something')

        self.assertFalse(ps.webhook_registered)

        class Response(object):
            status_code = 422

            def json(self):
                return {
                    u'documentation_url':
                    u'https://developer.github.com/v3/repos/hooks/#create-a-hook',
                    u'errors': [{
                        u'code': u'custom',
                        u'message': u'Hook already exists on this repository',
                        u'resource': u'Hook'
                    }],
                    u'message':
                    u'Validation Failed'
                }

        connection = GitHub.return_value
        repository = connection.repository.return_value
        repository.create_hook.return_value = github3.GitHubError(Response())

        ps.register_webhook()

        connection.repository.assert_called_with('owner', 'repo')
        repository.create_hook.assert_called_with(
            name='web',
            config={
                'url': 'https://example.com/api/github/',
                'content_type': 'json'
            })

        ps.refresh_from_db()
        self.assertTrue(ps.webhook_registered)
Exemplo n.º 2
0
 def _github_error_side_effect(*args, **kwargs):
     raise github3.GitHubError(mock.Mock())
Exemplo n.º 3
0
 def side_effect():
     raise github3.GitHubError(mock.MagicMock())
Exemplo n.º 4
0
new_names = [name for name in names if
             name not in gx.nodes and name not in bad]
old_names = [name for name in names if name in gx.nodes]
old_names = sorted(old_names, key=lambda n: gx.nodes[n]['time'])

total_names = new_names + old_names
print('start loop')
gh = github3.login(os.environ['USERNAME'], os.environ['PASSWORD'])
try:
    for i, name in enumerate(total_names):
        print(i, name, gh.rate_limit()['resources']['core']['remaining'])
        r = requests.get('https://api.github.com/repos/conda-forge/'
                         '{}-feedstock/contents/recipe/meta.yaml'.format(name),
                         auth=(os.environ['USERNAME'], os.environ['PASSWORD']))
        if r.status_code == 403:
            raise github3.GitHubError(r)
        elif r.status_code != 200:
            print('Something odd happened to this recipe '
                  '{}'.format(r.status_code))
            with open('bad.txt', 'a') as f:
                f.write('{}\n'.format(name))
            continue
        meta_yaml = r.json()['content']
        if meta_yaml:
            text = codecs.decode(b64decode(meta_yaml))
            yaml_dict = parsed_meta_yaml(text)
            if not yaml_dict:
                with open('bad.txt', 'a') as f:
                    f.write('{}\n'.format(name))
                continue
            # TODO: Write schema for dict