-
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#72103 [16.0][MIG] github_pull_request (#25)
- Loading branch information
1 parent
53fe9a2
commit 46e2ddd
Showing
23 changed files
with
730 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
'depends': [ | ||
'base', | ||
'github_event', | ||
'github_pull_request' | ||
], | ||
'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
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,49 @@ | ||
Github Pull Request | ||
=================== | ||
|
||
This modules defines what is a GitHub pull requests (as an Odoo object). | ||
|
||
.. contents:: Table of Contents | ||
|
||
Pull Requests | ||
------------- | ||
As system administrator, I go to ``Configuration > Technical > GitHub > Pull Requests``. | ||
|
||
.. image:: static/description/menu_technical_pull_requests.png | ||
|
||
I see the list of pull requests: | ||
|
||
.. image:: static/description/pull_request_tree.png | ||
|
||
.. image:: static/description/pull_request_form.png | ||
|
||
Events | ||
------ | ||
A pull request has a list of events. | ||
|
||
.. image:: static/description/pull_request_event_list.png | ||
|
||
In the form view of an event, a ``Pull Request`` section is added. | ||
|
||
.. image:: static/description/pull_request_event_form.png | ||
|
||
This section is filled using the payload when processing the event. | ||
|
||
Pull Request Creation / Update | ||
------------------------------ | ||
When an event is processed, a pull request is assigned to the event. | ||
If no existing pull request matches the event, a new pull request is created. | ||
|
||
.. | ||
Of course, if the event is not related to a pull requests (i.e. if it was generated from a github issue), | ||
no pull request will be assigned to it. | ||
|
||
If it is the latest event for the pull request, the pull request record | ||
will be updated from the event data. | ||
|
||
Therefore, a pull request record in Odoo is updated as soon has new events are registered. | ||
|
||
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', | ||
'version': "16.0.1.0.0", | ||
'author': 'Numigi', | ||
'maintainer': 'Numigi', | ||
'website': 'https://bit.ly/numigi-com', | ||
'license': 'LGPL-3', | ||
'category': 'Connector', | ||
'summary': 'Define what is a github Pull Request as an odoo object.', | ||
'depends': [ | ||
'github_event', | ||
], | ||
'data': [ | ||
'security/ir.model.access.csv', | ||
'views/github_event.xml', | ||
'views/github_pull_request.xml', | ||
'views/menu.xml', | ||
], | ||
'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,185 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * github_pull_request | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 16.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2019-12-04 19:31+0000\n" | ||
"PO-Revision-Date: 2019-12-04 14:33-0500\n" | ||
"Last-Translator: <>\n" | ||
"Language-Team: \n" | ||
"Language: fr\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Plural-Forms: \n" | ||
"X-Generator: Poedit 2.0.6\n" | ||
|
||
#. module: github_pull_request | ||
#: sql_constraint:github.pull_request:0 | ||
msgid "A Pull Request already exists for this source" | ||
msgstr "Une pull request existe déjà pour cette source" | ||
|
||
#. module: github_pull_request | ||
#: selection:github.event,pull_request_state:0 | ||
#: selection:github.pull_request,state:0 | ||
msgid "Closed" | ||
msgstr "Fermé" | ||
|
||
#. module: github_pull_request | ||
#: model:ir.model.fields,field_description:github_pull_request.field_github_pull_request__create_uid | ||
msgid "Created by" | ||
msgstr "" | ||
|
||
#. module: github_pull_request | ||
#: model:ir.model.fields,field_description:github_pull_request.field_github_pull_request__create_date | ||
msgid "Created on" | ||
msgstr "" | ||
|
||
#. module: github_pull_request | ||
#: model:ir.model.fields,field_description:github_pull_request.field_github_pull_request__developer_id | ||
#: model_terms:ir.ui.view,arch_db:github_pull_request.github_pull_request_search | ||
msgid "Developer" | ||
msgstr "Développeur" | ||
|
||
#. module: github_pull_request | ||
#: model:ir.model.fields,field_description:github_pull_request.field_github_pull_request__display_name | ||
msgid "Display Name" | ||
msgstr "" | ||
|
||
#. module: github_pull_request | ||
#: model:ir.model.fields,field_description:github_pull_request.field_github_pull_request__event_ids | ||
#: model_terms:ir.ui.view,arch_db:github_pull_request.github_pull_request_form | ||
msgid "Events" | ||
msgstr "Événements" | ||
|
||
#. module: github_pull_request | ||
#: model_terms:ir.ui.view,arch_db:github_pull_request.github_pull_request_search | ||
msgid "Finished" | ||
msgstr "Fini" | ||
|
||
#. module: github_pull_request | ||
#: model:ir.model,name:github_pull_request.model_github_event | ||
msgid "Github Event" | ||
msgstr "" | ||
|
||
#. module: github_pull_request | ||
#: model:ir.model,name:github_pull_request.model_github_pull_request | ||
#: model_terms:ir.ui.view,arch_db:github_pull_request.github_pull_request_form | ||
#: model_terms:ir.ui.view,arch_db:github_pull_request.github_pull_request_search | ||
#: model_terms:ir.ui.view,arch_db:github_pull_request.github_pull_request_tree | ||
msgid "Github Pull Request" | ||
msgstr "" | ||
|
||
#. module: github_pull_request | ||
#: model:ir.model.fields,field_description:github_pull_request.field_github_pull_request__host | ||
msgid "Host" | ||
msgstr "Hôte" | ||
|
||
#. module: github_pull_request | ||
#: model:ir.model.fields,field_description:github_pull_request.field_github_pull_request__id | ||
msgid "ID" | ||
msgstr "" | ||
|
||
#. module: github_pull_request | ||
#: model:ir.model.fields,field_description:github_pull_request.field_github_pull_request____last_update | ||
msgid "Last Modified on" | ||
msgstr "" | ||
|
||
#. module: github_pull_request | ||
#: model:ir.model.fields,field_description:github_pull_request.field_github_pull_request__write_uid | ||
msgid "Last Updated by" | ||
msgstr "" | ||
|
||
#. module: github_pull_request | ||
#: model:ir.model.fields,field_description:github_pull_request.field_github_pull_request__write_date | ||
msgid "Last Updated on" | ||
msgstr "" | ||
|
||
#. module: github_pull_request | ||
#: model:ir.model.fields,field_description:github_pull_request.field_github_pull_request__latest_update | ||
msgid "Latest Update" | ||
msgstr "" | ||
|
||
#. module: github_pull_request | ||
#: selection:github.event,pull_request_state:0 | ||
#: selection:github.pull_request,state:0 | ||
msgid "Merged" | ||
msgstr "Mergé" | ||
|
||
#. module: github_pull_request | ||
#: selection:github.event,pull_request_state:0 | ||
#: selection:github.pull_request,state:0 | ||
#: model_terms:ir.ui.view,arch_db:github_pull_request.github_pull_request_search | ||
msgid "Open" | ||
msgstr "Ouvert" | ||
|
||
#. module: github_pull_request | ||
#: model:ir.model.fields,field_description:github_pull_request.field_github_pull_request__organization | ||
msgid "Organization" | ||
msgstr "Organisation" | ||
|
||
#. module: github_pull_request | ||
#: model:ir.model.fields,field_description:github_pull_request.field_github_event__pull_request_id | ||
#: model_terms:ir.ui.view,arch_db:github_pull_request.github_event_form_with_pull_request_fields | ||
msgid "Pull Request" | ||
msgstr "Pull Request" | ||
|
||
#. module: github_pull_request | ||
#: model:ir.model.fields,field_description:github_pull_request.field_github_pull_request__pull_request_number | ||
msgid "Pull Request Number" | ||
msgstr "Numéro de la pull request" | ||
|
||
#. module: github_pull_request | ||
#: model:ir.model.fields,field_description:github_pull_request.field_github_event__pull_request_state | ||
msgid "Pull Request State" | ||
msgstr "État de la pull request" | ||
|
||
#. module: github_pull_request | ||
#: model:ir.model.fields,field_description:github_pull_request.field_github_event__pull_request_title | ||
msgid "Pull Request Title" | ||
msgstr "Titre de la pull request" | ||
|
||
#. module: github_pull_request | ||
#: model:ir.model.fields,field_description:github_pull_request.field_github_event__pull_request_updated_at | ||
msgid "Pull Request Updated At" | ||
msgstr "Date mise à jour de la pull request" | ||
|
||
#. module: github_pull_request | ||
#: model:ir.actions.act_window,name:github_pull_request.pull_requests_action_window | ||
#: model:ir.ui.menu,name:github_pull_request.menu_github_pull_requests | ||
msgid "Pull Requests" | ||
msgstr "" | ||
|
||
#. module: github_pull_request | ||
#: model:ir.model.fields,field_description:github_pull_request.field_github_pull_request__repository | ||
#: model_terms:ir.ui.view,arch_db:github_pull_request.github_pull_request_search | ||
msgid "Repository" | ||
msgstr "Dépôt" | ||
|
||
#. module: github_pull_request | ||
#: model:ir.model.fields,field_description:github_pull_request.field_github_pull_request__source | ||
msgid "Source" | ||
msgstr "" | ||
|
||
#. module: github_pull_request | ||
#: model:ir.model.fields,field_description:github_pull_request.field_github_pull_request__state | ||
#: model_terms:ir.ui.view,arch_db:github_pull_request.github_event_form_with_pull_request_fields | ||
#: model_terms:ir.ui.view,arch_db:github_pull_request.github_pull_request_form | ||
#: model_terms:ir.ui.view,arch_db:github_pull_request.github_pull_request_search | ||
msgid "State" | ||
msgstr "État" | ||
|
||
#. module: github_pull_request | ||
#: model:ir.model.fields,field_description:github_pull_request.field_github_pull_request__title | ||
#: model_terms:ir.ui.view,arch_db:github_pull_request.github_event_form_with_pull_request_fields | ||
msgid "Title" | ||
msgstr "Titre" | ||
|
||
#. module: github_pull_request | ||
#: model_terms:ir.ui.view,arch_db:github_pull_request.github_event_form_with_pull_request_fields | ||
#: model_terms:ir.ui.view,arch_db:github_pull_request.github_pull_request_form | ||
msgid "Updated At" | ||
msgstr "Mise à jour" |
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,7 @@ | ||
# 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_event, | ||
github_pull_request, | ||
) |
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,13 @@ | ||
# 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). | ||
|
||
OPEN = 'open' | ||
MERGED = 'merged' | ||
CLOSED = 'closed' | ||
|
||
|
||
PULL_REQUEST_STATES = [ | ||
(OPEN, 'Open'), | ||
(MERGED, 'Merged'), | ||
(CLOSED, 'Closed'), | ||
] |
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,76 @@ | ||
# 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). | ||
|
||
import dateutil.parser | ||
from odoo import fields, models | ||
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT | ||
from .common import PULL_REQUEST_STATES, MERGED | ||
|
||
|
||
class GithubEvent(models.Model): | ||
|
||
_inherit = 'github.event' | ||
|
||
pull_request_id = fields.Many2one( | ||
'github.pull_request', | ||
'Pull Request', | ||
ondelete='restrict', | ||
index=True, | ||
copy=False, | ||
) | ||
pull_request_updated_at = fields.Datetime() | ||
pull_request_title = fields.Char() | ||
pull_request_state = fields.Selection( | ||
PULL_REQUEST_STATES, | ||
) | ||
|
||
def _find_existing_pull_request(self, url): | ||
return self.env['github.pull_request'].search( | ||
[ | ||
('source', '=', url), | ||
] | ||
) | ||
|
||
def _make_pull_request(self, url): | ||
return self.env['github.pull_request'].create({'source': url}) | ||
|
||
def _get_pull_request(self): | ||
url = self._get_value_from_payload('pull_request.html_url') | ||
existing_pull_request = self._find_existing_pull_request(url) | ||
return existing_pull_request or self._make_pull_request(url) | ||
|
||
def _get_pull_request_state(self): | ||
is_merged = self._get_value_from_payload('pull_request.merged_at') | ||
return ( | ||
MERGED if is_merged else self._get_value_from_payload('pull_request.state') | ||
) | ||
|
||
def _get_pull_request_updated_at(self): | ||
datetime_string = self._get_value_from_payload('pull_request.updated_at') | ||
datetime_obj = dateutil.parser.parse(datetime_string) | ||
naive_datetime_string = datetime_obj.strftime(DEFAULT_SERVER_DATETIME_FORMAT) | ||
return naive_datetime_string | ||
|
||
def _get_pull_request_title(self): | ||
return self._get_value_from_payload("pull_request.title") | ||
|
||
def _update_from_pull_request_fields(self): | ||
"""Update the event's data related to pull requests from its payload.""" | ||
self.write( | ||
{ | ||
'pull_request_id': self._get_pull_request().id, | ||
'pull_request_state': self._get_pull_request_state(), | ||
'pull_request_updated_at': self._get_pull_request_updated_at(), | ||
'pull_request_title': self._get_pull_request_title(), | ||
} | ||
) | ||
|
||
def process(self): | ||
super().process() | ||
|
||
is_pull_request_event = 'pull_request' in self.payload_serialized | ||
if is_pull_request_event: | ||
self._update_from_pull_request_fields() | ||
|
||
if self.pull_request_id.is_latest_event(self): | ||
self.pull_request_id.update_from_event(self) |
Oops, something went wrong.