|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +import logging |
| 4 | +log = logging.getLogger('git_repo.gitbucket') |
| 5 | + |
| 6 | +from ..service import register_target |
| 7 | +from .github import GithubService |
| 8 | + |
| 9 | +import github3 |
| 10 | + |
| 11 | +@register_target('bucket', 'gitbucket') |
| 12 | +class GitbucketService(GithubService): |
| 13 | + fqdn = "localhost" |
| 14 | + port = 8080 |
| 15 | + def __init__(self, *args, **kwarg): |
| 16 | + super(GitbucketService, self).__init__(*args, **kwarg) |
| 17 | + |
| 18 | + def connect(self): |
| 19 | + self.gh = github3.GitHubEnterprise(self.build_url(self)) |
| 20 | + super(GitbucketService, self).connect() |
| 21 | + |
| 22 | + @classmethod |
| 23 | + def get_auth_token(cls, login, password, prompt=None): |
| 24 | + print("Please edit _YOUR_ACCESS_TOKEN_ to actual token in ~/.gitconfig or ~/.git/config after.") |
| 25 | + print("And add ssh-url = ssh://git@{}:_YOUR_SSH_PORT_".format(cls.fqdn)) |
| 26 | + return "_YOUR_ACCESS_TOKEN_" |
| 27 | + ## this code maybe works when GitBucket supports add access token API. |
| 28 | + #print("build_url: ", cls.build_url(cls)) |
| 29 | + #import platform |
| 30 | + #gh = github3.GitHubEnterprise(cls.build_url(cls)) |
| 31 | + #gh.login(login, password, two_factor_callback=lambda: prompt('2FA code> ')) |
| 32 | + #try: |
| 33 | + # auth = gh.authorize(login, password, |
| 34 | + # scopes=[ 'repo', 'delete_repo', 'gist' ], |
| 35 | + # note='git-repo2 token used on {}'.format(platform.node()), |
| 36 | + # note_url='https://github.com/guyzmo/git-repo') |
| 37 | + # return auth.token |
| 38 | + #except github3.models.GitHubError as err: |
| 39 | + # if len(err.args) > 0 and 422 == err.args[0].status_code: |
| 40 | + # raise ResourceExistsError("A token already exist for this machine on your github account.") |
| 41 | + # else: |
| 42 | + # raise err |
| 43 | + |
| 44 | + def format_path(self, repository, namespace=None, rw=False): |
| 45 | + path = super(GitbucketService, self).format_path(repository, namespace, rw) |
| 46 | + if not path.endswith(".git"): |
| 47 | + path = "{}.git".format(path) |
| 48 | + return path |
| 49 | + |
| 50 | + def delete(self, repo, user=None): |
| 51 | + raise NotImplementedError("GitBucket doesn't suport this action now.") |
| 52 | + |
| 53 | + def request_create(self, user, repo, from_branch, onto_branch, title=None, description=None, auto_slug=False, edit=None): |
| 54 | + raise NotImplementedError("GitBucket doesn't support this action now.") |
| 55 | + |
| 56 | + def gist_list(self, gist=None): |
| 57 | + raise NotImplementedError("GitBucket doesn't support manipulate gist by API.") |
| 58 | + |
| 59 | + def gist_fetch(self, gist, fname=None): |
| 60 | + raise NotImplementedError("GitBucket doesn't support manipulate gist by API.") |
| 61 | + |
| 62 | + def gist_clone(self, gist): |
| 63 | + raise NotImplementedError("GitBucket doesn't support manipulate gist by API.") |
| 64 | + |
| 65 | + def gist_create(self, gist_pathes, description, secret=False): |
| 66 | + raise NotImplementedError("GitBucket doesn't support manipulate gist by API.") |
| 67 | + |
| 68 | + def gist_delete(self, gist_id): |
| 69 | + raise NotImplementedError("GitBucket doesn't support manipulate gist by API.") |
0 commit comments