Skip to content

Commit 72afeec

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

25 files changed

+340
-253
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: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from urllib.request import urlopen
1010

1111
import pytz
12-
from github import Auth, Github # pylint: disable=missing-manifest-dependency
13-
from github.GithubException import ( # pylint: disable=missing-manifest-dependency
12+
from github import Auth, Github
13+
from github.GithubException import (
1414
UnknownObjectException,
1515
)
1616

@@ -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: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
55
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
66

7-
# pylint: disable=missing-manifest-dependency
87
from github.GithubException import GithubException
98

109
from odoo import api, exceptions, fields, models
@@ -106,6 +105,7 @@ def full_update(self):
106105

107106
@api.model
108107
def cron_update_organization_team(self):
108+
# pylint: disable=no-search-all
109109
organizations = self.search([])
110110
organizations.full_update()
111111
organizations.mapped("team_ids").full_update()
@@ -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: 16 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

@@ -173,6 +173,7 @@ def full_update(self):
173173

174174
@api.model
175175
def cron_update_branch_list(self):
176+
# pylint: disable=no-search-all
176177
branches = self.search([])
177178
branches.button_sync_branch()
178179
return True
@@ -196,9 +197,13 @@ def button_sync_branch(self):
196197
branch_ids.append(branch.id)
197198
else:
198199
_logger.warning(
199-
"the branch '%s'/'%s' has been ignored.",
200+
"The branch '%s'/'%s' has been ignored because '%s' is not "
201+
"configured as a series for organization '%s'. "
202+
"Please add this series in the organization configuration.",
200203
repository.name,
201204
gh_branch.name,
205+
gh_branch.name,
206+
repository.organization_id.name,
202207
)
203208
repository.repository_branch_ids = [(6, 0, branch_ids)]
204209

github_connector/models/github_repository_branch.py

Lines changed: 43 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
@@ -127,6 +127,7 @@ def button_analyze_code(self):
127127

128128
@api.model
129129
def cron_download_all(self):
130+
# pylint: disable=no-search-all
130131
branches = self.search([])
131132
branches._download_code()
132133
return True
@@ -162,15 +163,50 @@ def _download_code(self):
162163
branch.local_path,
163164
)
164165
) from None
165-
command = f"git clone {gh_repo.clone_url} -b {branch.name} {branch.local_path}" # noqa: E501
166-
os.system(command)
166+
167+
# Get GitHub token for authenticated cloning
168+
token = tools.config.get("github_token") or self.env[
169+
"ir.config_parameter"
170+
].sudo().get_param("github.access_token", default="")
171+
172+
# Use authenticated URL if token is available
173+
clone_url = gh_repo.clone_url
174+
if token and clone_url.startswith("https://github.com/"):
175+
clone_url = clone_url.replace(
176+
"https://github.com/", f"https://{token}@github.com/"
177+
)
178+
179+
# Build git clone command
180+
command = [
181+
"git",
182+
"clone",
183+
"-b",
184+
branch.name,
185+
clone_url,
186+
branch.local_path,
187+
]
188+
189+
# Set environment to disable git credential prompts
190+
env = os.environ.copy()
191+
env["GIT_TERMINAL_PROMPT"] = "0" # Disable credential prompts
192+
env["GIT_ASKPASS"] = "echo" # Return empty string for password prompts
193+
194+
subprocess.run(
195+
command,
196+
capture_output=True,
197+
text=True,
198+
timeout=300, # 5 minute timeout
199+
check=True,
200+
env=env,
201+
stdin=subprocess.DEVNULL, # Don't wait for input
202+
)
167203
branch.write(
168204
{"last_download_date": datetime.today(), "state": "to_analyze"}
169205
)
170206
else:
171207
# Update repository
172208
try:
173-
res = check_output(
209+
res = subprocess.check_output(
174210
["git", "pull", "origin", branch.name], cwd=branch.local_path
175211
)
176212
vals = {"last_download_date": datetime.today()}
@@ -217,7 +253,7 @@ def _get_analysis_rules(self):
217253
def _call_cloc_command(self):
218254
"""Execute the cloc command and save the result temporarily to access it in
219255
multiple places."""
220-
res = check_output(["cloc", "--by-file", "--json", self.local_path])
256+
res = subprocess.check_output(["cloc", "--by-file", "--json", self.local_path])
221257
return json.loads(res)
222258

223259
def set_analysis_rule_info(self):
@@ -323,7 +359,7 @@ def _analyze_code(self):
323359
# Mark the branch as analyzed
324360
branch.write(vals)
325361
if partial_commit:
326-
self._cr.commit() # pylint: disable=invalid-commit
362+
self.env.cr.commit() # pylint: disable=invalid-commit
327363
except Exception as e:
328364
_logger.warning(
329365
"Cannot analyze branch %s so skipping it, error is: %s",
@@ -409,6 +445,7 @@ def _compute_github_url(self):
409445

410446

411447
class GithubRepositoryBranchRuleInfo(models.TransientModel):
448+
# pylint: disable=no-wizard-in-models
412449
_inherit = "github.analysis.rule.info.mixin"
413450
_name = "github.repository.branch.rule.info"
414451
_description = " Github Repository Branch Rule Info"

0 commit comments

Comments
 (0)