Skip to content

Commit

Permalink
[11.0][FIX] github_connector keyerror 'blog' (#34)
Browse files Browse the repository at this point in the history
[FIX] github_connector: keyerror 'blog'

Description of the issue/feature this PR addresses:

On new database error when syncing new github organization (example: OCA).
Error traceback: KeyError: 'blog'

Current behavior before PR:

Synchronization gets blog key on `get_odoo_data_from_github` but blog field does not exist.
When it tries to match the key with model attribute we get key error.

Desired behavior after PR is merged:

Get blog key from github data and show it on form view.
  • Loading branch information
enriquemartin authored and pedrobaeza committed Feb 2, 2019
1 parent fa8c8e7 commit c399f9f
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 23 deletions.
1 change: 1 addition & 0 deletions github_connector/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ Contributors
* Sébastien BEAU ([email protected])
* Benoît GUILLOT ([email protected])
* Vicent Cubells ([email protected])
* Enrique Martín ([email protected])

Maintainer
----------
Expand Down
2 changes: 1 addition & 1 deletion github_connector/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
'name': 'Github Connector',
'summary': 'Synchronize information from Github repositories',
'version': '11.0.1.1.1',
'version': '11.0.1.1.2',
'category': 'Connector',
'license': 'AGPL-3',
'author':
Expand Down
29 changes: 21 additions & 8 deletions github_connector/models/abstract_github_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,30 @@ def github_login_field(self):
return self._github_login_field

@api.model
def get_odoo_data_from_github(self, data):
"""Prepare function that map Github data to create in Odoo"""
def get_conversion_dict(self):
"""
Prepare function that map Github fields to Odoo fields
:return: Dictionary {odoo_field: github_field}
"""
return {
'github_id_external': data['id'],
'github_url': data.get('html_url', False),
'github_login': data.get(self.github_login_field(), False),
'github_create_date': data.get('created_at', False),
'github_write_date': data.get('updated_at', False),
'github_last_sync_date': fields.Datetime.now(),
'github_id_external': 'id',
'github_url': 'html_url',
'github_login': self.github_login_field(),
'github_create_date': 'created_at',
'github_write_date': 'updated_at',
}

@api.model
def get_odoo_data_from_github(self, data):
"""Prepare function that map Github data to create in Odoo"""
map_dict = self.get_conversion_dict()
res = {}
for k, v in map_dict.items():
if hasattr(self, k) and data.get(v, False):
res.update({k: data[v]})
res.update({'github_last_sync_date': fields.Datetime.now()})
return res

@api.multi
def get_github_data_from_odoo(self):
"""Prepare function that map Odoo data to create in Github.
Expand Down
16 changes: 12 additions & 4 deletions github_connector/models/github_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,21 @@ class GithubOrganization(models.Model):
ci_url_pattern = fields.Char(string='CI URL Pattern')

# Overloadable Section
@api.model
def get_conversion_dict(self):
res = super(GithubOrganization, self).get_conversion_dict()
res.update({
'name': 'name',
'description': 'description',
'location': 'location',
'email': 'email',
'website_url': 'blog',
})
return res

@api.model
def get_odoo_data_from_github(self, data):
res = super(GithubOrganization, self).get_odoo_data_from_github(data)
keys = ['name', 'description', 'location', 'blog', 'email']
for key in keys:
if key in data:
res.update({key: data[key]})
if 'avatar_url' in data:
res.update({
'image': self.get_base64_image_from_github(data['avatar_url']),
Expand Down
15 changes: 11 additions & 4 deletions github_connector/models/github_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,23 @@ def _compute_repository_branch_qty(self):
len(repository.repository_branch_ids)

# Overloadable Section
@api.model
def get_conversion_dict(self):
res = super(GithubRepository, self).get_conversion_dict()
res.update({
'name': 'name',
'github_url': 'url',
'description': 'description',
'website': 'homepage',
})
return res

@api.model
def get_odoo_data_from_github(self, data):
organization_obj = self.env['github.organization']
res = super(GithubRepository, self).get_odoo_data_from_github(data)
organization = organization_obj.get_from_id_or_create(data['owner'])
res.update({
'name': data['name'],
'github_url': data['url'],
'description': data['description'],
'website': data['homepage'],
'organization_id': organization.id,
})
return res
Expand Down
14 changes: 11 additions & 3 deletions github_connector/models/github_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ def _compute_repository_qty(self):
team.repository_qty = len(team.repository_ids)

# Overloadable Section
@api.model
def get_conversion_dict(self):
res = super(GithubTeam, self).get_conversion_dict()
res.update({
'name': 'name',
'description': 'description',
'privacy': 'privacy',
})
return res

@api.model
def get_odoo_data_from_github(self, data):
organization_obj = self.env['github.organization']
res = super(GithubTeam, self).get_odoo_data_from_github(data)
Expand All @@ -102,9 +113,6 @@ def get_odoo_data_from_github(self, data):
else:
organization_id = False
res.update({
'name': data['name'],
'description': data['description'],
'privacy': data['privacy'],
'organization_id': organization_id,
})
return res
Expand Down
16 changes: 13 additions & 3 deletions github_connector/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,25 @@ def _compute_github_team_qty(self):
partner.github_team_qty = len(partner.github_team_ids)

# Custom Section
@api.model
def get_conversion_dict(self):
res = super(ResPartner, self).get_conversion_dict()
res.update({
'website': 'blog',
'email': 'email',
})
return res

@api.model
def get_odoo_data_from_github(self, data):
res = super(ResPartner, self).get_odoo_data_from_github(data)
res.update({
'name':
data['name'] and data['name'] or
'%s (Github)' % data['login'],
'website': data['blog'],
'email': data['email'],
'image': self.get_base64_image_from_github(data['avatar_url']),
})
if 'avatar_url' in data:
res.update({
'image': self.get_base64_image_from_github(data['avatar_url']),
})
return res

0 comments on commit c399f9f

Please sign in to comment.