Skip to content

Commit

Permalink
[15.0][MIG] connector_jira: Migrate to version 15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sonhd91 committed Jun 29, 2022
1 parent 02e9451 commit 169e159
Show file tree
Hide file tree
Showing 39 changed files with 295 additions and 190 deletions.
26 changes: 16 additions & 10 deletions connector_jira/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ JIRA Connector
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fconnector--jira-lightgray.png?logo=github
:target: https://github.com/OCA/connector-jira/tree/13.0/connector_jira
:target: https://github.com/OCA/connector-jira/tree/15.0/connector_jira
:alt: OCA/connector-jira
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/connector-jira-13-0/connector-jira-13-0-connector_jira
:target: https://translation.odoo-community.org/projects/connector-jira-15-0/connector-jira-15-0-connector_jira
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/233/13.0
:target: https://runbot.odoo-community.org/runbot/233/15.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -204,7 +204,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/connector-jira/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/connector-jira/issues/new?body=module:%20connector_jira%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/connector-jira/issues/new?body=module:%20connector_jira%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand All @@ -219,16 +219,22 @@ Authors
Contributors
~~~~~~~~~~~~

* Guewen Baconnier <guewen.baconnier@camptocamp.com>
* Akim Juillerat <akim.juillerat@camptocamp.com>

* Damien Crier
* Patrick Tombez <patrick.tombez@camptocamp.com>
* Thierry Ducrest
* Timon Tschanz <timon.tschanz@camptocamp.com>
* jcoux <julien.coux@camptocamp.com>
* Tonow-c2c
* Simone Orsi <simahawk@gmail.com>
* Alexey Pelykh <alexey.pelykh@brainbeanapps.com>
* `Camptocamp <https://camptocamp.com>`_:

* Timon Tschanz <timon.tschanz@camptocamp.com>
* jcoux <julien.coux@camptocamp.com>
* Patrick Tombez <patrick.tombez@camptocamp.com>
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
* Akim Juillerat <akim.juillerat@camptocamp.com>
* `Trobz <https://trobz.com>`_:

* Son Ho <sonhd@trobz.com>

