Skip to content

feat: add support for /import/github #959

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

Merged
merged 2 commits into from
Dec 16, 2019
Merged

feat: add support for /import/github #959

merged 2 commits into from
Dec 16, 2019

Conversation

andrew-littlebits
Copy link

Addresses #952

This adds a method to the ProjectManager called import_github, which maps to the /import/github API endpoint. Calling import_github will trigger an import operation from <repo_id> into <target_namespace>, using <personal_access_token> to authenticate against github. In practice a gitlab server may take many 10's of seconds to respond to this API call, so we also take the liberty of increasing the default timeout (only for this method invocation).

Unfortunately since import is a protected keyword in python, I was unable to follow the endpoint structure with the manager namespace (eg: gitlab.import.github is not allowed`). I'm open to suggestions on a more sensible interface.

I'm successfully using this addition to batch-import hundreds of github repositories into gitlab. I didn't see any low-hanging-fruit way to add a unit test for this - please advise if this is acceptable.

@max-wittig
Copy link
Member

Thanks for the MR. I think we should follow the GitLab API as closely as possible, without adding helpers to keep it as thin of a layer as possible. Then we could also remove the dependency to another API wrapper library.

It should be implemented like descriped here: https://docs.gitlab.com/ee/api/import.html#import-repository-from-github.

API requests can be faked pretty easily as test, like done here: https://github.com/python-gitlab/python-gitlab/blob/master/gitlab/tests/test_gitlab.py#L757

@andrew-littlebits
Copy link
Author

andrew-littlebits commented Dec 4, 2019

Ok, no problem, I can clean out the PyGithub dependency and add a test. I'll try to get on this shortly.

@andrew-littlebits
Copy link
Author

@max-wittig i'm not quite familiar with this error (see failed pipeline build), and it doesn't look like its anywhere near code that i've touched. Do you have a moment to take a look? I can dig deeper too, but I wanted to check first if this is a known issue.

@max-wittig
Copy link
Member

Left a few comments.

@andrew-littlebits
Copy link
Author

As requested in an outdated discussion: i've lightly modified the base gitlab object to allow timeout to be specified in kwargs. This helps to avoid hacky code: instead of needing to change the global timeout parameter for the /import/github API call, I can set it just for that request.

@max-wittig
Copy link
Member

@andrew-littlebits Sorry for letting you wait so long. LGTM. Could you just rebase your branch to the latest master? Thanks!

Andrew Tergis added 2 commits December 16, 2019 13:41
Addresses #952

This adds a method to the `ProjectManager` called `import_github`, which
maps to the `/import/github` API endpoint. Calling `import_github` will
trigger an import operation from <repo_id> into <target_namespace>,
using <personal_access_token> to authenticate against github. In
practice a gitlab server may take many 10's of seconds to respond to
this API call, so we also take the liberty of increasing the default
timeout (only for this method invocation).

Unfortunately since `import` is a protected keyword in python, I was unable
to follow the endpoint structure with the manager namespace. I'm open to
suggestions on a more sensible interface.

I'm successfully using this addition to batch-import hundreds of github
repositories into gitlab.
On startup, the `timeout` parameter is loaded from config and stored on
the base gitlab object instance. This instance parameter is used as the
timeout for all API requests (it's passed into the `session` object when
making HTTP calls).

This change allows any API method to specify a `timeout` argument to
`**kwargs` that will override the global timeout value. This was
somewhat needed / helpful for the `import_github` method.

I have also updated the docs accordingly.
@andrew-littlebits
Copy link
Author

@max-wittig no worries, thank you for walking me through the process! I've rebased and lightly squashed.

@max-wittig max-wittig merged commit 97e1fca into python-gitlab:master Dec 16, 2019
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