|
8 | 8 | import logging |
9 | 9 | import os |
10 | 10 | import shutil |
| 11 | +import subprocess |
11 | 12 | from datetime import datetime |
12 | | -from subprocess import check_output |
| 13 | + |
13 | 14 |
|
14 | 15 | from odoo import addons, api, exceptions, fields, models, tools |
15 | 16 | from odoo.tools.safe_eval import safe_eval |
@@ -162,15 +163,41 @@ def _download_code(self): |
162 | 163 | branch.local_path, |
163 | 164 | ) |
164 | 165 | ) 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 | + ) |
167 | 194 | branch.write( |
168 | 195 | {"last_download_date": datetime.today(), "state": "to_analyze"} |
169 | 196 | ) |
170 | 197 | else: |
171 | 198 | # Update repository |
172 | 199 | try: |
173 | | - res = check_output( |
| 200 | + res = subprocess.check_output( |
174 | 201 | ["git", "pull", "origin", branch.name], cwd=branch.local_path |
175 | 202 | ) |
176 | 203 | vals = {"last_download_date": datetime.today()} |
@@ -217,7 +244,7 @@ def _get_analysis_rules(self): |
217 | 244 | def _call_cloc_command(self): |
218 | 245 | """Execute the cloc command and save the result temporarily to access it in |
219 | 246 | 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]) |
221 | 248 | return json.loads(res) |
222 | 249 |
|
223 | 250 | def set_analysis_rule_info(self): |
@@ -323,7 +350,7 @@ def _analyze_code(self): |
323 | 350 | # Mark the branch as analyzed |
324 | 351 | branch.write(vals) |
325 | 352 | if partial_commit: |
326 | | - self._cr.commit() # pylint: disable=invalid-commit |
| 353 | + self.env.cr.commit() # pylint: disable=invalid-commit |
327 | 354 | except Exception as e: |
328 | 355 | _logger.warning( |
329 | 356 | "Cannot analyze branch %s so skipping it, error is: %s", |
|
0 commit comments