Skip to content

Commit 7e41204

Browse files
committed
[MIG] github_connector: Migration to 19.0
1 parent 273e1b6 commit 7e41204

12 files changed

Lines changed: 117 additions & 93 deletions

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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,7 @@ 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(
287+
token = tools.config.get("github_token") or self.env["ir.config_parameter"].sudo().get_param(
289288
"github.access_token", default=""
290289
)
291290
if not token:

github_connector/models/github_organization.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,39 +119,39 @@ 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
)
127127
mapping = {
128-
data["organization_id"][0]: data["organization_id_count"] for data in data
128+
org.id: count for org, count in data
129129
}
130130
for item in self:
131131
item.repository_qty = mapping.get(item.id, 0)
132132

133133
@api.depends("team_ids.organization_id")
134134
def _compute_team_qty(self):
135-
data = self.env["github.team"].read_group(
135+
data = self.env["github.team"]._read_group(
136136
[("organization_id", "in", self.ids)],
137-
["organization_id"],
138-
["organization_id"],
137+
groupby=["organization_id"],
138+
aggregates=["__count"],
139139
)
140140
mapping = {
141-
data["organization_id"][0]: data["organization_id_count"] for data in data
141+
org.id: count for org, count in data
142142
}
143143
for item in self:
144144
item.team_qty = mapping.get(item.id, 0)
145145

146146
@api.depends("organization_serie_ids.organization_id")
147147
def _compute_organization_serie_qty(self):
148-
data = self.env["github.organization.serie"].read_group(
148+
data = self.env["github.organization.serie"]._read_group(
149149
[("organization_id", "in", self.ids)],
150-
["organization_id"],
151-
["organization_id"],
150+
groupby=["organization_id"],
151+
aggregates=["__count"],
152152
)
153153
mapping = {
154-
data["organization_id"][0]: data["organization_id_count"] for data in data
154+
org.id: count for org, count in data
155155
}
156156
for item in self:
157157
item.organization_serie_qty = mapping.get(item.id, 0)

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: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ 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)], groupby=["repository_id"], aggregates=["__count"]
9191
)
9292
mapping = {
93-
data["repository_id"][0]: data["repository_id_count"] for data in data
93+
repo.id: count for repo, count in data
9494
}
9595
for item in self:
9696
item.team_qty = mapping.get(item.id, 0)
@@ -104,11 +104,11 @@ 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)], groupby=["repository_id"], aggregates=["__count"]
109109
)
110110
mapping = {
111-
data["repository_id"][0]: data["repository_id_count"] for data in data
111+
repo.id: count for repo, count in data
112112
}
113113
for item in self:
114114
item.repository_branch_qty = mapping.get(item.id, 0)
@@ -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: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
import logging
99
import os
1010
import shutil
11+
import subprocess
1112
from datetime import datetime
12-
from subprocess import check_output
13+
1314

