Skip to content

Commit

Permalink
[FIX] correct analysis for V10.0 modules
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Mar 17, 2017
1 parent 5262f58 commit bbb67ca
Show file tree
Hide file tree
Showing 15 changed files with 163 additions and 44 deletions.
1 change: 1 addition & 0 deletions github_connector/__openerp__.py
Expand Up @@ -24,6 +24,7 @@
'views/view_wizard_load_github_model.xml',
'views/view_wizard_update_from_github.xml',
'views/view_wizard_update_company_author.xml',
'views/view_wizard_update_branch_list.xml',
'views/view_reporting.xml',
'views/action.xml',
'views/view_git_author.xml',
Expand Down
13 changes: 13 additions & 0 deletions github_connector/data/ir_cron.xml
Expand Up @@ -6,6 +6,19 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<openerp><data noupdate="1">

<record model="ir.cron" id="cron_update_branch_list">
<field name="name">Download Branches List for All repositories</field>
<field name="interval_number">1</field>
<field name="active" eval="False"/>
<field name="user_id" ref="base.user_root"/>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
<field name="model" eval="'github.repository'"/>
<field name="function" eval="'cron_update_branch_list'"/>
<field name="args" eval="'()'"/>
</record>

<record model="ir.cron" id="cron_download_code">
<field name="name">Download Source Code from All Github Branches</field>
<field name="interval_number">1</field>
Expand Down
12 changes: 12 additions & 0 deletions github_connector/demo/github_organization_serie.xml
Expand Up @@ -7,33 +7,45 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<openerp><data>

<record id="oca_organization_serie_50" model="github.organization.serie">
<field name="sequence">1</field>
<field name="name">5.0</field>
<field name="organization_id" ref="oca_organization" />
</record>

<record id="oca_organization_serie_60" model="github.organization.serie">
<field name="sequence">2</field>
<field name="name">6.0</field>
<field name="organization_id" ref="oca_organization" />
</record>

<record id="oca_organization_serie_61" model="github.organization.serie">
<field name="sequence">3</field>
<field name="name">6.1</field>
<field name="organization_id" ref="oca_organization" />
</record>

<record id="oca_organization_serie_70" model="github.organization.serie">
<field name="sequence">4</field>
<field name="name">7.0</field>
<field name="organization_id" ref="oca_organization" />
</record>

<record id="oca_organization_serie_80" model="github.organization.serie">
<field name="sequence">5</field>
<field name="name">8.0</field>
<field name="organization_id" ref="oca_organization" />
</record>

<record id="oca_organization_serie_90" model="github.organization.serie">
<field name="sequence">6</field>
<field name="name">9.0</field>
<field name="organization_id" ref="oca_organization" />
</record>

<record id="oca_organization_serie_10" model="github.organization.serie">
<field name="sequence">7</field>
<field name="name">10.0</field>
<field name="organization_id" ref="oca_organization" />
</record>

</data></openerp>
1 change: 1 addition & 0 deletions github_connector/models/__init__.py
Expand Up @@ -24,3 +24,4 @@

