Skip to content

Conversation

@AmandaCameron
Copy link
Contributor

This is a WIP attempt at making the tool agnostic to subgroups as presented in #174

@AmandaCameron
Copy link
Contributor Author

Worth noting, this PR also fixes #172 because the reason I needed the subgroup support was to file a bunch of MRs at once for a wide-sweeping change.

@AmandaCameron
Copy link
Contributor Author

The tests are still failing, but it's because of this test here: https://github.com/guyzmo/git-repo/blob/devel/tests/integration/test_main.py#L120-L122 not sure what we should do about that (disable the test / set it up so it'll work )

@guyzmo
Copy link
Owner

guyzmo commented Aug 6, 2017

Well, this test was implemented to make sure the repo_slug invariant is right, and that invariant was, up until your patch, having one and only one slash in it.

Now, your patch is changing the invariant, thus the test shall change. We'll also need to check the side effects of that patch, i.e. checking what kind of errors will happen with other services when asking for multiple slash slugs that would then be invalid. (I think there's a sort of grouping implementing in bitbucket, though).

git_repo/repo.py Outdated
if len(overflow) != 0:
raise ArgumentError('Too many slashes.'
'Format of the parameter is <user>/<repo> or <repo>.')
#self.namespace, self.repo_name, *overflow = self.repo_slug.split('/')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as a todo note: don't forget to remove that commented line when you'll be done 😉

self.user_name, self.repo_name, *overflow = self.repo_slug.split('/')
if len(overflow) != 0:
raise ArgumentError('Too many slashes.'
'Format of the parameter is <user>/<repo> or <repo>.')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe, this test could stay with a check on some member that would be: if self.service._single_member_namespace: raise ArgumentError(…) So that services (like github? gitea?…) that don't implement namespaces >1 level would still raise that error.

git_repo/repo.py Outdated
if not self.user_name:
if not self.namespace:
raise ArgumentError('Cannot clone repository, '
'you shall provide either a <user>/<repo> parameter '
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to change <user>/<repo> as well in the __doc__ at the top of the file (the --help) and on other occurences like here! 😉


if not from_project:
raise ResourceNotFoundError('Could not find project `{}/{}`!'.format(from_user, from_repo))
raise ResourceNotFoundError('Could not find project `{}`!'.format(from_reposlug))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if '://' in url:
*_, user, name = url.split('/')
return '/'.join([user, name])
# *_, user, name = url.split('/')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: remove comment 😉

Copy link
Owner

@guyzmo guyzmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far so good! Only a few minor comments inline, just need to have proper test cases (for repo.py, and for each service). I introduce you about the tests system on IRC.

Copy link
Owner

@guyzmo guyzmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simple change for nested namespace limiting

class GitlabService(RepositoryService):
fqdn = 'gitlab.com'

_supports_nested_namespaces = True
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here I would change that to max_nested_namespaces = 21

as gitlab supports 21 subgroups maximum (if I remember right), so a good idea would be to set it up to that number!

git_repo/repo.py Outdated
#self.namespace, self.repo_name, *overflow = self.repo_slug.split('/')
*namespace, self.repo_name = self.repo_slug.split('/')
self.namespace = '/'.join(namespace)
if len(namespace) > 1 and not self.service._supports_nested_namespaces:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you could do something like if len(namespace) >= self.service.max_nested_namespaces

'server-cert'
]

_supports_nested_namespaces = False
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here max_nested_namespaces would be 1 as default!

def test_04_clone__subgroup(self):
self.action_clone(namespace='git-repo-test/subgroup',
repository='test-repo')

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you could add another test that would be:

def test_04_clone__subgroup_too_many(self):
    self.action_clone(namespace='git-repo-test/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z', repository='test-repo')

assert None is did_clone
# def test_clone__too_many_slashes(self):
# did_clone = self.main_clone('guyzmo/git/repo', 2)
# assert None is did_clone
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I understand that this one is less obvious, and I'll make it a todo for me. So if you don't feel like it, leave it commented out, it's on me 😉

Basically, the way I'd implement it would be to add a new optional parameter to self.main_clone() that specifies the number of allowed backslashes, so that the test would be:

def test_clone__not_too_many_slashes(self):
    did_clone = self.main_clone('guyzmo/git/repo', allowed_ns=3, 0)


def test_clone__too_many_slashes(self):
    did_clone = self.main_clone('guyzmo/git/repo', allowed_ns=1, 2)

where the main_clone helper would change the allowed value of RepositoryService's mockup before calling the do_clone() function.

Copy link
Owner

@guyzmo guyzmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall your tests look fine, and the errors you're getting are likely to be hicups with betamax configuration (I'm still struggling to find the right way to have it configured so that it generates the cassettes fine for anybody else than me).

Beyond my comments above about the number of allowed nested namespaces, your PR looks pretty much fine to me.

I'll need to find some time ASAP (likely this week end or early next week) to rebuild the cassettes from your tests and check that it's all working smoothly and nicely.

Until then, please use your own branch for what you need to double check that it's just working beautifully and you've not missed anything! (consider that the poor person's staging 😉).

Thank you again a lot for your contribution ♥👍🍻

Copy link
Owner

@guyzmo guyzmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lovely ♥ 🙌

@AmandaCameron
Copy link
Contributor Author

I'm seeing a lot of AttributeErrors inside the various tests, and I'm having a hard time understanding where they're coming from, but most of the test failures are around that. It seems like some piece of the magic is breaking down, but I'm not familiar enough with the whole picture to understand how / why.

@guyzmo
Copy link
Owner

guyzmo commented Nov 18, 2017

@timfonic I'm sorry for the time to merge and answer, but cf the readme file I'm getting pretty busy, and I don't have enough time to give alone all the care this project needs.

@guyzmo guyzmo closed this Nov 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants