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

[11.0][FIX] github_connector keyerror 'blog' #34

Merged
merged 5 commits into from
Feb 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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