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

🚧 Add Gogs support #82

Closed
wants to merge 1 commit into from
Closed

Conversation

pyhedgehog
Copy link
Contributor

@pyhedgehog pyhedgehog commented Dec 20, 2016

Current status:

  1. Implemented:
    • get_auth_token accepts url of profile page as login
    • connect
    • create
    • delete
    • list
  2. Tested:
    • config
    • list and list -l
    • open
    • add
    • create
    • delete
    • clone
  3. Added custom config options: (see GoGSService.connect)
    • verify - yes/no or path to ca-bundle
    • default-private - set to yes if new repositories should be private
    • ssh-url - i.e. 127.0.0.1:3022
  4. Uses proxy from git config
  5. Unable to implement as unsupported by Gogs API:
  6. get_auth_token can't return alternative fqdn and other custom options back to config command.

resolves #18

@pyhedgehog pyhedgehog changed the title #18: Gogs support GH18: Gogs support Dec 20, 2016
@pyhedgehog pyhedgehog mentioned this pull request Dec 20, 2016
@guyzmo guyzmo self-requested a review December 20, 2016 11:33
if verify.lower().strip() in ('0','no','false',''):
verify = False
elif verify.lower().strip() in ('1','yes','true'):
verify = True
Copy link
Owner

Choose a reason for hiding this comment

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

This feature is being implemented in another pull request, which is ready and will be released along the next release (which is due relatively soon, it's mostly depending on Gitlab to merge a patch I made).

So I'm merging that PR into devel (I actually thought I already did), so you can rebase your branch and use self.insecure instead of verify.

elif verify.lower().strip() in ('1','yes','true'):
verify = True
self.default_private = self.config.get('default-private', 'true').lower() not in ('0','no','false')
self.ssh_url = self.config.get('ssh-url', None) or self.fqdn
Copy link
Owner

Choose a reason for hiding this comment

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

is it likely that ssh_url would be different than based on fqdn? The assumption I'm making with self-hosted gitlab is that the fqdn for both ssh and http is the same, so for homogeinity I'd rather do the same here (and if it's wrong, then maybe make a fix for both gogs and gitlab), but I'm open to counter arguments on it.

And BTW the way you're using it, it's actually ssh_fqdn as an URL is supposed to look like ssh:// and might contain a path.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ssh-url can contains either fqdn with non-standard port 127.0.0.1:3022, or "fqdn" that refers some alias in ~/.ssh/config with Port and other parameters (i.e. ProxyCommand) pre-customized.

Copy link
Owner

Choose a reason for hiding this comment

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

hm… ok, though it's not the right place to configure that, it should be done the same way self.insecure is implemented, so all services can access that (as both gitlab and github can run on private instances).

if proxy:
proxies[scheme] = proxy
try:
self.session = requests.Session()
Copy link
Owner

Choose a reason for hiding this comment

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

The session shall be created in __init__, ideally when instanciating the external library that abstract the API. The reason for that is that the tests rely on the session instance to be monkey patched in order to be recorded and replayed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

connect() is called from git_repo.services.service.RepositoryService.__init__, isn't it?

Copy link
Owner

Choose a reason for hiding this comment

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

not necessarily, only if a repository argument is given to the __init__(). Basically, the tests framework is designed on the fact that instanciation of the requests.Session() (and any abstraction in between) is setup in __init__() whereas the connection is setup in connect(), making it then possible to hijack the Session instance in between.

if not verify:
try:
import urllib3
urllib3.disable_warnings()
Copy link
Owner

Choose a reason for hiding this comment

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

why are you disabling urllib3 warnings? If it needs to yell, let it yell! ☺

if not self._privatekey:
raise ConnectionError('Could not connect to GoGS. '
'Please configure .gitconfig '
'with your github private key.') from err
Copy link
Owner

@guyzmo guyzmo Dec 20, 2016

Choose a reason for hiding this comment

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

s/github/GoGS/

verify = False
elif verify.lower().strip() in ('1','yes','true'):
verify = True
self.default_private = self.config.get('default-private', 'true').lower() not in ('0','no','false')
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not for a config option for that, which would then be not homogeneous with the other services. Though you're making a good point here, we're missing private status of a repository creation in the API, so I believe we should add a --private argument to both create and fork.

About the configurations (and setting up defaults), there's issue #46 discussing this, which aims at doing things in a smart way, until then adding CLI parameters shouldn't be too much of a pain. So, I believe a good time to think about that would be for 2.0!

for scheme in 'http https'.split():
proxy = config.get_value(scheme, 'proxy', '')
if proxy:
proxies[scheme] = proxy
Copy link
Owner

Choose a reason for hiding this comment

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

proxies support is a great idea I totally did not think of…

but again, it should be implemented outside of the service implementation, so that it's accessible to all services (the same way self.insecure is implemented).

so either you remove it, and make an issue/PR to add this globally, or you leave it, and we'll replace that when we'll implement proxy support across services. Not sure what's the smartest.

Copy link
Owner

Choose a reason for hiding this comment

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

opened #105 about that.

@guyzmo
Copy link
Owner

guyzmo commented Dec 20, 2016

ok, so first of all I'm stumped that there's no API for forking a project! It's like one of the most basic feature to be expected from such a service 😖 And I hope that requests will land soon… BTW requests alone without a git ref that can be fetched is only half the feature…

That being said, it's a great job you've done 👍
but I'm not found of having everything as raw requests implemented in git-repo, because we're loosing the level of abstraction that an intermediate library provides.

I prefer to work on with a library that can gather more efforts from different projects implementing it to make it right, and eventually to maintain it when the remote API changes. And, then the RepositoryService specialization is just integrating that library for the special use cases of the project.

At the very least, if you want to roll your own API implementation (which is pretty clean overall), I'd then ask you to move it all within its own class:

class GogsAPI:
    def __init__(self):
        self.session = requests.Session()
        …

    def get_user(self, …):
        …

    def create(self):
        …

    def delete(self):
        …

    def iter_repositories(self):
        …

and then use that within GoGSService. Eventually, we might consider extracting that either to its own module in git-repo, or to a new library python-gogs.

@pyhedgehog
Copy link
Contributor Author

Ok. Let's close this one and I'll implement it second time from scratch.
Also I'm going to attempt to create pull requests for most important features for gogs and python-gogs-client.

@guyzmo
Copy link
Owner

guyzmo commented Dec 20, 2016

you can actually keep that PR and squash the merges (git push -f) to overwrite your changes. Then you can make a backup of your existing changes as another branch on your own fork just for the sake of it.

@guyzmo guyzmo reopened this Dec 20, 2016
@guyzmo guyzmo changed the title GH18: Gogs support 🚧 Add Gogs support Dec 21, 2016
@guyzmo guyzmo added this to the 1.10 milestone Dec 24, 2016
@guyzmo
Copy link
Owner

guyzmo commented Feb 3, 2017

(actually merged)

@guyzmo guyzmo closed this Feb 3, 2017
@guyzmo guyzmo removed the ready label Feb 3, 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.

Add gogs support
2 participants