Skip to content

Commit

Permalink
TA#72894 [IMP][16.0] pre-commit : add black hook (#27)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Majda EL MARIOULI <majdaelmariouli@gmail.com>
  • Loading branch information
rivo2302 and majouda authored Dec 12, 2024
1 parent 3fd2aab commit 9fe6d63
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 112 deletions.
26 changes: 13 additions & 13 deletions .docker_files/main/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{
'name': 'Main Module',
'version': '1.0.0',
'author': 'Numigi',
'maintainer': 'Numigi',
'website': 'https://www.numigi.com',
'license': 'LGPL-3',
'category': 'Other',
'summary': 'Install all addons required for testing.',
'depends': [
'base',
'github_event',
'github_pull_request'
"name": "Main Module",
"version": "1.0.0",
"author": "Numigi",
"maintainer": "Numigi",
"website": "https://www.numigi.com",
"license": "LGPL-3",
"category": "Other",
"summary": "Install all addons required for testing.",
"depends": [
"base",
"github_event",
"github_pull_request",
],
'installable': True,
"installable": True,
}
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ default_language_version:
python: python3
node: "14.13.0"
repos:
- repo: https://github.com/psf/black
rev: 22.8.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 3.8.3
hooks:
Expand Down
30 changes: 15 additions & 15 deletions github_event/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{
'name': 'Github Events',
'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 event as an odoo object',
'depends': [
'base_sparse_field',
"name": "Github Events",
"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 event as an odoo object",
"depends": [
"base_sparse_field",
],
'data': [
'security/ir.model.access.csv',
'views/github_event.xml',
'views/menu.xml',
"data": [
"security/ir.model.access.csv",
"views/github_event.xml",
"views/menu.xml",
],
'installable': True,
"installable": True,
}
10 changes: 5 additions & 5 deletions github_event/models/github_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class GithubEvent(models.Model):

_name = "github.event"
_description = "Github Event"
_order = 'id desc'
_order = "id desc"

action = fields.Char()
payload = fields.Text()
payload_serialized = Serialized(compute='_compute_payload_serialized')
payload_serialized = Serialized(compute="_compute_payload_serialized")

@api.depends('payload')
@api.depends("payload")
def _compute_payload_serialized(self):
events_with_payloads = self.filtered(lambda e: e.payload)
for event in events_with_payloads:
Expand All @@ -30,7 +30,7 @@ def _get_value_from_payload(self, path):
:return: the value contained at the given path.
"""
section = self.payload_serialized
keys = path.split('.')
keys = path.split(".")

for key in keys[:-1]:
if not isinstance(section, dict) or key not in section:
Expand All @@ -50,4 +50,4 @@ def process(self):
This method is intended to be inherited by other modules
to add extra behavior when processing a github event.
"""
self.action = self._get_value_from_payload('action')
self.action = self._get_value_from_payload("action")
9 changes: 4 additions & 5 deletions github_event/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@


class GithubEventCase(common.SavepointCase):

@classmethod
def setUpClass(cls):
super().setUpClass()
cls.event_1 = cls.env['github.event'].create({})
cls.event_2 = cls.env['github.event'].create({})
cls.event_1 = cls.env["github.event"].create({})
cls.event_2 = cls.env["github.event"].create({})

def _read_payload(self, filename):
test_folder = os.path.dirname(os.path.realpath(__file__))
payload_file_path = os.path.join(test_folder, 'data', filename)
with open(payload_file_path, 'r') as file:
payload_file_path = os.path.join(test_folder, "data", filename)
with open(payload_file_path, "r") as file:
return file.read()
9 changes: 4 additions & 5 deletions github_event/tests/test_github_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

@ddt
class TestGithubEvent(GithubEventCase):

@data(
('pull_request_1_merged.json', 'closed'),
('pull_request_2_closed.json', 'closed'),
('pull_request_2_reopened.json', 'reopened'),
('check_run_completed.json', 'completed'),
("pull_request_1_merged.json", "closed"),
("pull_request_2_closed.json", "closed"),
("pull_request_2_reopened.json", "reopened"),
("check_run_completed.json", "completed"),
)
@unpack
def test_action(self, filename, expected_action):
Expand Down
32 changes: 16 additions & 16 deletions github_pull_request/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
# 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',
"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',
"data": [
"security/ir.model.access.csv",
"views/github_event.xml",
"views/github_pull_request.xml",
"views/menu.xml",
],
'installable': True,
"installable": True,
}
12 changes: 6 additions & 6 deletions github_pull_request/models/common.py
Original file line number Diff line number Diff line change
@@ -1,13 +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'
OPEN = "open"
MERGED = "merged"
CLOSED = "closed"


PULL_REQUEST_STATES = [
(OPEN, 'Open'),
(MERGED, 'Merged'),
(CLOSED, 'Closed'),
(OPEN, "Open"),
(MERGED, "Merged"),
(CLOSED, "Closed"),
]
32 changes: 16 additions & 16 deletions github_pull_request/models/github_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

class GithubEvent(models.Model):

_inherit = 'github.event'
_inherit = "github.event"

pull_request_id = fields.Many2one(
'github.pull_request',
'Pull Request',
ondelete='restrict',
"github.pull_request",
"Pull Request",
ondelete="restrict",
index=True,
copy=False,
)
Expand All @@ -25,28 +25,28 @@ class GithubEvent(models.Model):
)

def _find_existing_pull_request(self, url):
return self.env['github.pull_request'].search(
return self.env["github.pull_request"].search(
[
('source', '=', url),
("source", "=", url),
]
)

def _make_pull_request(self, url):
return self.env['github.pull_request'].create({'source': 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')
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')
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')
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_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
Expand All @@ -58,17 +58,17 @@ 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(),
"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
is_pull_request_event = "pull_request" in self.payload_serialized
if is_pull_request_event:
self._update_from_pull_request_fields()

Expand Down
28 changes: 14 additions & 14 deletions github_pull_request/models/github_pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@


regex_github_source = re.compile(
r'https:\/\/(?P<host>[\w\.]+)/'
r'(?P<organization>\w+)/'
r'(?P<repository>[\w\-_]+)/'
r'pull/'
r'(?P<pull_request_number>\d+)'
r"https:\/\/(?P<host>[\w\.]+)/"
r"(?P<organization>\w+)/"
r"(?P<repository>[\w\-_]+)/"
r"pull/"
r"(?P<pull_request_number>\d+)"
)


class GithubPullRequest(models.Model):
_name = "github.pull_request"
_description = "Github Pull Request"
_rec_name = 'title'
_rec_name = "title"

title = fields.Char()
source = fields.Char(required=True)
Expand All @@ -27,24 +27,24 @@ class GithubPullRequest(models.Model):
default=OPEN,
)
developer_id = fields.Many2one(
'res.partner', 'Developer', ondelete='restrict', index=True
"res.partner", "Developer", ondelete="restrict", index=True
)
host = fields.Char(readonly=True)
organization = fields.Char(readonly=True)
repository = fields.Char(readonly=True)
pull_request_number = fields.Integer(readony=True)

_sql_constraints = [
('source', 'UNIQUE (source)', 'A Pull Request already exists for this source'),
("source", "UNIQUE (source)", "A Pull Request already exists for this source"),
]

@api.model
def create(self, vals):
updated_vals = update_according_to_source(vals['source'], vals)
updated_vals = update_according_to_source(vals["source"], vals)
return super().create(updated_vals)

def write(self, vals):
updated_vals = update_according_to_source(vals.get('source', ''), vals)
updated_vals = update_according_to_source(vals.get("source", ""), vals)
super().write(updated_vals)


Expand All @@ -57,13 +57,13 @@ def update_according_to_source(source: str, vals: dict) -> dict:

class GithubPullRequestWithEvents(models.Model):

_inherit = 'github.pull_request'
_inherit = "github.pull_request"

latest_update = fields.Datetime()
event_ids = fields.One2many(
'github.event',
'pull_request_id',
'Events',
"github.event",
"pull_request_id",
"Events",
)

def is_latest_event(self, event):
Expand Down
Loading

0 comments on commit 9fe6d63

Please sign in to comment.