Skip to content

Commit

Permalink
TA#72104 [16.0][MIG] github_pull_request_project
Browse files Browse the repository at this point in the history
  • Loading branch information
lanto-razafindrabe committed Dec 6, 2024
1 parent 46e2ddd commit bc0afc0
Show file tree
Hide file tree
Showing 18 changed files with 484 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .docker_files/main/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
'depends': [
'base',
'github_event',
'github_pull_request'
'github_pull_request',
'github_pull_request_project',
],
'installable': True,
}
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ USER odoo

COPY github_event /mnt/extra-addons/github_event
COPY github_pull_request /mnt/extra-addons/github_pull_request
COPY github_pull_request_project /mnt/extra-addons/github_pull_request_project

COPY .docker_files/main /mnt/extra-addons/main
COPY .docker_files/odoo.conf /etc/odoo
19 changes: 19 additions & 0 deletions github_pull_request_project/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Github Pull Request Project
===========================

This modules adds a relation between tasks and github pull request.


Tasks in Pull Request Form view
-------------------------------

.. image:: static/description/pull_request_form_tasks.png

Pull Requests in Tasks Form View
--------------------------------

.. image:: static/description/project_task_pull_requests.png

Contributors
------------
* Numigi (tm) and all its contributors (https://bit.ly/numigiens)
4 changes: 4 additions & 0 deletions github_pull_request_project/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2023 - today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from . import models

Check notice on line 4 in github_pull_request_project/__init__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

github_pull_request_project/__init__.py#L4

'.models' imported but unused (F401)
23 changes: 23 additions & 0 deletions github_pull_request_project/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2023 - Today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{

Check warning on line 4 in github_pull_request_project/__manifest__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

github_pull_request_project/__manifest__.py#L4

Statement seems to have no effect
'name': 'Github Pull Request Project',
'version': "16.0.1.0.0",
'author': 'Numigi',
'maintainer': 'Numigi',
'website': 'https://bit.ly/numigi-com',
'license': 'LGPL-3',
'category': 'Project',
'summary': 'Create a relation between tasks and github.pull_request models.',
'depends': ['project', 'github_pull_request'],
'data': [
'data/project_tags.xml',
'views/ir_actions_act_window.xml',
'views/ir_ui_menu.xml',
'views/github_pull_request.xml',
'views/project_task.xml',
],
'auto_install': True,
'installable': True,
}
19 changes: 19 additions & 0 deletions github_pull_request_project/data/project_tags.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>

<record id="tag_pull_request_open" model="project.tags">
<field name="name">PR: Open</field>
<field name="color" eval="10" /> <!-- green -->
</record>

<record id="tag_pull_request_merged" model="project.tags">
<field name="name">PR: Merged</field>
<field name="color" eval="11" /> <!-- purple -->
</record>

<record id="tag_pull_request_closed" model="project.tags">
<field name="name">PR: Closed</field>
<field name="color" eval="1" /> <!-- red -->
</record>

</odoo>
50 changes: 50 additions & 0 deletions github_pull_request_project/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * github_pull_request_project
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-11-14 19:48+0000\n"
"PO-Revision-Date: 2019-11-14 19:48+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: github_pull_request_project
#: model:ir.model,name:github_pull_request_project.model_github_pull_request
msgid "Github Pull Request"
msgstr ""

#. module: github_pull_request_project
#: model:ir.model.fields,field_description:github_pull_request_project.field_project_task__no_pull_request_open
msgid "No Pull Request Open"
msgstr "Aucune pull request d'ouverte"

#. module: github_pull_request_project
#: model:ir.model.fields,field_description:github_pull_request_project.field_project_task__pull_request_qty
msgid "Pull Request Qty"
msgstr "Quantité de pull request"

#. module: github_pull_request_project
#: model:ir.actions.act_window,name:github_pull_request_project.pull_requests_action_window_context
#: model:ir.model.fields,field_description:github_pull_request_project.field_project_task__pull_request_ids
#: model:ir.ui.menu,name:github_pull_request_project.project_pull_request_menu
#: model_terms:ir.ui.view,arch_db:github_pull_request_project.project_task_form_pull_requests
msgid "Pull Requests"
msgstr ""

#. module: github_pull_request_project
#: model:ir.model,name:github_pull_request_project.model_project_task
msgid "Task"
msgstr "Tâche"

#. module: github_pull_request_project
#: model:ir.model.fields,field_description:github_pull_request_project.field_github_pull_request__task_ids
msgid "Tasks"
msgstr "Tâches"

4 changes: 4 additions & 0 deletions github_pull_request_project/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2023 - today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from . import github_pull_request

Check notice on line 4 in github_pull_request_project/models/__init__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

github_pull_request_project/models/__init__.py#L4

'.github_pull_request' imported but unused (F401)
106 changes: 106 additions & 0 deletions github_pull_request_project/models/github_pull_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Copyright 2023 - today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import fields, models, api


class GithubPullRequestTask(models.Model):

_inherit = "github.pull_request"

task_ids = fields.Many2many(
'project.task',
'pull_request_task_ref',
'pull_request_id',
'task_id',
string='Tasks',
)

@api.model
def create(self, vals):
pr = super().create(vals)
pr.task_ids._update_pull_request_tags()
return pr

def write(self, vals):
must_update_tags_on_tasks = 'task_ids' in vals or 'state' in vals

if must_update_tags_on_tasks:
tasks_to_update = self.mapped('task_ids')

super().write(vals)

if must_update_tags_on_tasks:
tasks_to_update |= self.mapped('task_ids')
tasks_to_update._update_pull_request_tags()

return True


def has_pull_request_at_state(task: 'project.task', state: str) -> bool:

Check notice on line 40 in github_pull_request_project/models/github_pull_request.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

github_pull_request_project/models/github_pull_request.py#L40

undefined name 'project' (F821)
"""Return True if the task has at least one PR at the given state."""
return task.pull_request_ids.filtered(lambda pr: pr.state == state)


class ProjectTaskPullRequest(models.Model):

_inherit = "project.task"

pull_request_ids = fields.Many2many(
'github.pull_request',
'pull_request_task_ref',
'task_id',
'pull_request_id',
string='Pull Requests',
copy=False,
)

def _compute_pull_request_qty(self):
for record in self:
record.pull_request_qty = len(record.pull_request_ids)

pull_request_qty = fields.Integer(compute="_compute_pull_request_qty")

@api.model
def create(self, vals):
task = super().create(vals)
task._update_pull_request_tags()
return task

def write(self, vals):
super().write(vals)

if 'pull_request_ids' in vals:
self._update_pull_request_tags()

return True

def _update_pull_request_tags(self):
tag_open = self.env.ref('github_pull_request_project.tag_pull_request_open')
tag_merged = self.env.ref('github_pull_request_project.tag_pull_request_merged')
tag_closed = self.env.ref('github_pull_request_project.tag_pull_request_closed')

for task in self:
show_open_tag = has_pull_request_at_state(task, 'open')
show_merged_tag = (
has_pull_request_at_state(task, 'merged') and not show_open_tag
)
show_closed_tag = (
has_pull_request_at_state(task, 'closed')
and not show_open_tag
and not show_merged_tag
)

task.update(
{
'tag_ids': [
(4 if show_open_tag else 3, tag_open.id),
(4 if show_merged_tag else 3, tag_merged.id),
(4 if show_closed_tag else 3, tag_closed.id),
]
}
)

@api.onchange('pull_request_ids')
def _onchange_pull_requests_update_tags(self):
self._update_pull_request_tags()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions github_pull_request_project/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2023 - today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from . import test_project_task
Loading

0 comments on commit bc0afc0

Please sign in to comment.