Skip to content

Commit

Permalink
[IMP] connector_jira: pre-commit auto fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SilvioC2C committed Jun 24, 2024
1 parent 259c0c7 commit 2e2299d
Show file tree
Hide file tree
Showing 23 changed files with 468 additions and 421 deletions.
251 changes: 133 additions & 118 deletions connector_jira/README.rst

Large diffs are not rendered by default.

9 changes: 2 additions & 7 deletions connector_jira/components/backend_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _post_get_json(
try:
r_json = jira.utils.json_loads(r)
except ValueError as e:
logging.error("{}\n{}".format(e, r.text))
logging.error(f"{e}\n{r.text}")
raise e
return r_json

Expand All @@ -76,12 +76,7 @@ def handle_404(self):
yield
except jira.exceptions.JIRAError as err:
if err.status_code == 404:
raise IDMissingInBackend(
"{} (url: {})".format(
err.text,
err.url,
)
) from err
raise IDMissingInBackend(f"{err.text} (url: {err.url})") from err
raise

@contextmanager
Expand Down
1 change: 1 addition & 0 deletions connector_jira/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def _validate_jwt_token(self):
jwt_token = authorization_header[4:]
decoded = jwt.get_unverified_header(jwt_token)
if "kid" in decoded:
# pylint: disable=E8106
response = requests.get(
f"https://connect-install-keys.atlassian.com/{decoded['kid']}"
)
Expand Down
4 changes: 2 additions & 2 deletions connector_jira/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def from_string(value):
if isinstance(value, datetime):
if value.tzinfo:
raise ValueError(
"MilliDatetime field expects a naive datetime: %s" % value
f"MilliDatetime field expects a naive datetime: {value}"
)
return value
if len(value) > fields.DATETIME_LENGTH:
Expand All @@ -58,6 +58,6 @@ def convert_to_cache(self, value, record, validate=True):
return False
if isinstance(value, date) and not isinstance(value, datetime):
raise TypeError(
"%s (field %s) must be string or datetime" ", not date." % (value, self)
f"{value} (field {self}) must be string or datetime, not date."
)
return self.from_string(value)
3 changes: 1 addition & 2 deletions connector_jira/models/account_analytic_line/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,7 @@ def yield_read(self, worklog_ids):
for chunk in self._chunks(worklog_ids, 1000):
payload = json.dumps({"ids": chunk})
result = self._post_get_json(path, data=payload)
for worklog in result:
yield worklog
yield from result

def updated_since(self, since=None):
path = "worklog/updated"
Expand Down
10 changes: 5 additions & 5 deletions connector_jira/models/account_analytic_line/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ def author(self, record):
email = jira_author.get("emailAddress", "<unknown>")
raise MappingError(
_(
'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.",
jira_author_key=jira_author_key,
email=email,
"No user found with login '%(key)s' or email '%(mail)s'."
" You must create a user or link it manually if the"
" login/email differs.",
key=jira_author_key,
mail=email,
)
)
employee = (
Expand Down
17 changes: 9 additions & 8 deletions connector_jira/models/jira_backend/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ class JiraBackend(models.Model):
application_key = fields.Char(
compute="_compute_application_key",
store=True,
help="The name that will be used as application key to register the app on the "
"Atlassian marketplace website. It has to be unique among all apps on the marketplace.",
help="The name that will be used as application key to register the app on the"
" Atlassian marketplace website.\n"
"It has to be unique among all apps on the marketplace.",
)
company_id = fields.Many2one(
comodel_name="res.company",
Expand Down Expand Up @@ -464,7 +465,7 @@ def _scheduler_delete_analytic_line(self):
backend.search([]).delete_analytic_line()

def make_issue_url(self, jira_issue_id):
return urllib.parse.urljoin(self.uri, "/browse/{}".format(jira_issue_id))
return urllib.parse.urljoin(self.uri, f"/browse/{jira_issue_id}")

def _get_base_url(self):
fqdn = self.env["ir.config_parameter"].get_param("web.base.url", "")
Expand Down Expand Up @@ -536,11 +537,11 @@ def _install_app(self, payload):
'sharedSecret': Use to sign JWT tokens
'serverVersion': DEPRECATED
'pluginsVersion': DEPRECATED
'baseUrl': URL prefix for this Atlassian product instance. All of its REST endpoints
begin with this `baseUrl`. Do not use the `baseUrl` as an identifier for the
Atlassian product as this value may not be unique.
'displayUrl': If the Atlassian product instance has an associated custom domain, this
is the URL through which users will access the product.
'baseUrl': URL prefix for this Atlassian product instance. All of its REST
endpoints begin with this `baseUrl`. Do not use the `baseUrl` as an
identifier for the Atlassian product as this value may not be unique.
'displayUrl': If the Atlassian product instance has an associated custom
domain, this is the URL through which users will access the product.
'productType': 'jira',
'description': 'Atlassian JIRA at https: //testcamptocamp.atlassian.net ',
'eventType': 'installed',
Expand Down
11 changes: 5 additions & 6 deletions connector_jira/models/project_project/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def _selection_project_type(self):
def _add_sql_constraints(self):
# we replace the sql constraint by a python one
# to include the organizations
for (key, definition, _msg) in self._sql_constraints:
conname = "{}_{}".format(self._table, key)
for key, definition, _msg in self._sql_constraints:
conname = f"{self._table}_{key}"
if key == "jira_binding_uniq":
has_definition = tools.constraint_definition(
self.env.cr, self._table, conname
Expand Down Expand Up @@ -256,7 +256,7 @@ def name_get(self):
for project in self:
project_id, name = super(ProjectProject, project).name_get()[0]
if project.jira_key:
name = "[{}] {}".format(project.jira_key, name)
name = f"[{project.jira_key}] {name}"
names.append((project_id, name))
return names

Expand Down Expand Up @@ -289,7 +289,6 @@ def create_and_link_jira(self):


class ProjectAdapter(Component):

_name = "jira.project.adapter"
_inherit = ["jira.webservice.adapter"]
_apply_on = ["jira.project.project"]
Expand Down Expand Up @@ -362,7 +361,7 @@ def create_shared(self, key=None, name=None, shared_key=None, lead=None):
if self.logging:
logging.error(
"Unexpected result while running create shared project."
"Server response saved in %s for further investigation "
"[HTTP response=%s]." % (f.name, r.status_code)
f" Server response saved in {f.name} for further investigation"
f" [HTTP response={r.status_code}]."
)
return False
2 changes: 1 addition & 1 deletion connector_jira/models/project_task/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def name_get(self):
for task in self:
task_id, name = super(ProjectTask, task).name_get()[0]
if task.jira_compound_key:
name = "[{}] {}".format(task.jira_compound_key, name)
name = f"[{task.jira_compound_key}] {name}"
names.append((task_id, name))
return names

Expand Down
4 changes: 2 additions & 2 deletions connector_jira/models/project_task/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,15 @@ def _create_data(self, map_record, **kwargs):
map_record,
jira_epic=self.jira_epic,
project_binding=self.project_binding,
**kwargs
**kwargs,
)

def _update_data(self, map_record, **kwargs):
return super()._update_data(
map_record,
jira_epic=self.jira_epic,
project_binding=self.project_binding,
**kwargs
**kwargs,
)

def _import(self, binding, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion connector_jira/models/res_users/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def link_with_jira(self, backends=None, raise_if_mismatch=False):
"key": resolve_by_key,
"value": resolve_by_value,
"error": "other_user_bound",
"detail": "linked with {}".format(existing.login),
"detail": f"linked with {existing.login}",
}
)
continue
Expand Down
3 changes: 3 additions & 0 deletions connector_jira/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
20 changes: 20 additions & 0 deletions connector_jira/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
- [Camptocamp](https://camptocamp.com):

- Damien Crier
- Thierry Ducrest
- Tonow-c2c
- Simone Orsi \<<[email protected]>\>
- Timon Tschanz \<<[email protected]>\>
- jcoux \<<[email protected]>\>
- Patrick Tombez \<<[email protected]>\>
- Guewen Baconnier \<<[email protected]>\>
- Akim Juillerat \<<[email protected]>\>
- Alexandre Fayolle \<<[email protected]>\>

- [CorporateHub](https://corporatehub.eu/)

- Alexey Pelykh \<<[email protected]>\>

- [Trobz](https://trobz.com):

> - Son Ho \<<[email protected]>\>
19 changes: 0 additions & 19 deletions connector_jira/readme/CONTRIBUTORS.rst

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
This module adds Jira synchronization feature. It works with Jira Cloud by behaving as an Atlassian Connect App.
This module adds Jira synchronization feature. It works with Jira Cloud
by behaving as an Atlassian Connect App.
84 changes: 84 additions & 0 deletions connector_jira/readme/INSTALL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
You need the following Python packages:

- requests
- jira
- oauthlib
- requests-oauthlib
- requests-toolbelt
- PyJWT
- cryptography
- atlassian-jwt

Once the addon is installed, follow these steps:

## Job Queue

In `odoo.conf`, configure similarly:

```
[queue_job]
channels = root:1,root.connector_jira.import:2
```

## Backend

1. Open the menu Connectors \> Jira \> Backends
2. Create a new Jira Backend
- Put the name you want
- You can also select the company where records will be created and
the default project template used when Odoo will create the
projects in Jira
- Save
3. Make note of the value of the App Descriptor URL (important: make
sure that the system parameter web.base.url is set properly. For
local development you will want to use ngrok to make your computer
reachable over https from Jira Cloud).

## Installing the backend as a Jira App

In case this gets outdated, refer to
<https://developer.atlassian.com/platform/marketplace/listing-connect-apps/#list-a-connect-app>

1. Login on marketplace.atlassian.com (possibly create an account)
2. On the top right corner, the icon with your avatar leads to a menu
-\> select the Publish an App entry
3. On the Publish a new app screen:
- select a Vendor (normally your company)
- upload your app: select Provide a URL to your artifact
- click on the Enter URL button
- paste the App Descriptor URL in the pop-up and click on the Done
button
- the Name field should get populated from the name of your backend
- Compatible application: select Jira
- build number: can be kept as is
4. Click on the Save as private button (!) Important: do not click the
"Next: Make public" button. That flow would allow anyone on Jira
Cloud to install your backend.
5. On the next screen, you can go to the "Private Listings" page, and
click on the "Create a token" button: this token can be used to
install the app on your Jira instance.

## Installing the Jira App on your Jira Cloud instance

1. Connect to your Jira instance with an account with Admin access
2. In the Apps menu, select Manage your apps
3. In the Apps screen, click on the Settings link which is under the
User-installed apps list
4. In the settings screen, check the Enable private listings box, and
click on Apply
5. Refresh the Apps page: you should see an Upload app link: click on
it
6. On the Upload app dialog, paste the token URL you received in the
previous procedure, and click on Upload

## Configuration of the Backend

Going back to Odoo, the backend should now be in the Running state, with
some information filled in, such as the Jira URI.

**Configure the Epic Link**

If you use Epics, you need to click on "Configure Epic Link", Odoo will
search the name of the custom field used for the Epic Link.

Congratulations, you're done!
Loading

0 comments on commit 2e2299d

Please sign in to comment.