1415
from odoo import addons, api, exceptions, fields, models, tools
1516
from odoo.tools.safe_eval import safe_eval
@@ -162,15 +163,41 @@ 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["ir.config_parameter"].sudo().get_param(
169+
"github.access_token", default=""
170+
)
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("https://github.com/", f"https://{token}@github.com/")
176+
177+
# Build git clone command
178+
command = ["git", "clone", "-b", branch.name, clone_url, branch.local_path]
179+
180+
# Set environment to disable git credential prompts
181+
env = os.environ.copy()
182+
env['GIT_TERMINAL_PROMPT'] = '0' # Disable credential prompts
183+
env['GIT_ASKPASS'] = 'echo' # Return empty string for password prompts
184+
185+
subprocess.run(
186+
command,
187+
capture_output=True,
188+
text=True,
189+
timeout=300, # 5 minute timeout
190+
check=True,
191+
env=env,
192+
stdin=subprocess.DEVNULL # Don't wait for input
193+
)
167194
branch.write(
168195
{"last_download_date": datetime.today(), "state": "to_analyze"}
169196
)
170197
else:
171198
# Update repository
172199
try:
173-
res = check_output(
200+
res = subprocess.check_output(
174201
["git", "pull", "origin", branch.name], cwd=branch.local_path
175202
)
176203
vals = {"last_download_date": datetime.today()}
@@ -217,7 +244,7 @@ def _get_analysis_rules(self):
217244
def _call_cloc_command(self):
218245
"""Execute the cloc command and save the result temporarily to access it in
219246
multiple places."""
220-
res = check_output(["cloc", "--by-file", "--json", self.local_path])
247+
res = subprocess.check_output(["cloc", "--by-file", "--json", self.local_path])
221248
return json.loads(res)
222249

223250
def set_analysis_rule_info(self):
@@ -323,7 +350,7 @@ def _analyze_code(self):
323350
# Mark the branch as analyzed
324351
branch.write(vals)
325352
if partial_commit:
326-
self._cr.commit() # pylint: disable=invalid-commit
353+
self.env.cr.commit() # pylint: disable=invalid-commit
327354
except Exception as e:
328355
_logger.warning(
329356
"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

github_connector/models/res_partner.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,10 @@ class ResPartner(models.Model):
4747
)
4848

4949
# Constraints Section
50-
_sql_constraints = [
51-
(
52-
"github_login_uniq",
53-
"unique(github_name)",
54-
"Two different partners cannot have the same Github Login",
55-
)
56-
]
50+
_github_login_uniq = models.Constraint(
51+
"unique(github_name)",
52+
"Two different partners cannot have the same Github Login",
53+
)
5754

5855
@api.constrains("github_name", "is_company")
5956
def _check_login_company(self):
@@ -74,10 +71,10 @@ def _compute_organization_qty(self):
7471

7572
@api.depends("github_team_partner_ids")
7673
def _compute_github_team_qty(self):
77-
data = self.env["github.team.partner"].read_group(
78-
[("partner_id", "in", self.ids)], ["partner_id"], ["partner_id"]
74+
data = self.env["github.team.partner"]._read_group(
75+
[("partner_id", "in", self.ids)], groupby=["partner_id"], aggregates=["__count"]
7976
)
80-
mapping = {data["partner_id"][0]: data["partner_id_count"] for data in data}
77+
mapping = {partner.id: count for partner, count in data}
8178
for item in self:
8279
item.github_team_qty = mapping.get(item.id, 0)
8380

github_connector/security/res_groups.xml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,23 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
66
-->
77
<odoo>
88
<record id="base.group_no_one" model="res.groups">
9-
<field name="users" eval="[(4, ref('base.user_root'))]" />
9+
<field name="user_ids" eval="[(4, ref('base.user_root'))]" />
1010
</record>
11+
12+
<record id="privilege_github_connector" model="res.groups.privilege">
13+
<field name="name">Github Connector</field>
14+
<field name="category_id" ref="module_category_github_connector"/>
15+
</record>
16+
1117
<record id="group_github_connector_user" model="res.groups">
12-
<field name="name">Connector Github User</field>
13-
<field name="category_id" ref="module_category_github_connector" />
18+
<field name="name">User</field>
19+
<field name="privilege_id" ref="privilege_github_connector" />
1420
</record>
1521
<record id="group_github_connector_manager" model="res.groups">
16-
<field name="name">Connector Github Manager</field>
17-
<field name="category_id" ref="module_category_github_connector" />
22+
<field name="name">Manager</field>
23+
<field name="privilege_id" ref="privilege_github_connector" />
1824
<field
19-
name="users"
25+
name="user_ids"
2026
eval="[(4, ref('base.user_admin')), (4, ref('base.user_root'))]"
2127
/>
2228
<field

github_connector/views/view_github_repository.xml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
1515
filter_domain="['|', ('name', 'ilike', self), ('description', 'ilike', self)]"
1616
/>
1717
<field name="organization_id" />
18-
<group expand="1" string="Group By">
19-
<filter
20-
string="Organization"
21-
name="organization"
22-
context="{'group_by' : 'organization_id'}"
23-
/>
24-
</group>
18+
<filter
19+
string="Organization"
20+
name="organization"
21+
context="{'group_by' : 'organization_id'}"
22+
/>
2523
</search>
2624
</field>
2725
</record>

0 commit comments

Comments
 (0)