Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates git-repo to run with newer deps #198

Open
wants to merge 11 commits into
base: devel
Choose a base branch
from
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ before_install: |
fi
# command to install dependencies
install:
- "pip install --upgrade pip" # upgrade to latest pip (needed on py3.4)
- "pip install -r requirements-test.txt"
- "pip install --upgrade pip pipenv" # upgrade to latest pip (needed on py3.4)
- "pipenv install -e .[test]"
# command to run tests
script: "py.test --cov=git_repo --cov-report term-missing tests"
script: "pipenv run py.test --cov=git_repo --cov-report term-missing tests"
12 changes: 12 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
git-repo = {editable = true,extras = ["test"],path = "."}

[requires]
python_version = "3.7"
473 changes: 473 additions & 0 deletions Pipfile.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions git_repo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/usr/bin/env python
11 changes: 6 additions & 5 deletions git_repo/services/ext/bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def delete(self, repo, user=None):

def list(self, user, _long=False):
try:
user = User.find_user_by_username(user)
user = User(User.find_user_by_username(user))
except HTTPError as err:
raise ResourceNotFoundError("User {} does not exists.".format(user)) from err

Expand All @@ -106,7 +106,7 @@ def list(self, user, _long=False):
yield "{}"
repositories = list(repositories)
yield ("Total repositories: {}".format(len(repositories)),)
yield from columnize(["/".join([user.username, repo.name]) for repo in repositories])
yield from columnize(["/".join([user.nickname, repo.name]) for repo in repositories])
else:
yield "{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{:12}\t{}"
yield ['Status', 'Commits', 'Reqs', 'Issues', 'Forks', 'Coders', 'Watch', 'Likes', 'Lang', 'Modif', 'Name']
Expand Down Expand Up @@ -134,7 +134,7 @@ def list(self, user, _long=False):
# info
repo.language or '?', # language
repo.updated_on, # date
'/'.join([user.username, repo.name]), # name
'/'.join([user.nickname, repo.name]), # name
]

def _format_gist(self, gist):
Expand Down Expand Up @@ -319,10 +319,11 @@ def request_list(self, user, repo):
r.links['html']['href']
) for r in self.bb.repositoryPullRequestsInState(
owner=user,
repository_name=repo,
state='open'
repository_name=repo
) if not isinstance(r, dict) # if no PR is empty, result is a dict
)
yield "{}\t{:<60}\t{}"
yield 'id', 'title', 'URL'
for pull in sorted(requests):
try:
yield pull
Expand Down
40 changes: 20 additions & 20 deletions git_repo/services/ext/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ def connect(self):

def create(self, user, repo, add=False):
try:
group = self.gl.groups.search(user)
data = {'name': repo, 'path': repo}
group = self.gl.groups.list(search=user)
data = {'name': repo}
if group:
data['namespace_id'] = group[0].id
self.gl.projects.create(data=data)
except GitlabCreateError as err:
if json.loads(err.response_body.decode('utf-8'))['message']['name'][0] == 'has already been taken':
if json.loads(err.response_body.decode('utf-8')).get('message', {}).get('name', [None])[0] == 'has already been taken':
raise ResourceExistsError("Project already exists.") from err
else:
raise ResourceError("Unhandled error.") from err
Expand All @@ -60,7 +60,7 @@ def fork(self, user, repo):
try:
return self.gl.projects.get('{}/{}'.format(user, repo)).forks.create({}).path_with_namespace
except GitlabCreateError as err:
if json.loads(err.response_body.decode('utf-8'))['message']['name'][0] == 'has already been taken':
if json.loads(err.response_body.decode('utf-8')).get('message', {}).get('name', [None])[0] == 'has already been taken':
raise ResourceExistsError("Project already exists.") from err
else:
raise ResourceError("Unhandled error: {}".format(err)) from err
Expand All @@ -71,8 +71,8 @@ def delete(self, repo, user=None):
try:
repository = self.gl.projects.get('{}/{}'.format(user, repo))
if repository:
result = self.gl.delete(repository.__class__, repository.id)
if not repository or not result:
result = self.gl.projects.delete(repository.id)
if not repository:
raise ResourceNotFoundError("Cannot delete: repository {}/{} does not exists.".format(user, repo))
except GitlabGetError as err:
if err.response_code == 404:
Expand Down Expand Up @@ -182,7 +182,7 @@ def gist_fetch(self, snippet, fname=None):
except Exception as err:
raise ResourceNotFoundError('Could not find snippet') from err

return snippet.raw().decode('utf-8')
return snippet.content().decode('utf-8')

def gist_clone(self, gist):
raise ArgumentError('Snippets cannot be cloned in gitlab.')
Expand All @@ -197,7 +197,7 @@ def load_file(fname, path='.'):

data = {
'title': description,
'visibility_level': 0 if secret else 20
'visibility': 'private' if secret else 'public'
}

