-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TA#72104 [16.0][MIG] github_pull_request_project
- Loading branch information
1 parent
46e2ddd
commit bc0afc0
Showing
18 changed files
with
484 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). | ||
|
||
{ | ||
'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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
106 changes: 106 additions & 0 deletions
106
github_pull_request_project/models/github_pull_request.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
"""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.
Binary file added
BIN
+92.5 KB
github_pull_request_project/static/description/project_task_pull_requests.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+97.8 KB
github_pull_request_project/static/description/pull_request_form_tasks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.