Skip to content
This repository has been archived by the owner on Mar 2, 2021. It is now read-only.

Commit

Permalink
Upgrade github3.py to 0.5.1 and requests to 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia authored and Crosspop committed Feb 22, 2013
1 parent 292de78 commit 1d7b6ab
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 17 deletions.
23 changes: 20 additions & 3 deletions asuka/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from boto.ec2.connection import EC2Connection
from boto.exception import EC2ResponseError
from boto.route53.connection import Route53Connection
from github3.api import login
from github3.github import GitHub
from github3.repos import Repository
from paramiko.pkey import PKey
Expand Down Expand Up @@ -202,11 +203,11 @@ def repository(self):
'content_type': 'json',
'secret': self.github_client_secret
}
for hook in repo.list_hooks():
for hook in repo.iter_hooks():
if (hook.name == hook_name and
frozenset(hook.events) == hook_events and
hook.config == hook_config):
if not hook.is_active():
if not hook.active:
hook.edit(
name=hook_name,
events=list(hook_events),
Expand Down Expand Up @@ -238,7 +239,7 @@ def _create_github_deploy_key(self):
pass
else:
actual_key = self.private_key.get_base64()
for key in repos.list_keys():
for key in repos.iter_keys():
if key.title != self.key_name:
continue
elif key.key.split()[1] != actual_key:
Expand Down Expand Up @@ -341,6 +342,22 @@ def __ne__(self, operand):
def __hash__(self):
return hash(self.name)

def __getstate__(self):
config = dict((k, v)
for k, v in self.__dict__.items()
if not k.startswith('_'))
repo = self.repository
_, token = repo._session.headers['Authorization'].split()
config['repository'] = token, repo.owner.login, repo.name
config['private_key'] = self.private_key
return config

def __setstate__(self, state):
token, owner, repo = state.pop('repository')
github = login(token=token)
state['repository'] = github.repository(owner, repo)
self.__init__(**state)

def __repr__(self):
c = type(self)
return '<{0}.{1} {2!r}>'.format(c.__module__, c.__name__, self.name)
Expand Down
2 changes: 1 addition & 1 deletion asuka/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def __init__(self, app, number, merge_test=True):
raise ValueError("pull request #{0} can't be found".format(number))
if merge_test:
for x in xrange(10):
mergeable = pr.is_mergeable()
mergeable = pr.mergeable
if mergeable is None or x < 2:
pr = app.repository.pull_request(number)
continue
Expand Down
40 changes: 29 additions & 11 deletions asuka/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def authorize(request):
},
headers={'Accept': 'application/json'}
)
token = response.json['access_token']
token = response.json()['access_token']
gh = login(token=token)
if not app.repository.is_collaborator(gh.user().login):
raise Forbidden()
Expand Down Expand Up @@ -272,21 +272,29 @@ def hook_push(webapp, payload):
def redeploy(webapp, commit, branch):
logger = logging.getLogger(__name__ + '.redeploy')
logger.info('start redeployment: %s [%s]', branch.label, commit.ref)
webapp.pool.apply_async(redeploy_worker, (branch, commit))
webapp.pool.apply_async(
redeploy_worker,
(webapp.app, branch.label, commit.ref)
)


def redeploy_worker(branch, commit):
cleanup_worker(branch, commit)
deploy_worker(branch, commit)
def redeploy_worker(app, branch, commit):
cleanup_worker(app, branch, commit)
deploy_worker(app, branch, commit)


def cleanup(webapp, commit, branch):
logger = logging.getLogger(__name__ + '.cleanup')
logger.info('start cleaning up: %s [%s]', branch.label, commit.ref)
webapp.pool.apply_async(cleanup_worker, (branch, commit))
webapp.pool.apply_async(
cleanup_worker,
(webapp.app, branch.label, commit.ref)
)


def cleanup_worker(branch, commit):
def cleanup_worker(app, branch, commit):
branch = find_by_label(app, branch)
commit = Commit(app, commit)
logger = logging.getLogger(__name__ + '.cleanup_worker')
try:
system_logger = logging.getLogger('asuka')
Expand All @@ -304,10 +312,15 @@ def cleanup_worker(branch, commit):
def promote(webapp, commit, branch):
logger = logging.getLogger(__name__ + '.promote')
logger.info('start promoting: %s [%s]', branch.label, commit.ref)
webapp.pool.apply_async(promote_worker, (branch, commit))
webapp.pool.apply_async(
promote_worker,
(webapp.app, branch.label, commit.ref)
)


def promote_worker(branch, commit):
def promote_worker(app, branch, commit):
branch = find_by_label(app, branch)
commit = Commit(app, commit)
logger = logging.getLogger(__name__ + '.promote_worker')
try:
system_logger = logging.getLogger('asuka')
Expand Down Expand Up @@ -348,7 +361,10 @@ def promote_worker(branch, commit):
def deploy(webapp, commit, branch):
logger = logging.getLogger(__name__ + '.deploy')
logger.info('start deployment: %s [%s]', branch.label, commit.ref)
webapp.pool.apply_async(deploy_worker, (branch, commit))
webapp.pool.apply_async(
deploy_worker,
(webapp.app, branch.label, commit.ref)
)


def make_payload(branch, commit):
Expand Down Expand Up @@ -390,7 +406,9 @@ def make_payload(branch, commit):
}


def deploy_worker(branch, commit):
def deploy_worker(app, branch, commit):
branch = find_by_label(app, branch)
commit = Commit(app, commit)
logger = logging.getLogger(__name__ + '.deploy_worker')
try:
system_logger = logging.getLogger('asuka')
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@


install_requires = [
'boto == 2.6.0', 'distribute', 'github3.py == 0.1a8', 'iso8601 == 0.1.4',
'boto == 2.6.0', 'distribute', 'github3.py == 0.5.1', 'iso8601 == 0.1.4',
'Jinja2 == 2.6', 'paramiko == 1.7.7.2', 'Plastic == 0.1.0', 'pip == 1.2.1',
'PyYAML == 3.10', 'requests == 0.14.1', 'waitress == 0.8.1',
'PyYAML == 3.10', 'requests == 1.1.0', 'waitress == 0.8.1',
'Werkzeug >= 0.8.3'
]

Expand Down

0 comments on commit 1d7b6ab

Please sign in to comment.