Maintainers
~~~~~~~~~~~
Expand All @@ -243,6 +249,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/connector-jira <https://github.com/OCA/connector-jira/tree/13.0/connector_jira>`_ project on GitHub.
This module is part of the `OCA/connector-jira <https://github.com/OCA/connector-jira/tree/15.0/connector_jira>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
11 changes: 5 additions & 6 deletions connector_jira/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{
"name": "JIRA Connector",
"version": "13.0.1.1.0",
"version": "15.0.1.0.0",
"author": "Camptocamp,Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Connector",
Expand All @@ -20,11 +20,9 @@
"requests",
"jira",
"oauthlib",
# these are dependencies but as they don't have the same name of
# package / module, we can't list them here
# 'requests-oauthlib',
# 'requests-toolbelt',
# 'PyJWT',
"requests-oauthlib",
"requests-toolbelt",
"PyJWT",
"cryptography",
],
},
Expand All @@ -44,6 +42,7 @@
"wizards/jira_account_analytic_line_import_views.xml",
"security/ir.model.access.csv",
"data/cron.xml",
"data/queue_job_data.xml",
],
"demo": ["demo/jira_backend_demo.xml"],
"installable": True,
Expand Down
10 changes: 5 additions & 5 deletions connector_jira/components/backend_adapter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016-2019 Camptocamp SA
# Copyright 2016-2022 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

import logging
Expand Down Expand Up @@ -81,7 +81,7 @@ def handle_404(self):
err.text,
err.url,
)
)
) from err
raise

@contextmanager
Expand All @@ -96,12 +96,12 @@ def handle_user_api_errors(self):
except requests.exceptions.ConnectionError as err:
_logger.exception("Jira ConnectionError")
message = _("Error during connection with Jira: %s") % (err,)
raise exceptions.UserError(message)
raise exceptions.UserError(message) from err
except jira.exceptions.JIRAError as err:
_logger.exception("Jira JIRAError")
message = _("Jira Error: %s") % (err,)
raise exceptions.UserError(message)
raise exceptions.UserError(message) from err
except IDMissingInBackend as err:
_logger.exception("Jira 404 for an ID")
message = _("Record does not exist in Jira: %s") % (err,)
raise exceptions.UserError(message)
raise exceptions.UserError(message) from err
4 changes: 2 additions & 2 deletions connector_jira/components/exporter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016-2019 Camptocamp SA
# Copyright 2016-2022 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

"""
Expand Down Expand Up @@ -156,7 +156,7 @@ def _retry_unique_violation(self):
"%s\n\n"
"Likely due to 2 concurrent jobs wanting to create "
"the same record. The job will be retried later." % err
)
) from err
else:
raise

Expand Down
31 changes: 15 additions & 16 deletions connector_jira/components/importer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016-2019 Camptocamp SA
# Copyright 2016-2022 Camptocamp SA
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

Expand Down Expand Up @@ -208,7 +208,7 @@ def _retry_unique_violation(self):
"%s\n\n"
"Likely due to 2 concurrent jobs wanting to create "
"the same record. The job will be retried later." % err
)
) from err
else:
raise

Expand Down Expand Up @@ -272,20 +272,19 @@ def do_in_new_work_context(self, model_name=None):
This can be used to make a preemptive check in a new transaction,
for instance to see if another transaction already made the work.
"""
with odoo.api.Environment.manage():
registry = odoo.registry(self.env.cr.dbname)
with closing(registry.cursor()) as cr:
try:
new_env = odoo.api.Environment(cr, self.env.uid, self.env.context)
backend = self.backend_record.with_env(new_env)
with backend.work_on(model_name or self.model._name) as work:
yield work
except Exception:
cr.rollback()
raise
else:
if not tools.config["test_enable"]:
cr.commit() # pylint: disable=invalid-commit
registry = odoo.registry(self.env.cr.dbname)
with closing(registry.cursor()) as cr:
try:
new_env = odoo.api.Environment(cr, self.env.uid, self.env.context)
backend = self.backend_record.with_env(new_env)
with backend.work_on(model_name or self.model._name) as work:
yield work
except Exception:
cr.rollback()
raise
else:
if not tools.config["test_enable"]:
cr.commit() # pylint: disable=invalid-commit

def _handle_record_missing_on_jira(self):
"""Hook called when we are importing a record missing on Jira
Expand Down
65 changes: 65 additions & 0 deletions connector_jira/data/queue_job_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<!-- Queue Job Channel -->
<record id="import_root" model="queue.job.channel">
<field name="name">connector_jira.import</field>
<field name="parent_id" ref="queue_job.channel_root" />
</record>

<!-- AccountAnalyticLine Queue Job Function -->

<record
id="job_function_import_record_jira_account_analytic_line"
model="queue.job.function"
>
<field name="model_id" ref="connector_jira.model_jira_account_analytic_line" />
<field name="method">import_record</field>
<field name="channel_id" ref="connector_jira.import_root" />
<field name="related_action" eval='{"func_name": "related_action_jira_link"}' />
</record>

<!-- JiraBinding Queue Job Function -->

<record id="job_function_import_batch_jira_binding" model="queue.job.function">
<field name="model_id" ref="connector_jira.model_jira_binding" />
<field name="method">import_batch</field>
<field name="channel_id" ref="connector_jira.import_root" />
</record>

<record id="job_function_run_batch_timestamp" model="queue.job.function">
<field name="model_id" ref="connector_jira.model_jira_binding" />
<field name="method">run_batch_timestamp</field>
<field name="channel_id" ref="connector_jira.import_root" />
</record>

<record id="job_function_delete_record" model="queue.job.function">
<field name="model_id" ref="connector_jira.model_jira_binding" />
<field name="method">delete_record</field>
<field name="channel_id" ref="connector_jira.import_root" />
</record>

<record id="job_function_import_record_jira_binding" model="queue.job.function">
<field name="model_id" ref="connector_jira.model_jira_binding" />
<field name="method">import_record</field>
<field name="channel_id" ref="connector_jira.import_root" />
<field name="related_action" eval='{"func_name": "related_action_jira_link"}' />
</record>

<record id="job_function_export_record" model="queue.job.function">
<field name="model_id" ref="connector_jira.model_jira_binding" />
<field name="method">export_record</field>
<field name="channel_id" ref="connector_jira.import_root" />
<field
name="related_action"
eval='{"func_name": "related_action_unwrap_binding"}'
/>
</record>

<!-- JiraIssueType Queue Job Function -->

<record id="job_function_import_batch_jira_issue_type" model="queue.job.function">
<field name="model_id" ref="connector_jira.model_jira_issue_type" />
<field name="method">import_batch</field>
<field name="channel_id" ref="connector_jira.import_root" />
</record>
</odoo>
5 changes: 1 addition & 4 deletions connector_jira/models/account_analytic_line/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016-2019 Camptocamp SA
# Copyright 2016-2022 Camptocamp SA
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

Expand All @@ -8,7 +8,6 @@
from odoo import _, api, exceptions, fields, models

from odoo.addons.component.core import Component
from odoo.addons.queue_job.job import job, related_action

UpdatedWorklog = namedtuple(
"UpdatedWorklog",
Expand Down Expand Up @@ -105,8 +104,6 @@ def _compute_jira_issue_url(self):
record.jira_epic_issue_key
)

@job(default_channel="root.connector_jira.import")
@related_action(action="related_action_jira_link")
@api.model
def import_record(self, backend, issue_id, worklog_id, force=False):
"""Import a worklog from JIRA"""
Expand Down
9 changes: 5 additions & 4 deletions connector_jira/models/account_analytic_line/importer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2016-2019 Camptocamp SA
# Copyright 2016-2022 Camptocamp SA
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

Expand Down Expand Up @@ -85,11 +85,12 @@ def author(self, record):
email = jira_author["emailAddress"]
raise MappingError(
_(
'No user found with login "%s" or email "%s".'
'No user found with login "%(jira_author_key)s" or email "%(email)s".'
"You must create a user or link it manually if the "
"login/email differs."
"login/email differs.",
jira_author_key=jira_author_key,
email=email,
)
% (jira_author_key, email)
)
employee = (
self.env["hr.employee"]
Expand Down
38 changes: 18 additions & 20 deletions connector_jira/models/jira_backend/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright: 2015 LasLabs, Inc.
# Copyright 2016-2019 Camptocamp SA
# Copyright 2016-2022 Camptocamp SA
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

Expand Down Expand Up @@ -29,8 +29,8 @@
try:
from jira import JIRA, JIRAError
from jira.utils import json_loads
except ImportError:
pass # already logged in components/backend_adapter.py
except ImportError as err:
_logger.debug(err)

try:
from cryptography.hazmat.backends import default_backend
Expand All @@ -42,18 +42,17 @@

@contextmanager
def new_env(env):
with api.Environment.manage():
registry = odoo.registry(env.cr.dbname)
with closing(registry.cursor()) as cr:
new_env = api.Environment(cr, env.uid, env.context)
try:
yield new_env
except Exception:
cr.rollback()
raise
else:
if not tools.config["test_enable"]:
cr.commit() # pylint: disable=invalid-commit
registry = odoo.registry(env.cr.dbname)
with closing(registry.cursor()) as cr:
new_env = api.Environment(cr, env.uid, env.context)
try:
yield new_env
except Exception:
cr.rollback()
raise
else:
if not tools.config["test_enable"]:
cr.commit() # pylint: disable=invalid-commit


class JiraBackend(models.Model):
Expand Down Expand Up @@ -147,7 +146,6 @@ def _default_consumer_key(self):
)

use_webhooks = fields.Boolean(
string="Use Webhooks",
readonly=True,
help="Webhooks need to be configured on the Jira instance. "
"When activated, synchronization from Jira is blazing fast. "
Expand Down Expand Up @@ -192,7 +190,6 @@ def _default_consumer_key(self):
"The name of the field is something like 'customfield_10003'. ",
)
epic_link_on_epic = fields.Boolean(
string="Epic link on epic",
help="Epics on JIRA cannot be linked to another epic. Check this box"
"to fill the epic field with itself on Odoo.",
)
Expand Down Expand Up @@ -475,9 +472,11 @@ def check_connection(self):
try:
self.get_api_client().myself()
except (ValueError, requests.exceptions.ConnectionError) as err:
raise exceptions.UserError(_("Failed to connect (%s)") % (err,))
raise exceptions.UserError(_("Failed to connect (%s)") % (err,)) from err
except JIRAError as err:
raise exceptions.UserError(_("Failed to connect (%s)") % (err.text,))
raise exceptions.UserError(
_("Failed to connect (%s)") % (err.text,)
) from err
raise exceptions.UserError(_("Connection successful"))

def import_project_task(self):
Expand Down Expand Up @@ -572,7 +571,6 @@ class JiraBackendTimestamp(models.Model):
required=True,
)
from_date_field = fields.Char(
string="From Date Field",
required=True,
)
# For worklogs, jira allows to work with milliseconds
Expand Down
Loading

0 comments on commit 169e159

Please sign in to comment.