from . import wizard_update_from_github
from . import wizard_update_company_author
from . import wizard_update_branch_list
39 changes: 27 additions & 12 deletions github_connector/models/abstract_github_model.py
Expand Up @@ -92,14 +92,31 @@ def get_from_id_or_create(self, data, extra_data=None):
{'id': 7600578, 'url': 'https://api.github.com/orgs/OCA'})
"""
extra_data = extra_data and extra_data or {}
res = self.search([('github_id', '=', data['id'])])
if not res:
if self._need_individual_call:
github_model = self.get_github_for(self.github_type())
data = github_model.get_by_url(data['url'])
return self._create_from_github_data(data, extra_data)
else:
return res

# We try to search object by id
existing_object = self.search([('github_id', '=', data['id'])])
if existing_object:
return existing_object

# We try to see if object exist by name (instead of id)
if self._github_login_field:
existing_object = self.search([
('github_login', '=', data[self._github_login_field])])
if existing_object:
# Update the existing object with the id
existing_object.github_id = data['id']
_logger.info(
"Existing object %s#%d with github name '%s' has been"
" updated with unique github id %s#%s" % (
self._name, existing_object.id,
data[self._github_login_field], data['id'],
self.github_type()))
return existing_object

if self._need_individual_call:
github_model = self.get_github_for(self.github_type())
data = github_model.get_by_url(data['url'])
return self._create_from_github_data(data, extra_data)

@api.model
def create_from_name(self, name):
Expand All @@ -121,10 +138,6 @@ def create_from_name(self, name):
if not current_object:
# Create the object
return self._create_from_github_data(res)
else:
# Manage the special case when the name changed...
# TODO
pass

@api.multi
def button_update_from_github_light(self):
Expand Down Expand Up @@ -188,6 +201,8 @@ def _update_from_github_data(self, data):
# process, we realize a write only if data changed
to_write = {}
for k, v in vals.iteritems():
# TODO : improve, this line raise a warning on many2one
# comparison "Comparing apples and oranges..."
if item[k] != v:
to_write[k] = v
if to_write:
Expand Down
7 changes: 3 additions & 4 deletions github_connector/models/github_issue.py
Expand Up @@ -76,10 +76,9 @@ def _compute_comment_qty(self):
@api.depends('comment_ids.opinion')
def _compute_opinion(self):
for issue in self:
issue.approved_comment_qty =\
issue.mapped('comment_ids.opinion').count('approved')
issue.disapproved_comment_qty =\
issue.mapped('comment_ids.opinion').count('disapproved')
opinions = issue.mapped('comment_ids.opinion')
issue.approved_comment_qty = opinions.count('approved')
issue.disapproved_comment_qty = opinions.count('disapproved')

# Overloadable Section
def get_odoo_data_from_github(self, data):
Expand Down
9 changes: 8 additions & 1 deletion github_connector/models/github_organization_serie.py
Expand Up @@ -8,11 +8,18 @@

class GithubOrganizationSerie(models.Model):
_name = 'github.organization.serie'
_order = 'name'
_order = 'sequence, name'

# Columns Section
name = fields.Char(string='Name', required=True)

sequence = fields.Integer(string='Sequence', required=True)

organization_id = fields.Many2one(
comodel_name='github.organization', string='Organization',
required=True)

_sql_constraints = [
('sequence_organization_uniq', 'unique(organization_id, sequence)',
("Sequence serie must be unique by organization."))
]
6 changes: 6 additions & 0 deletions github_connector/models/github_repository.py
Expand Up @@ -149,6 +149,12 @@ def button_sync_issue_with_comment(self):
for repository in self:
repository.issue_ids.button_sync_comment()

@api.model
def cron_update_branch_list(self):
branches = self.search([])
branches.button_sync_branch()
return True

@api.multi
def button_sync_branch(self):
github_branch = self.get_github_for('repository_branches')
Expand Down
13 changes: 9 additions & 4 deletions github_connector/models/github_repository_branch.py
Expand Up @@ -24,7 +24,7 @@
class GithubRepository(models.Model):
_name = 'github.repository.branch'
_inherit = ['abstract.github.model']
_order = 'complete_name'
_order = 'repository_id, sequence_serie'

_github_type = 'repository_branches'
_github_login_field = False
Expand Down Expand Up @@ -60,6 +60,10 @@ class GithubRepository(models.Model):
comodel_name='github.organization.serie', string='Organization Serie',
compute='_compute_organization_serie_id', store=True)

sequence_serie = fields.Integer(
string='Sequence Serie', store=True,
related='organization_serie_id.sequence')

local_path = fields.Char(
string='Local Path', compute='_compute_local_path')

Expand Down Expand Up @@ -255,6 +259,7 @@ def _compute_local_path(self):
path = self.env['ir.config_parameter'].get_param(
'git.source_code_local_path')
for branch in self:
branch.local_path = path\
+ branch.repository_id.organization_id.github_login + '/'\
+ branch.complete_name
branch.local_path = os.path.join(
path,
branch.repository_id.organization_id.github_login,
branch.complete_name)
17 changes: 17 additions & 0 deletions github_connector/models/wizard_update_branch_list.py
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2016-Today: Odoo Community Association (OCA)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp import models, api


class WizardUpdateBranchList(models.TransientModel):
_name = 'wizard.update.branch.list'

@api.multi
def button_update_branch_list(self):
for wizard in self:
repository_obj = self.env['github.repository']
items = repository_obj.browse(self._context['active_ids'])
items.button_sync_branch()
19 changes: 19 additions & 0 deletions github_connector/views/action.xml
Expand Up @@ -102,6 +102,25 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field name="model">github.repository.branch</field>
</record>

<record id="action_wizard_update_branch_list" model="ir.actions.act_window">
<field name="name">Update Branch List</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">wizard.update.branch.list</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="multi">True</field>
</record>

<record id="value_wizard_update_branch_list" model="ir.values">
<field name="model_id" ref="model_github_repository" />
<field name="name">Update Branch List</field>
<field name="key2">client_action_multi</field>
<field name="value" eval="'ir.actions.act_window,' + str(ref('action_wizard_update_branch_list'))" />
<field name="key">action</field>
<field name="model">github.repository</field>
</record>


<!-- Settings Part -->
<record id="action_wizard_load_github_model" model="ir.actions.act_window">
Expand Down
33 changes: 14 additions & 19 deletions github_connector/views/view_github_organization.xml
Expand Up @@ -74,24 +74,27 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field name="location"/>
</group>
<notebook>
<page name="member" string="Members">
<group col="4">
<field name="member_ids" colspan="4" nolabel="1"/>
</group>
</page>
<page name="repository" string="Repositories">
<group col="4">
<field name="repository_ids" colspan="4" nolabel="1"/>
</group>
</page>
<page name="extra_setting" string="Extra Settings">
<page name="extra_setting" string="Settings">
<group col="4" string="Ignored Repositories">
<field name="ignored_repository_names" colspan="4"/>
</group>
<group col="4" string="Specific Repositories">
<field name="specific_repository_names" colspan="4"/>
</group>
</page>
<page string="Organization Series">
<field name="organization_serie_ids" colspan="4" nolabel="1">
<tree string="organization_serie_ids" editable="bottom">
<field name="sequence"/>
<field name="name"/>
</tree>
</field>
</page>
<page name="repository" string="Repositories">
<group col="4">
<field name="repository_ids" colspan="4" nolabel="1"/>
</group>
</page>
<page name="github" string="Github">
<group col="4">
<field name="github_url" widget="url" colspan="4"/>
Expand All @@ -106,14 +109,6 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
groups="github_connector.group_github_connector_manager"/>
</group>
</page>

<page string="Organization Series">
<field name="organization_serie_ids" colspan="4" nolabel="1">
<tree string="organization_serie_ids" editable="bottom">
<field name="name"/>
</tree>
</field>
</page>
</notebook>
</sheet>
</form>
Expand Down
22 changes: 22 additions & 0 deletions github_connector/views/view_wizard_update_branch_list.xml
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016-Today: Odoo Community Association (OCA)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<openerp><data>

<record id="view_wizard_update_branch_list_form" model="ir.ui.view">
<field name="model">wizard.update.branch.list</field>
<field name="arch" type="xml">
<form>
<footer>
<button name="button_update_branch_list" string="Update Branch List" type="object" class="oe_highlight" />
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>

</data></openerp>
5 changes: 4 additions & 1 deletion github_connector_odoo/README.rst
Expand Up @@ -9,7 +9,10 @@ Analyze Odoo Modules Informations from github repositories
Installation
============

Nothing special is needed to install this module.
This module will not analyse correctly V10 branches, except if you get
a patch, available on that branch, to analyse correctly new manifest files.

https://github.com/grap/OCB/tree/8.0_BACKPORT_V10_analysis

Configuration
=============
Expand Down
10 changes: 7 additions & 3 deletions github_connector_odoo/models/github_repository_branch.py
Expand Up @@ -11,7 +11,10 @@
from openerp import models, fields, api

from openerp.modules import load_information_from_description_file
from openerp.modules.module import MANIFEST

# Hard define this value to make this module working with or without
# the patch (that backports V10 manifests analysis code.
MANIFEST_NAMES = ('__manifest__.py', '__openerp__.py')

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -185,7 +188,8 @@ def clean(name):
return name

def is_really_module(name):
manifest_name = opj(dir, name, MANIFEST)
return os.path.isfile(manifest_name)
for mname in MANIFEST_NAMES:
if os.path.isfile(opj(dir, name, mname)):
return True

return map(clean, filter(is_really_module, os.listdir(dir)))

0 comments on commit bbb67ca

Please sign in to comment.