try:
Expand All @@ -211,12 +211,11 @@ def load_file(fname, path='.'):
namespace = self.username
gist_path = gist_pathes[1]
data.update({
'project_id': '/'.join([namespace, project]),
'code': load_file(gist_path),
'file_name': os.path.basename(gist_path),
}
)
gist = self.gl.project_snippets.create(data)
gist = self.gl.projects.get('/'.join([namespace, project])).snippets.create(data)

elif len(gist_pathes) == 1:
gist_path = gist_pathes[0]
Expand Down Expand Up @@ -302,15 +301,14 @@ def request_create(self, onto_user, onto_repo, from_branch, onto_branch, title=N
if not title and not description:
raise ArgumentError('Missing message for request creation')

request = self.gl.project_mergerequests.create(
project_id=from_project.id,
data={
'source_branch': from_branch,
'target_branch': onto_branch,
'target_project_id': onto_project.id,
'title': title,
'description': description
}
request = self.gl.projects.get(from_project.id).mergerequests.create(
{
'source_branch': from_branch,
'target_branch': onto_branch,
'target_project_id': onto_project.id,
'title': title,
'description': description
}
)

yield '{}'
Expand All @@ -324,14 +322,16 @@ def request_create(self, onto_user, onto_repo, from_branch, onto_branch, title=N

except GitlabGetError as err:
raise ResourceNotFoundError(err) from err
except GitlabCreateError as err:
raise ResourceError("Creation error: {}".format(err)) from err
except Exception as err:
raise ResourceError("Unhandled error: {}".format(err)) from err

def request_list(self, user, repo):
project = self.gl.projects.get('/'.join([user, repo]))
yield "{:>3}\t{:<60}\t{:2}"
yield ('id', 'title', 'URL')
for mr in self.gl.project_mergerequests.list(project_id=project.id):
for mr in project.mergerequests.list() :
yield ( str(mr.iid),
mr.title,
mr.web_url
Expand Down
11 changes: 0 additions & 11 deletions requirements-test.txt

This file was deleted.

10 changes: 0 additions & 10 deletions requirements.txt

This file was deleted.

82 changes: 29 additions & 53 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/env python3
# encoding: utf-8
from setuptools import setup, find_packages

import sys, os

import pip

from setuptools import setup, find_packages, dist
from setuptools import setup, find_packages
from setuptools.command.test import test as TestCommand
from distutils.core import Command
from distutils.core import setup
Expand All @@ -15,15 +14,6 @@
print('Please install with python version 3')
sys.exit(1)

# Use buildout's path for eggs
def get_egg_cache_dir(self):
egg_cache_dir = os.path.join(os.curdir, 'var', 'eggs')
if not os.path.exists(egg_cache_dir):
os.makedirs(egg_cache_dir, exist_ok=True)
return egg_cache_dir
dist.Distribution.get_egg_cache_dir = get_egg_cache_dir


class DistClean(Command):
description = 'Clean the repository from all buildout stuff'
user_options = []
Expand Down Expand Up @@ -94,46 +84,32 @@ def run_tests(self):
sys.exit(errno)


class Buildout(Command):
description = 'Running buildout on the project'
user_options = []

def initialize_options(self): pass
def finalize_options(self): pass

def run(self):
try:
from zc.buildout.buildout import main
except ImportError:
print('Please install buildout!\n pip install zc.buildout')
sys.exit(1)
errno = main(sys.argv[sys.argv.index('buildout')+1:])
if errno == 0:
print('Now you can run tests using: bin/py.test')
print('Now you can test current code using: bin/git-repo')
print('Thank you 🍻')
sys.exit(errno)

requirements = [
'docopt',
'progress',
'python-dateutil',
'lxml',
'GitPython',
'github3.py<1.0.0',
'python-gitlab',
'gogs-client',
'pybitbucket_fork',
'python-gerritclient',
]

requirements_tests = [
'pytest',
'pytest-cov',
'pytest-sugar',
'pytest-datadir-ng',
'testfixtures',
'mock',
'betamax==0.5.1',
'betamax-serializers',
]

requirements_links = []

def requirements(spec=None):
spec = '{}{}.txt'.format('requirements',
'-'+spec if spec else '')
requires = []

requirements = pip.req.parse_requirements(
spec, session=pip.download.PipSession())

for item in requirements:
if getattr(item, 'link', None):
requirements_links.append(str(item.link))
if item.req:
requires.append(str(item.req))

return requires


setup(name='git-repo',
description='Tool for managing repository services from your git CLI tool',
classifiers=[
Expand All @@ -160,17 +136,17 @@ def requirements(spec=None):
author_email='guyzmo+git-repo@m0g.net',
setup_requires=[
'setuptools_scm',
'setuptools-markdown',
'wheel>=0.25.0',
],
long_description_markdown_filename='README.md',
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
use_scm_version={'version_scheme':'guess-next-dev'},
include_package_data = True,
install_requires=requirements(),
tests_require=requirements('test'),
install_requires=requirements,
tests_require=requirements_tests,
extras_require={'test': requirements_tests},
dependency_links=requirements_links,
cmdclass={
'buildout': Buildout,
'dist_clean': DistClean,
'test': PyTest,
},
Expand Down