Skip to content

Instantly share code, notes, and snippets.

@kounoike
Created March 19, 2017 10:34
Show Gist options
  • Save kounoike/95ad741d8269663628b45f1925c5f957 to your computer and use it in GitHub Desktop.
Save kounoike/95ad741d8269663628b45f1925c5f957 to your computer and use it in GitHub Desktop.
GitBucket support for git-repo.
[gitrepo "gitbucket"]
type = gitbucket
token = MY_SECRET_KEY
fqdn = localhost
name = gitbucket
scheme = http
port = 80
ssh-url = ssh://git@localhost:29418

What's this?

sample implementation of gitbucket module for guyzmo/git-repo. ref: guyzmo/git-repo#142.

It can only some actions.

  • login
  • list repositories
  • create repository
  • clone repository

These action can't run. because GitBucket doesn't support such API yet.

  • Gist
  • delete repository
  • create/list and other PR related action

Why didn't PR?

Currently, GitBucket and this module can't use for convinient action. Maybe some API on GitBucket are required.

How to run

  1. Setup GitBucket with ssh support(default: off).
  2. Make access token by GitBucket web user interface.
  3. install git-repo with gitbucket.py into services/ext directory.
  4. Write [gitrepo "gitbucket"] section by editor(can't use git repo config because lack of add access token API).
#!/usr/bin/env python
import logging
log = logging.getLogger('git_repo.gitbucket')
from ..service import register_target
from ...exceptions import ArgumentError
from .github import GithubService
import github3
from git.exc import GitCommandError
from datetime import datetime
@register_target('gb', 'gitbucket')
class GitbucketService(GithubService):
fqdn = "localhost"
def __init__(self, *args, **kwarg):
super(GitbucketService, self).__init__(*args, **kwarg)
def connect(self):
self.gh = github3.GitHubEnterprise(self.build_url(self))
super(GitbucketService, self).connect()
@classmethod
def get_auth_token(cls, login, password, prompt=None):
raise NotImplementedError("Currently, GitBucket doesn't support add access token by API.")
## this code maybe works when GitBucket supports add access token API.
#print("build_url: ", cls.build_url(cls))
#import platform
#gh = github3.GitHubEnterprise(cls.build_url(cls))
#gh.login(login, password, two_factor_callback=lambda: prompt('2FA code> '))
#try:
# auth = gh.authorize(login, password,
# scopes=[ 'repo', 'delete_repo', 'gist' ],
# note='git-repo2 token used on {}'.format(platform.node()),
# note_url='https://github.com/guyzmo/git-repo')
# return auth.token
#except github3.models.GitHubError as err:
# if len(err.args) > 0 and 422 == err.args[0].status_code:
# raise ResourceExistsError("A token already exist for this machine on your github account.")
# else:
# raise err
def format_path(self, repository, namespace=None, rw=False):
repo = repository
if namespace:
repo = '{}/{}'.format(namespace, repository)
if not rw and '/' in repo:
return '{}/{}'.format(self.url_ro, repo)
elif rw and '/' in repo:
if ':' in self.url_rw:
return '{}/{}.git'.format(self.url_rw, repo)
else:
return '{}:{}'.format(self.url_rw, repo)
else:
raise ArgumentError("Cannot tell how to handle this url: `{}/{}`!".format(namespace, repo))
def delete(self, repo, user=None):
raise NotImplementedError("GitBucket doesn't suport this action.")
def request_create(self, user, repo, from_branch, onto_branch, title=None, description=None, auto_slug=False, edit=None):
raise NotImplementedError("GitBucket doesn't support this action")
def gist_list(self, gist=None):
raise NotImplementedError("GitBucket doesn't support manipulate gist by API.")
def gist_fetch(self, gist, fname=None):
raise NotImplementedError("GitBucket doesn't support manipulate gist by API.")
def gist_clone(self, gist):
raise NotImplementedError("GitBucket doesn't support manipulate gist by API.")
def gist_create(self, gist_pathes, description, secret=False):
raise NotImplementedError("GitBucket doesn't support manipulate gist by API.")
def gist_delete(self, gist_id):
raise NotImplementedError("GitBucket doesn't support manipulate gist by API.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment