Skip to content

Commit 085a791

Browse files
committed
[MIG] github_connector/github_connector_odoo: Migration to 19.0
1 parent 36a7cc3 commit 085a791

24 files changed

+322
-243
lines changed

github_connector/README.rst

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
.. image:: https://odoo-community.org/readme-banner-image
2+
:target: https://odoo-community.org/get-involved?utm_source=readme
3+
:alt: Odoo Community Association
4+
15
================
26
Github Connector
37
================
@@ -13,17 +17,17 @@ Github Connector
1317
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1418
:target: https://odoo-community.org/page/development-status
1519
:alt: Beta
16-
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
20+
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
1721
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1822
:alt: License: AGPL-3
1923
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Finterface--github-lightgray.png?logo=github
20-
:target: https://github.com/OCA/interface-github/tree/18.0/github_connector
24+
:target: https://github.com/OCA/interface-github/tree/19.0/github_connector
2125
:alt: OCA/interface-github
2226
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23-
:target: https://translation.odoo-community.org/projects/interface-github-18-0/interface-github-18-0-github_connector
27+
:target: https://translation.odoo-community.org/projects/interface-github-19-0/interface-github-19-0-github_connector
2428
:alt: Translate me on Weblate
2529
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26-
:target: https://runboat.odoo-community.org/builds?repo=OCA/interface-github&target_branch=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/interface-github&target_branch=19.0
2731
:alt: Try me on Runboat
2832

2933
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -107,7 +111,7 @@ This module provides 4 crons that you can enable:
107111
- Download Source Code for All Github Branches (``cron_download_code``)
108112
- Analyze Source Code for All Github Branches (``cron_analyze_code``)
109113

110-
.. |image| image:: https://raw.githubusercontent.com/OCA/interface-github/18.0/github_connector/static/description/github_settings.png
114+
.. |image| image:: https://raw.githubusercontent.com/OCA/interface-github/19.0/github_connector/static/description/github_settings.png
111115

112116
Usage
113117
=====
@@ -294,23 +298,23 @@ This module provides several reports
294298

295299
|github_repository_branch_rule_info_report|
296300

297-
.. |sync_organization| image:: https://raw.githubusercontent.com/OCA/interface-github/18.0/github_connector/static/description/sync_organization.png
298-
.. |github_organization_kanban| image:: https://raw.githubusercontent.com/OCA/interface-github/18.0/github_connector/static/description/github_organization_kanban.png
299-
.. |github_organization_series| image:: https://raw.githubusercontent.com/OCA/interface-github/18.0/github_connector/static/description/github_organization_series.png
300-
.. |github_organization_external_services| image:: https://raw.githubusercontent.com/OCA/interface-github/18.0/github_connector/static/description/github_organization_external_services.png
301-
.. |github_organization_sync_buttons| image:: https://raw.githubusercontent.com/OCA/interface-github/18.0/github_connector/static/description/github_organization_sync_buttons.png
302-
.. |github_team_kanban| image:: https://raw.githubusercontent.com/OCA/interface-github/18.0/github_connector/static/description/github_team_kanban.png
303-
.. |github_team_partner_kanban| image:: https://raw.githubusercontent.com/OCA/interface-github/18.0/github_connector/static/description/github_team_partner_kanban.png
304-
.. |github_team_repository_kanban| image:: https://raw.githubusercontent.com/OCA/interface-github/18.0/github_connector/static/description/github_team_repository_kanban.png
305-
.. |github_repository_kanban| image:: https://raw.githubusercontent.com/OCA/interface-github/18.0/github_connector/static/description/github_repository_kanban.png
306-
.. |github_repository_branch_kanban| image:: https://raw.githubusercontent.com/OCA/interface-github/18.0/github_connector/static/description/github_repository_branch_kanban.png
307-
.. |wizard_download_analyze| image:: https://raw.githubusercontent.com/OCA/interface-github/18.0/github_connector/static/description/wizard_download_analyze.png
308-
.. |github_repository_branch_list| image:: https://raw.githubusercontent.com/OCA/interface-github/18.0/github_connector/static/description/github_repository_branch_list.png
309-
.. |wizard_create_team| image:: https://raw.githubusercontent.com/OCA/interface-github/18.0/github_connector/static/description/wizard_create_team.png
310-
.. |wizard_create_repository| image:: https://raw.githubusercontent.com/OCA/interface-github/18.0/github_connector/static/description/wizard_create_repository.png
311-
.. |reporting_branches_by_serie| image:: https://raw.githubusercontent.com/OCA/interface-github/18.0/github_connector/static/description/reporting_branches_by_serie.png
312-
.. |reporting_sizes_by_serie| image:: https://raw.githubusercontent.com/OCA/interface-github/18.0/github_connector/static/description/reporting_sizes_by_serie.png
313-
.. |github_repository_branch_rule_info_report| image:: https://raw.githubusercontent.com/OCA/interface-github/18.0/github_connector/static/description/github_repository_branch_rule_info_report.png
301+
.. |sync_organization| image:: https://raw.githubusercontent.com/OCA/interface-github/19.0/github_connector/static/description/sync_organization.png
302+
.. |github_organization_kanban| image:: https://raw.githubusercontent.com/OCA/interface-github/19.0/github_connector/static/description/github_organization_kanban.png
303+
.. |github_organization_series| image:: https://raw.githubusercontent.com/OCA/interface-github/19.0/github_connector/static/description/github_organization_series.png
304+
.. |github_organization_external_services| image:: https://raw.githubusercontent.com/OCA/interface-github/19.0/github_connector/static/description/github_organization_external_services.png
305+
.. |github_organization_sync_buttons| image:: https://raw.githubusercontent.com/OCA/interface-github/19.0/github_connector/static/description/github_organization_sync_buttons.png
306+
.. |github_team_kanban| image:: https://raw.githubusercontent.com/OCA/interface-github/19.0/github_connector/static/description/github_team_kanban.png
307+
.. |github_team_partner_kanban| image:: https://raw.githubusercontent.com/OCA/interface-github/19.0/github_connector/static/description/github_team_partner_kanban.png
308+
.. |github_team_repository_kanban| image:: https://raw.githubusercontent.com/OCA/interface-github/19.0/github_connector/static/description/github_team_repository_kanban.png
309+
.. |github_repository_kanban| image:: https://raw.githubusercontent.com/OCA/interface-github/19.0/github_connector/static/description/github_repository_kanban.png
310+
.. |github_repository_branch_kanban| image:: https://raw.githubusercontent.com/OCA/interface-github/19.0/github_connector/static/description/github_repository_branch_kanban.png
311+
.. |wizard_download_analyze| image:: https://raw.githubusercontent.com/OCA/interface-github/19.0/github_connector/static/description/wizard_download_analyze.png
312+
.. |github_repository_branch_list| image:: https://raw.githubusercontent.com/OCA/interface-github/19.0/github_connector/static/description/github_repository_branch_list.png
313+
.. |wizard_create_team| image:: https://raw.githubusercontent.com/OCA/interface-github/19.0/github_connector/static/description/wizard_create_team.png
314+
.. |wizard_create_repository| image:: https://raw.githubusercontent.com/OCA/interface-github/19.0/github_connector/static/description/wizard_create_repository.png
315+
.. |reporting_branches_by_serie| image:: https://raw.githubusercontent.com/OCA/interface-github/19.0/github_connector/static/description/reporting_branches_by_serie.png
316+
.. |reporting_sizes_by_serie| image:: https://raw.githubusercontent.com/OCA/interface-github/19.0/github_connector/static/description/reporting_sizes_by_serie.png
317+
.. |github_repository_branch_rule_info_report| image:: https://raw.githubusercontent.com/OCA/interface-github/19.0/github_connector/static/description/github_repository_branch_rule_info_report.png
314318

315319
Known issues / Roadmap
316320
======================
@@ -345,7 +349,7 @@ Bug Tracker
345349
Bugs are tracked on `GitHub Issues <https://github.com/OCA/interface-github/issues>`_.
346350
In case of trouble, please check there if your issue has already been reported.
347351
If you spotted it first, help us to smash it by providing a detailed and welcomed
348-
`feedback <https://github.com/OCA/interface-github/issues/new?body=module:%20github_connector%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
352+
`feedback <https://github.com/OCA/interface-github/issues/new?body=module:%20github_connector%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
349353

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

@@ -390,6 +394,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
390394
mission is to support the collaborative development of Odoo features and
391395
promote its widespread use.
392396

393-
This module is part of the `OCA/interface-github <https://github.com/OCA/interface-github/tree/18.0/github_connector>`_ project on GitHub.
397+
This module is part of the `OCA/interface-github <https://github.com/OCA/interface-github/tree/19.0/github_connector>`_ project on GitHub.
394398

395399
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

github_connector/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
"name": "Github Connector",
99
"summary": "Synchronize information from Github repositories",
10-
"version": "18.0.1.0.0",
10+
"version": "19.0.1.0.0",
1111
"category": "Connector",
1212
"license": "AGPL-3",
1313
"author": "Odoo Community Association (OCA), GRAP, Akretion, Tecnativa",

github_connector/models/abstract_github_model.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,9 @@ def _update_from_github_data(self, data):
284284
item.write(to_write)
285285

286286
def get_github_connector(self):
287-
ICP = self.env["ir.config_parameter"]
288-
token = tools.config.get("github_token") or ICP.get_param(
289-
"github.access_token", default=""
290-
)
287+
token = tools.config.get("github_token") or self.env[
288+
"ir.config_parameter"
289+
].sudo().get_param("github.access_token", default="")
291290
if not token:
292291
raise UserError(
293292
self.env._(

github_connector/models/github_organization.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -119,40 +119,34 @@ def _compute_member_qty(self):
119119

120120
@api.depends("repository_ids.organization_id")
121121
def _compute_repository_qty(self):
122-
data = self.env["github.repository"].read_group(
122+
data = self.env["github.repository"]._read_group(
123123
[("organization_id", "in", self.ids)],
124-
["organization_id"],
125-
["organization_id"],
124+
groupby=["organization_id"],
125+
aggregates=["__count"],
126126
)
127-
mapping = {
128-
data["organization_id"][0]: data["organization_id_count"] for data in data
129-
}
127+
mapping = {org.id: count for org, count in data}
130128
for item in self:
131129
item.repository_qty = mapping.get(item.id, 0)
132130

133131
@api.depends("team_ids.organization_id")
134132
def _compute_team_qty(self):
135-
data = self.env["github.team"].read_group(
133+
data = self.env["github.team"]._read_group(
136134
[("organization_id", "in", self.ids)],
137-
["organization_id"],
138-
["organization_id"],
135+
groupby=["organization_id"],
136+
aggregates=["__count"],
139137
)
140-
mapping = {
141-
data["organization_id"][0]: data["organization_id_count"] for data in data
142-
}
138+
mapping = {org.id: count for org, count in data}
143139
for item in self:
144140
item.team_qty = mapping.get(item.id, 0)
145141

146142
@api.depends("organization_serie_ids.organization_id")
147143
def _compute_organization_serie_qty(self):
148-
data = self.env["github.organization.serie"].read_group(
144+
data = self.env["github.organization.serie"]._read_group(
149145
[("organization_id", "in", self.ids)],
150-
["organization_id"],
151-
["organization_id"],
146+
groupby=["organization_id"],
147+
aggregates=["__count"],
152148
)
153-
mapping = {
154-
data["organization_id"][0]: data["organization_id_count"] for data in data
155-
}
149+
mapping = {org.id: count for org, count in data}
156150
for item in self:
157151
item.organization_serie_qty = mapping.get(item.id, 0)
158152

github_connector/models/github_organization_serie.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ class GithubOrganizationSerie(models.Model):
2020
required=True,
2121
)
2222

23-
_sql_constraints = [
24-
(
25-
"sequence_organization_uniq",
26-
"unique(organization_id, sequence)",
27-
"Sequence serie must be unique by organization.",
28-
)
29-
]
23+
_sequence_organization_uniq = models.Constraint(
24+
"unique(organization_id, sequence)",
25+
"Sequence serie must be unique by organization.",
26+
)

github_connector/models/github_repository.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ def _compute_ignore(self):
8686

8787
@api.depends("team_ids")
8888
def _compute_team_qty(self):
89-
data = self.env["github.team.repository"].read_group(
90-
[("repository_id", "in", self.ids)], ["repository_id"], ["repository_id"]
89+
data = self.env["github.team.repository"]._read_group(
90+
[("repository_id", "in", self.ids)],
91+
groupby=["repository_id"],
92+
aggregates=["__count"],
9193
)
92-
mapping = {
93-
data["repository_id"][0]: data["repository_id_count"] for data in data
94-
}
94+
mapping = {repo.id: count for repo, count in data}
9595
for item in self:
9696
item.team_qty = mapping.get(item.id, 0)
9797

@@ -104,12 +104,12 @@ def _compute_complete_name(self):
104104

105105
@api.depends("repository_branch_ids.repository_id")
106106
def _compute_repository_branch_qty(self):
107-
data = self.env["github.repository.branch"].read_group(
108-
[("repository_id", "in", self.ids)], ["repository_id"], ["repository_id"]
107+
data = self.env["github.repository.branch"]._read_group(
108+
[("repository_id", "in", self.ids)],
109+
groupby=["repository_id"],
110+
aggregates=["__count"],
109111
)
110-
mapping = {
111-
data["repository_id"][0]: data["repository_id_count"] for data in data
112-
}
112+
mapping = {repo.id: count for repo, count in data}
113113
for item in self:
114114
item.repository_branch_qty = mapping.get(item.id, 0)
115115

@@ -196,9 +196,13 @@ def button_sync_branch(self):
196196
branch_ids.append(branch.id)
197197
else:
198198
_logger.warning(
199-
"the branch '%s'/'%s' has been ignored.",
199+
"The branch '%s'/'%s' has been ignored because '%s' is not "
200+
"configured as a series for organization '%s'. "
201+
"Please add this series in the organization configuration.",
200202
repository.name,
201203
gh_branch.name,
204+
gh_branch.name,
205+
repository.organization_id.name,
202206
)
203207
repository.repository_branch_ids = [(6, 0, branch_ids)]
204208

github_connector/models/github_repository_branch.py

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import logging
99
import os
1010
import shutil
11+
import subprocess
1112
from datetime import datetime
12-
from subprocess import check_output
1313

1414
from odoo import addons, api, exceptions, fields, models, tools
1515
from odoo.tools.safe_eval import safe_eval
@@ -162,15 +162,50 @@ def _download_code(self):
162162
branch.local_path,
163163
)
164164
) from None
165-
command = f"git clone {gh_repo.clone_url} -b {branch.name} {branch.local_path}" # noqa: E501
166-
os.system(command)
165+
166+
# Get GitHub token for authenticated cloning
167+
token = tools.config.get("github_token") or self.env[
168+
"ir.config_parameter"
169+
].sudo().get_param("github.access_token", default="")
170+
171+
# Use authenticated URL if token is available
172+
clone_url = gh_repo.clone_url
173+
if token and clone_url.startswith("https://github.com/"):
174+
clone_url = clone_url.replace(
175+
"https://github.com/", f"https://{token}@github.com/"
176+
)
177+
178+
# Build git clone command
179+
command = [
180+
"git",
181+
"clone",
182+
"-b",
183+
branch.name,
184+
clone_url,
185+
branch.local_path,
186+
]
187+
188+
# Set environment to disable git credential prompts
189+
env = os.environ.copy()
190+
env["GIT_TERMINAL_PROMPT"] = "0" # Disable credential prompts
191+
env["GIT_ASKPASS"] = "echo" # Return empty string for password prompts
192+
193+
subprocess.run(
194+
command,
195+
capture_output=True,
196+
text=True,
197+
timeout=300, # 5 minute timeout
198+
check=True,
199+
env=env,
200+
stdin=subprocess.DEVNULL, # Don't wait for input
201+
)
167202
branch.write(
168203
{"last_download_date": datetime.today(), "state": "to_analyze"}
169204
)
170205
else:
171206
# Update repository
172207
try:
173-
res = check_output(
208+
res = subprocess.check_output(
174209
["git", "pull", "origin", branch.name], cwd=branch.local_path
175210
)
176211
vals = {"last_download_date": datetime.today()}
@@ -217,7 +252,7 @@ def _get_analysis_rules(self):
217252
def _call_cloc_command(self):
218253
"""Execute the cloc command and save the result temporarily to access it in
219254
multiple places."""
220-
res = check_output(["cloc", "--by-file", "--json", self.local_path])
255+
res = subprocess.check_output(["cloc", "--by-file", "--json", self.local_path])
221256
return json.loads(res)
222257

223258
def set_analysis_rule_info(self):
@@ -323,7 +358,7 @@ def _analyze_code(self):
323358
# Mark the branch as analyzed
324359
branch.write(vals)
325360
if partial_commit:
326-
self._cr.commit() # pylint: disable=invalid-commit
361+
self.env.cr.commit() # pylint: disable=invalid-commit
327362
except Exception as e:
328363
_logger.warning(
329364
"Cannot analyze branch %s so skipping it, error is: %s",

github_connector/models/github_team.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,19 @@ def _compute_complete_name(self):
8484

8585
@api.depends("partner_ids")
8686
def _compute_partner_qty(self):
87-
data = self.env["github.team.partner"].read_group(
88-
[("team_id", "in", self.ids)], ["team_id"], ["team_id"]
87+
data = self.env["github.team.partner"]._read_group(
88+
[("team_id", "in", self.ids)], groupby=["team_id"], aggregates=["__count"]
8989
)
90-
mapping = {data["team_id"][0]: data["team_id_count"] for data in data}
90+
mapping = {team.id: count for team, count in data}
9191
for item in self:
9292
item.partner_qty = mapping.get(item.id, 0)
9393

9494
@api.depends("repository_ids")
9595
def _compute_repository_qty(self):
96-
data = self.env["github.team.repository"].read_group(
97-
[("team_id", "in", self.ids)], ["team_id"], ["team_id"]
96+
data = self.env["github.team.repository"]._read_group(
97+
[("team_id", "in", self.ids)], groupby=["team_id"], aggregates=["__count"]
9898
)
99-
mapping = {data["team_id"][0]: data["team_id_count"] for data in data}
99+
mapping = {team.id: count for team, count in data}
100100
for item in self:
101101
item.repository_qty = mapping.get(item.id, 0)
102102

0 commit comments

Comments
 (0)