diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e67d950 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +# generated from manifests external_dependencies +GitPython +github3.py +pathspec diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..66bc2cb --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo_test_helper diff --git a/vcp_github/README.rst b/vcp_github/README.rst new file mode 100644 index 0000000..07627b8 --- /dev/null +++ b/vcp_github/README.rst @@ -0,0 +1,211 @@ +========== +Vcp Github +========== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:086596db3dcb4fa7565fc97cf01ccd22449731243622d4587a1f609eab8bc121 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fversion--control--platform-lightgray.png?logo=github + :target: https://github.com/OCA/version-control-platform/tree/18.0/vcp_github + :alt: OCA/version-control-platform +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/version-control-platform-18-0/version-control-platform-18-0-vcp_github + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/version-control-platform&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +[ This file must be max 2-3 paragraphs, and is required. + +The goal of this document is to explain quickly the features of this +module: “what” this module does and “what” it is for. ] + +Example: + +This module extends the functionality of ... to support ... and to allow +users to ... + +**Table of contents** + +.. contents:: + :local: + +Use Cases / Context +=================== + +[ This file is optional but strongly suggested to allow end-users to +evaluate the module's usefulness in their context. ] + +BUSINESS NEED: It should explain the “why” of the module: + +- what is the business requirement that generated the need to develop + this module +- in which context or use cases this module can be useful (practical + examples are welcome!). + +APPROACH: It could also explain the approach to address the mentioned +need. + +USEFUL INFORMATION: It can also inform on related modules: + +- modules it depends on and their features +- other modules that can work well together with this one +- suggested setups where the module is useful (eg: multicompany, + multi-website) + +Installation +============ + +[ This file must only be present if there are very specific installation +instructions, such as installing non-python dependencies. The audience +is systems administrators. ] + +To install this module, you need to: + +1. Do this ... + +Configuration +============= + +[ This file is not always required; it should explain **how to configure +the module before using it**; it is aimed at users with administration +privileges. + +Please be detailed on the path to configuration (eg: do you need to +activate developer mode?), describe step by step configurations and the +use of screenshots is strongly recommended.] + +To configure this module, you need to: + +- Go to *App* > Menu > Menu item +- Activate boolean… > save +- … + +Usage +===== + +[ This file is required and contains the instructions on **“how”** to +use the module for end-users. + +If the module does not have a visible impact on the user interface, just +add the following sentence: + + This module does not impact the user interface. + +If that’s not the case, please make sure that every usage step is +covered and remember that images speak more than words!] + +To use this module, you need to: + +- Go to *App* > Menu > Menu item + + *insert screenshot!* + +- In “Contact” form, add a value to field *xyz* > save + + *insert screenshot!* + +- The value of *xyz* is now displayed in the list view. + + *insert screenshot!* + +Known issues / Roadmap +====================== + +[ Enumerate known caveats and future potential improvements. It is +mostly intended for end-users, and can also help potential new +contributors discovering new features to implement. ] + +- ... + +Changelog +========= + +[ The change log. The goal of this file is to help readers understand +changes between version. The primary audience is end users and +integrators. Purely technical changes such as code refactoring must not +be mentioned here. + +This file may contain ONE level of section titles, underlined with the ~ +(tilde) character. Other section markers are forbidden and will likely +break the structure of the README.rst or other documents where this +fragment is included. ] + +11.0.x.y.z (YYYY-MM-DD) +----------------------- + +- [BREAKING] Breaking changes come first. + (`#70 `__) +- [ADD] New feature. (`#74 `__) +- [FIX] Correct this. (`#71 `__) + +11.0.x.y.z (YYYY-MM-DD) +----------------------- + +- ... + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Dixmit + +Contributors +------------ + +- Firstname Lastname email.address@example.org (optional company website + url) +- Second Person second.person@example.org (optional company website url) + +Other credits +------------- + +[ This file is optional and contains additional credits, other than +authors, contributors, and maintainers. ] + +The development of this module has been financially supported by: + +- Company 1 name +- Company 2 name + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/version-control-platform `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/vcp_github/__init__.py b/vcp_github/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/vcp_github/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/vcp_github/__manifest__.py b/vcp_github/__manifest__.py new file mode 100644 index 0000000..668f42d --- /dev/null +++ b/vcp_github/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Vcp Github", + "summary": """Integrate Virtual Control Platform with Github""", + "version": "18.0.1.0.0", + "license": "AGPL-3", + "author": "Dixmit,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/version-control-platform", + "depends": [ + "vcp_management", + ], + "external_dependencies": { + "python": ["github3.py"], + }, + "data": [ + "data/data.xml", + ], + "demo": [], +} diff --git a/vcp_github/data/data.xml b/vcp_github/data/data.xml new file mode 100644 index 0000000..2a6e4c6 --- /dev/null +++ b/vcp_github/data/data.xml @@ -0,0 +1,11 @@ + + + + GitHub + github + + + GitHub + + + diff --git a/vcp_github/models/__init__.py b/vcp_github/models/__init__.py new file mode 100644 index 0000000..c6c3d79 --- /dev/null +++ b/vcp_github/models/__init__.py @@ -0,0 +1,5 @@ +from . import vcp_host +from . import vcp_platform +from . import vcp_repository +from . import vcp_user +from . import vcp_organization diff --git a/vcp_github/models/vcp_host.py b/vcp_github/models/vcp_host.py new file mode 100644 index 0000000..e320947 --- /dev/null +++ b/vcp_github/models/vcp_host.py @@ -0,0 +1,19 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import _, api, models +from odoo.exceptions import ValidationError + + +class VcpHost(models.Model): + _inherit = "vcp.host" + + @api.constrains("type_id") + def _check_kind_github(self): + for record in self.filtered(lambda r: r.type_id.code == "github"): + platforms = self.search( + [("id", "!=", record.id), ("type_id.code", "=", "github")], + limit=1, + ) + if platforms: + raise ValidationError(_("Only one GitHub Host type is allowed.")) diff --git a/vcp_github/models/vcp_organization.py b/vcp_github/models/vcp_organization.py new file mode 100644 index 0000000..be5339a --- /dev/null +++ b/vcp_github/models/vcp_organization.py @@ -0,0 +1,15 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + + +from odoo import models + + +class VcpOrganization(models.Model): + _inherit = "vcp.organization" + + def _get_contributor_url(self): + result = super()._get_contributor_url() + if not result and self.host_id.type_id.code == "github": + return f"https://github.com/{self.external_id}" + return result diff --git a/vcp_github/models/vcp_platform.py b/vcp_github/models/vcp_platform.py new file mode 100644 index 0000000..b8534bc --- /dev/null +++ b/vcp_github/models/vcp_platform.py @@ -0,0 +1,82 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import base64 +from datetime import datetime + +import github3 +import requests +from pytz import UTC + +from odoo import _, fields, models +from odoo.exceptions import ValidationError + + +class VcpPlatform(models.Model): + _inherit = "vcp.platform" + + def _get_git_url_github(self, repository): + return f"https://github.com/{self.name}/{repository.name}" + + def _get_github_clients(self): + git = [] + for key in self.key_ids: + git.append(github3.login(token=key.name)) + return git + + def _update_information_github(self): + self.ensure_one() + clients = self._get_github_clients() + if not clients: + raise ValidationError( + _("No github clients configured. Please enter at least an API Key.") + ) + org = clients[0].organization(self.name) + self.short_description = org.name + self.description = org.description + if org.avatar_url: + response = requests.get(org.avatar_url, timeout=10) + response.raise_for_status() + self.image_1920 = base64.b64encode(response.content) + repos = org.repositories() + for repo in repos: + self._update_github_repository(repo) + self.last_update = fields.Datetime.now() + + def _parse_github_date(self, date): + if not date: + return False + return UTC.normalize( + datetime.fromisoformat(date.replace("Z", "+00:00")) + ).replace(tzinfo=None) + + def _update_github_repository(self, repo): + vals = { + "created_at": self._parse_github_date(repo.created_at), + "stargazers_count": repo.stargazers_count, + "fork_count": repo.forks_count, + "watchers_count": repo.watchers_count, + "description": repo.description, + } + repository = self.env["vcp.repository"].search( + [ + ("name", "=", repo.name), + ("platform_id", "=", self.id), + ], + limit=1, + ) + if not repository: + repository = ( + self.env["vcp.repository"] + .sudo() + .create( + { + "name": repo.name, + "platform_id": self.id, + "from_date": vals.get("created_at"), + **vals, + } + ) + ) + else: + repository.sudo().write(vals) diff --git a/vcp_github/models/vcp_repository.py b/vcp_github/models/vcp_repository.py new file mode 100644 index 0000000..cadc3e6 --- /dev/null +++ b/vcp_github/models/vcp_repository.py @@ -0,0 +1,220 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import logging +from datetime import datetime, timedelta + +import github3 +from github3 import pulls +from pytz import UTC + +from odoo import fields, models +from odoo.exceptions import ValidationError + +_logger = logging.getLogger(__name__) + + +class VcpRepository(models.Model): + _inherit = "vcp.repository" + + def _update_branches_github(self): + self.ensure_one() + client = self.platform_id._get_github_clients()[0] + try: + repo = client.repository(self.platform_id.name, self.name) + original_branches = self.branch_ids + existing_branches = {b.branch_id.name: b for b in self.branch_ids} + found_branches = self.env["vcp.repository.branch"] + for branch in repo.branches(): + if branch.name in existing_branches: + existing_branches[branch.name].sudo().write( + {"last_commit": branch.commit.sha} + ) + found_branches |= existing_branches[branch.name] + else: + self.env["vcp.repository.branch"].sudo().create( + { + "repository_id": self.id, + "branch_id": self.platform_id._get_branch(branch.name), + "last_commit": branch.commit.sha, + } + ) + (original_branches - found_branches).sudo().unlink() + except github3.exceptions.ForbiddenError as e: + _logger.error(e) + rate = client.rate_limit() + reset = fields.Datetime.to_string( + datetime.utcfromtimestamp(rate["resources"]["core"]["reset"]) + ) + raise ValidationError(self.env._(f"Reset on {reset}")) from e + + def _parse_github_pr(self, pr, client): + origin_data = pr.as_dict() + comments_url = pr.comments_url + comments_req = client.session.get(comments_url) + comments = comments_req.json() + while comments_req.links.get("next"): + comments_url = comments_req.links["next"]["url"] + comments_req = client.session.get(comments_url) + comments += comments_req.json() + reviews_url = pr.reviews().url + reviews_req = client.session.get(reviews_url) + reviews = reviews_req.json() + while reviews_req.links.get("next"): + reviews_url = reviews_req.links["next"]["url"] + reviews_req = client.session.get(reviews_url) + reviews += reviews_req.json() + return ( + str(pr.id), + { + "user_id": self.platform_id.host_id._get_user(pr.user.login), + "repository_id": self.id, + "branch_id": self.platform_id._get_branch(pr.base.ref), + "organization_id": self.platform_id.host_id._get_organization( + pr.head.repo[0] + ), + "url": pr.html_url, + "state": pr.state, + "name": pr.title, + "is_merged": any(label["name"] == "merged 🎉" for label in pr.labels) + or pr.is_merged(), + "created_at": self.platform_id._parse_github_date( + origin_data["created_at"] + ), + "closed_at": self.platform_id._parse_github_date( + origin_data["closed_at"] + ), + "number": pr.number, + "updated_at": self.platform_id._parse_github_date( + origin_data["updated_at"] + ), + "label_ids": [fields.Command.clear()] + + [ + fields.Command.link( + self.env["vcp.request.label"]._get_label(label["name"]) + ) + for label in origin_data["labels"] + ], + "commits": origin_data["commits"], + "total_comments": origin_data["comments"], + "review_comments": origin_data["review_comments"], + "additions": origin_data["additions"], + "deletions": origin_data["deletions"], + }, + [ + { + "id": str(c["id"]), + "user_id": c.get("user") + and self.platform_id.host_id._get_user(c["user"].get("login")), + "body": c["body"], + "created_at": self.platform_id._parse_github_date(c["created_at"]), + "updated_at": self.platform_id._parse_github_date(c["updated_at"]), + } + for c in comments + ], + [ + { + "id": str(r["id"]), + "user_id": r.get("user") + and self.platform_id.host_id._get_user(r["user"].get("login")), + "body": r["body"], + "submitted_at": self.platform_id._parse_github_date( + r.get("submitted_at") + ), + "state": r["state"]["keyword"] + if isinstance(r["state"], dict) + else r["state"], + } + for r in reviews + ], + ) + + def _update_information_github( + self, update_interval_days=None, client_for_search=0 + ): + self.ensure_one() + clients = self.platform_id._get_github_clients() + try: + start = UTC.localize(self.from_date) + end = min( + start + + timedelta( + days=update_interval_days or self.platform_id.update_interval_days + ), + UTC.localize(datetime.now()), + ) + start += timedelta( + days=-1 + ) # Add buffer day to avoid missing PRs on boundary dates + i = client_for_search % len(clients) + for pr in clients[i].search_issues( + f"is:pr repo:{self.platform_id.name}/{self.name} " + f"updated:{start.isoformat()}..{end.isoformat()}" + ): + i = (1 + i) % len(clients) + pr_id, pr_data, comments, reviews = self._parse_github_pr( + clients[i]._instance_or_null( + pulls.PullRequest, + clients[i]._json( + pr.issue._get(pr.issue.pull_request_urls.get("url")), 200 + ), + ), + clients[i], + ) + opr = self.env["vcp.request"].search( + [("external_id", "=", pr_id), ("repository_id", "=", self.id)], + limit=1, + ) + if not opr: + opr = ( + self.env["vcp.request"] + .sudo() + .create({"external_id": pr_id, **pr_data}) + ) + else: + opr.sudo().write(pr_data) + for comment in comments: + comment_id = comment.pop("id") + ocomment = self.env["vcp.comment"].search( + [ + ("external_id", "=", comment_id), + ("repository_id", "=", self.id), + ], + limit=1, + ) + if not ocomment: + self.env["vcp.comment"].sudo().create( + { + "external_id": comment_id, + "request_id": opr.id, + **comment, + } + ) + else: + ocomment.sudo().write(comment) + for review in reviews: + review_id = review.pop("id") + oreview = self.env["vcp.review"].search( + [ + ("external_id", "=", review_id), + ("repository_id", "=", self.id), + ], + limit=1, + ) + if not oreview: + self.env["vcp.review"].sudo().create( + { + "external_id": review_id, + "request_id": opr.id, + **review, + } + ) + else: + oreview.sudo().write(review) + self.sudo().from_date = end.replace(tzinfo=None) + except github3.exceptions.ForbiddenError as e: + _logger.error(e) + rate = clients[i].rate_limit() + reset = fields.Datetime.to_string( + datetime.utcfromtimestamp(rate["resources"]["core"]["reset"]) + ) + raise ValidationError(self.env._(f"Reset on {reset}")) from e diff --git a/vcp_github/models/vcp_user.py b/vcp_github/models/vcp_user.py new file mode 100644 index 0000000..7b85782 --- /dev/null +++ b/vcp_github/models/vcp_user.py @@ -0,0 +1,15 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + + +from odoo import models + + +class VcpUser(models.Model): + _inherit = "vcp.user" + + def _get_contributor_url(self): + result = super()._get_contributor_url() + if not result and self.host_id.type_id.code == "github": + return f"https://github.com/{self.external_id}" + return result diff --git a/vcp_github/pyproject.toml b/vcp_github/pyproject.toml new file mode 100644 index 0000000..4231d0c --- /dev/null +++ b/vcp_github/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/vcp_github/readme/CONFIGURE.md b/vcp_github/readme/CONFIGURE.md new file mode 100644 index 0000000..2fdb0e6 --- /dev/null +++ b/vcp_github/readme/CONFIGURE.md @@ -0,0 +1,10 @@ +[ This file is not always required; it should explain **how to configure the module before using it**; it is aimed at users with administration privileges. + +Please be detailed on the path to configuration (eg: do you need to activate developer mode?), describe step by step configurations and the use of screenshots is strongly recommended.] + + +To configure this module, you need to: + +- Go to *App* > Menu > Menu item +- Activate boolean… > save +- … diff --git a/vcp_github/readme/CONTEXT.md b/vcp_github/readme/CONTEXT.md new file mode 100644 index 0000000..096235a --- /dev/null +++ b/vcp_github/readme/CONTEXT.md @@ -0,0 +1,16 @@ +[ This file is optional but strongly suggested to allow end-users to evaluate the +module's usefulness in their context. ] + +BUSINESS NEED: +It should explain the “why” of the module: +- what is the business requirement that generated the need to develop this module +- in which context or use cases this module can be useful (practical examples are welcome!). + +APPROACH: +It could also explain the approach to address the mentioned need. + +USEFUL INFORMATION: +It can also inform on related modules: +- modules it depends on and their features +- other modules that can work well together with this one +- suggested setups where the module is useful (eg: multicompany, multi-website) diff --git a/vcp_github/readme/CONTRIBUTORS.md b/vcp_github/readme/CONTRIBUTORS.md new file mode 100644 index 0000000..7be72fb --- /dev/null +++ b/vcp_github/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- Firstname Lastname (optional company website url) +- Second Person (optional company website url) diff --git a/vcp_github/readme/CREDITS.md b/vcp_github/readme/CREDITS.md new file mode 100644 index 0000000..9c2b025 --- /dev/null +++ b/vcp_github/readme/CREDITS.md @@ -0,0 +1,7 @@ +[ This file is optional and contains additional credits, other than + authors, contributors, and maintainers. ] + +The development of this module has been financially supported by: + +- Company 1 name +- Company 2 name diff --git a/vcp_github/readme/DESCRIPTION.md b/vcp_github/readme/DESCRIPTION.md new file mode 100644 index 0000000..2371a14 --- /dev/null +++ b/vcp_github/readme/DESCRIPTION.md @@ -0,0 +1,7 @@ +[ This file must be max 2-3 paragraphs, and is required. + +The goal of this document is to explain quickly the features of this module: “what” this module does and “what” it is for. ] + +Example: + +This module extends the functionality of ... to support ... and to allow users to ... diff --git a/vcp_github/readme/HISTORY.md b/vcp_github/readme/HISTORY.md new file mode 100644 index 0000000..a6daf58 --- /dev/null +++ b/vcp_github/readme/HISTORY.md @@ -0,0 +1,22 @@ +[ The change log. The goal of this file is to help readers + understand changes between version. The primary audience is + end users and integrators. Purely technical changes such as + code refactoring must not be mentioned here. + + This file may contain ONE level of section titles, underlined + with the ~ (tilde) character. Other section markers are + forbidden and will likely break the structure of the README.rst + or other documents where this fragment is included. ] + +## 11.0.x.y.z (YYYY-MM-DD) + +- [BREAKING] Breaking changes come first. + ([#70](https://github.com/OCA/repo/issues/70)) +- [ADD] New feature. + ([#74](https://github.com/OCA/repo/issues/74)) +- [FIX] Correct this. + ([#71](https://github.com/OCA/repo/issues/71)) + +## 11.0.x.y.z (YYYY-MM-DD) + +- ... diff --git a/vcp_github/readme/INSTALL.md b/vcp_github/readme/INSTALL.md new file mode 100644 index 0000000..77b98e7 --- /dev/null +++ b/vcp_github/readme/INSTALL.md @@ -0,0 +1,7 @@ +[ This file must only be present if there are very specific + installation instructions, such as installing non-python + dependencies. The audience is systems administrators. ] + +To install this module, you need to: + +1. Do this ... diff --git a/vcp_github/readme/ROADMAP.md b/vcp_github/readme/ROADMAP.md new file mode 100644 index 0000000..446840c --- /dev/null +++ b/vcp_github/readme/ROADMAP.md @@ -0,0 +1,5 @@ +[ Enumerate known caveats and future potential improvements. + It is mostly intended for end-users, and can also help + potential new contributors discovering new features to implement. ] + +- ... diff --git a/vcp_github/readme/USAGE.md b/vcp_github/readme/USAGE.md new file mode 100644 index 0000000..2cf1275 --- /dev/null +++ b/vcp_github/readme/USAGE.md @@ -0,0 +1,21 @@ +[ This file is required and contains the instructions on **“how”** to use the module for end-users. + +If the module does not have a visible impact on the user interface, just add the following sentence: + +> This module does not impact the user interface. + +If that’s not the case, please make sure that every usage step is covered and remember that images speak more than words!] + +To use this module, you need to: + +- Go to *App* > Menu > Menu item + + *insert screenshot!* + +- In “Contact” form, add a value to field *xyz* > save + + *insert screenshot!* + +- The value of *xyz* is now displayed in the list view. + + *insert screenshot!* diff --git a/vcp_github/static/description/icon.png b/vcp_github/static/description/icon.png new file mode 100644 index 0000000..3a0328b Binary files /dev/null and b/vcp_github/static/description/icon.png differ diff --git a/vcp_github/static/description/index.html b/vcp_github/static/description/index.html new file mode 100644 index 0000000..63aa4a5 --- /dev/null +++ b/vcp_github/static/description/index.html @@ -0,0 +1,555 @@ + + + + + +Vcp Github + + + +
+

Vcp Github

+ + +

Beta License: AGPL-3 OCA/version-control-platform Translate me on Weblate Try me on Runboat

+

[ This file must be max 2-3 paragraphs, and is required.

+

The goal of this document is to explain quickly the features of this +module: “what” this module does and “what” it is for. ]

+

Example:

+

This module extends the functionality of … to support … and to allow +users to …

+

Table of contents

+ +
+

Use Cases / Context

+

[ This file is optional but strongly suggested to allow end-users to +evaluate the module’s usefulness in their context. ]

+

BUSINESS NEED: It should explain the “why” of the module:

+
    +
  • what is the business requirement that generated the need to develop +this module
  • +
  • in which context or use cases this module can be useful (practical +examples are welcome!).
  • +
+

APPROACH: It could also explain the approach to address the mentioned +need.

+

USEFUL INFORMATION: It can also inform on related modules:

+
    +
  • modules it depends on and their features
  • +
  • other modules that can work well together with this one
  • +
  • suggested setups where the module is useful (eg: multicompany, +multi-website)
  • +
+
+
+

Installation

+

[ This file must only be present if there are very specific installation +instructions, such as installing non-python dependencies. The audience +is systems administrators. ]

+

To install this module, you need to:

+
    +
  1. Do this …
  2. +
+
+
+

Configuration

+

[ This file is not always required; it should explain how to configure +the module before using it; it is aimed at users with administration +privileges.

+

Please be detailed on the path to configuration (eg: do you need to +activate developer mode?), describe step by step configurations and the +use of screenshots is strongly recommended.]

+

To configure this module, you need to:

+
    +
  • Go to App > Menu > Menu item
  • +
  • Activate boolean… > save
  • +
  • +
+
+
+

Usage

+

[ This file is required and contains the instructions on “how” to +use the module for end-users.

+

If the module does not have a visible impact on the user interface, just +add the following sentence:

+
+This module does not impact the user interface.
+

If that’s not the case, please make sure that every usage step is +covered and remember that images speak more than words!]

+

To use this module, you need to:

+
    +
  • Go to App > Menu > Menu item

    +

    insert screenshot!

    +
  • +
  • In “Contact” form, add a value to field xyz > save

    +

    insert screenshot!

    +
  • +
  • The value of xyz is now displayed in the list view.

    +

    insert screenshot!

    +
  • +
+
+
+

Known issues / Roadmap

+

[ Enumerate known caveats and future potential improvements. It is +mostly intended for end-users, and can also help potential new +contributors discovering new features to implement. ]

+
    +
  • +
+
+
+

Changelog

+

[ The change log. The goal of this file is to help readers understand +changes between version. The primary audience is end users and +integrators. Purely technical changes such as code refactoring must not +be mentioned here.

+

This file may contain ONE level of section titles, underlined with the ~ +(tilde) character. Other section markers are forbidden and will likely +break the structure of the README.rst or other documents where this +fragment is included. ]

+
+

11.0.x.y.z (YYYY-MM-DD)

+
    +
  • [BREAKING] Breaking changes come first. +(#70)
  • +
  • [ADD] New feature. (#74)
  • +
  • [FIX] Correct this. (#71)
  • +
+
+ +
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Dixmit
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+

[ This file is optional and contains additional credits, other than +authors, contributors, and maintainers. ]

+

The development of this module has been financially supported by:

+
    +
  • Company 1 name
  • +
  • Company 2 name
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/version-control-platform project on GitHub.

+

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

+
+
+
+ + diff --git a/vcp_github/tests/__init__.py b/vcp_github/tests/__init__.py new file mode 100644 index 0000000..c63e32e --- /dev/null +++ b/vcp_github/tests/__init__.py @@ -0,0 +1 @@ +from . import test_github diff --git a/vcp_github/tests/test_github.py b/vcp_github/tests/test_github.py new file mode 100644 index 0000000..dd00238 --- /dev/null +++ b/vcp_github/tests/test_github.py @@ -0,0 +1,116 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import base64 +from unittest.mock import MagicMock, patch + +from odoo.fields import Command +from odoo.tests.common import TransactionCase + + +class TestGithub(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.platform = cls.env["vcp.platform"].create( + { + "name": "oca", + "host_id": cls.env.ref("vcp_github.vcp_github_host").id, + "key_ids": [ + Command.create({"name": "ghp_exampletoken1234567890abcdef"}) + ], + "default_update_repository_information": True, + "information_update": True, + } + ) + + def test_update_organization_and_logo(self): + base_url = self.env["ir.config_parameter"].sudo().get_param("web.base.url") + with ( + patch("odoo.addons.vcp_github.models.vcp_platform.github3") as mock_github3, + patch( + "odoo.addons.vcp_github.models.vcp_platform.requests.get" + ) as mock_requests_get, + ): + mock_client = MagicMock() + mock_org = MagicMock() + mock_org.name = "Odoo Community Association" + mock_org.avatar_url = f"{base_url}/logo.png" + mock_requests_get.return_value.content = base64.b64decode( + self.env.company.logo + ) + mock_client.organization.return_value = mock_org + mock_github3.login.return_value = mock_client + self.platform.update_information() + self.assertEqual( + self.platform.short_description, "Odoo Community Association" + ) + mock_github3.login.assert_called_once_with( + token="ghp_exampletoken1234567890abcdef" + ) + mock_client.organization.assert_called_once_with("oca") + + def test_update_organization_with_repository(self): + with patch( + "odoo.addons.vcp_github.models.vcp_platform.github3" + ) as mock_github3: + mock_client = MagicMock() + mock_org = MagicMock() + mock_org.name = "Odoo Community Association" + mock_org.avatar_url = False + mock_repo1 = MagicMock() + mock_repo1.name = "server-tools" + mock_repo1.created_at = "2020-01-01T00:00:00Z" + mock_repo2 = MagicMock() + mock_repo2.name = "server-brand" + mock_repo2.created_at = "2021-01-01T10:00:00Z" + mock_org.repositories.return_value = [mock_repo1, mock_repo2] + mock_client.organization.return_value = mock_org + mock_github3.login.return_value = mock_client + self.platform.update_information() + self.assertEqual(len(self.platform.repository_ids), 2) + repo_names = {repo.name for repo in self.platform.repository_ids} + self.assertSetEqual(repo_names, {"server-tools", "server-brand"}) + mock_github3.login.assert_called_once_with( + token="ghp_exampletoken1234567890abcdef" + ) + mock_client.organization.assert_called_once_with("oca") + return self.platform.repository_ids.filtered(lambda r: r.name == "server-tools") + + def test_update_repository(self): + repository = self.test_update_organization_with_repository() + self.assertFalse(repository.request_ids) + with patch( + "odoo.addons.vcp_github.models.vcp_platform.github3.login" + ) as mock_client: + mock_login = MagicMock() + mock_client.return_value = mock_login + mock_login.session.get.return_value = MagicMock( + links={}, + json=lambda: [], + ) + mock_issue_request = MagicMock( + as_dict=lambda: { + "id": 1, + "user": {"login": "contributor1"}, + "base": {"ref": "main"}, + "head": {"repo": [MagicMock()]}, + "html_url": "https://github.com/oca/server-tools/pull/1", + "state": "closed", + "title": "Fix issue", + "labels": [{"name": "merged 🎉"}], + "created_at": "2023-01-01T00:00:00Z", + "updated_at": "2023-01-03T00:00:00Z", + "closed_at": "2023-01-02T00:00:00Z", + "commits": 3, + "comments": 2, + "review_comments": 1, + "additions": 150, + "deletions": 50, + "number": 1, + } + ) + mock_login._instance_or_null.return_value = mock_issue_request + mock_login.search_issues.return_value = [mock_issue_request] + repository.update_information() + self.assertTrue(repository.request_ids) diff --git a/vcp_management/README.rst b/vcp_management/README.rst new file mode 100644 index 0000000..6a91983 --- /dev/null +++ b/vcp_management/README.rst @@ -0,0 +1,91 @@ +============== +VCP Management +============== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:e5814614bba4bc7f628d116d3529a253bb2ae9bff8e8a16c3cfc7eefa5def3cf + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fversion--control--platform-lightgray.png?logo=github + :target: https://github.com/OCA/version-control-platform/tree/18.0/vcp_management + :alt: OCA/version-control-platform +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/version-control-platform-18-0/version-control-platform-18-0-vcp_management + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/version-control-platform&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Creates a set of modules used for handling a version control patform. + +**Table of contents** + +.. contents:: + :local: + +Use Cases / Context +=================== + +The aim of this module is to allow any community to import data from a +version control system. + +The system should be done in a way that is agnostic to the system and +the connections are handled directly by specific modules. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Dixmit + +Contributors +------------ + +- `Dixmit `__ + + - Enric Tobella + +- `Akretion `__ + + - Sebastien Beau + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/version-control-platform `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/vcp_management/__init__.py b/vcp_management/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/vcp_management/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/vcp_management/__manifest__.py b/vcp_management/__manifest__.py new file mode 100644 index 0000000..24fe0d4 --- /dev/null +++ b/vcp_management/__manifest__.py @@ -0,0 +1,37 @@ +# Copyright 2025 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "VCP Management", + "summary": """Management for your Virtual Control Platforms""", + "version": "18.0.1.0.0", + "license": "AGPL-3", + "author": "Dixmit,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/version-control-platform", + "depends": ["base"], + "data": [ + "security/security.xml", + "security/ir.model.access.csv", + "data/ir_cron.xml", + "templates/templates.xml", + "views/menu.xml", + "views/vcp_comment.xml", + "views/vcp_review.xml", + "views/vcp_request.xml", + "views/vcp_repository.xml", + "views/vcp_branch.xml", + "views/vcp_platform.xml", + "views/vcp_organization.xml", + "views/vcp_user.xml", + "views/vcp_host.xml", + "views/vcp_rule.xml", + "views/vcp_rule_information.xml", + ], + "demo": [], + "external_dependencies": { + "python": ["GitPython", "pathspec"], + "bin": ["cloc"], + # special definition used by OCA to install packages + "deb": ["cloc"], + }, +} diff --git a/vcp_management/data/ir_cron.xml b/vcp_management/data/ir_cron.xml new file mode 100644 index 0000000..bb3ba1c --- /dev/null +++ b/vcp_management/data/ir_cron.xml @@ -0,0 +1,41 @@ + + + + + VCP: Repository Update + + code + model._cron_update_repositories() + 1 + minutes + False + + + VCP: Platform Update + + code + model._cron_update_platforms() + 1 + days + False + + + VCP: Branch Update + + code + model._cron_update_branches() + 1 + days + False + + + VCP: Branch Rule Process + + code + model._cron_process_branch_rules() + 1 + days + False + + diff --git a/vcp_management/models/__init__.py b/vcp_management/models/__init__.py new file mode 100644 index 0000000..aa400f5 --- /dev/null +++ b/vcp_management/models/__init__.py @@ -0,0 +1,15 @@ +from . import vcp_platform +from . import vcp_branch +from . import vcp_rule +from . import vcp_rule_information +from . import vcp_rule_information_mixin +from . import vcp_repository +from . import vcp_repository_branch +from . import vcp_request +from . import vcp_review +from . import vcp_comment +from . import res_partner +from . import vcp_host +from . import vcp_host_type +from . import vcp_user +from . import vcp_organization diff --git a/vcp_management/models/res_partner.py b/vcp_management/models/res_partner.py new file mode 100644 index 0000000..902e67b --- /dev/null +++ b/vcp_management/models/res_partner.py @@ -0,0 +1,72 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + + +from odoo import api, fields, models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + vcp_merged_requests = fields.Integer( + compute="_compute_vcp_contributions", + string="Merged Requests", + prefetch=False, + ) + vcp_created_requests = fields.Integer( + compute="_compute_vcp_contributions", + string="Created Requests", + prefetch=False, + ) + vcp_comments = fields.Integer( + compute="_compute_vcp_contributions", string="Comments", prefetch=False + ) + vcp_reviews = fields.Integer( + compute="_compute_vcp_contributions", string="Reviews", prefetch=False + ) + vcp_user_ids = fields.One2many( + "vcp.user", + inverse_name="partner_id", + ) + vcp_organization_ids = fields.One2many( + "vcp.organization", + inverse_name="partner_id", + ) + + @api.depends() + def _compute_vcp_contributions(self): + self.filtered(lambda p: p.vcp_user_ids)._compute_vcp_contributions_field( + "partner_id" + ) + self.filtered(lambda p: not p.vcp_user_ids)._compute_vcp_contributions_field( + "partner_organization_id" + ) + + @api.model + def _get_contributors_field_map(self): + return { + "vcp_merged_requests": "merged_requests", + "vcp_created_requests": "created_requests", + "vcp_comments": "comments", + "vcp_reviews": "reviews", + } + + def _compute_vcp_contributions_field(self, field): + today = fields.Date.today() + start, end = self.env["vcp.platform"]._get_dates(today.year, today.month, "MAT") + data = ( + self.env["vcp.platform"] + .search([]) + ._generate_data( + start=start, + end=end, + field=field, + kind="user", + extra_domain=[(field, "in", self.ids)], + ) + ) + field_map = self._get_contributors_field_map() + for partner in self: + partner.update( + {key: data[partner.id].get(field_map[key], 0) for key in field_map} + ) diff --git a/vcp_management/models/vcp_branch.py b/vcp_management/models/vcp_branch.py new file mode 100644 index 0000000..1ac5390 --- /dev/null +++ b/vcp_management/models/vcp_branch.py @@ -0,0 +1,23 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class VcpBranch(models.Model): + """ + Branches of code on our repository + """ + + _name = "vcp.branch" + _description = "Branch" + + name = fields.Char(required=True) + platform_id = fields.Many2one( + comodel_name="vcp.platform", + string="Platform", + required=True, + ) + _sql_constraints = [ + ("name_uniq", "unique(name, platform_id)", "Branch name must be unique.") + ] diff --git a/vcp_management/models/vcp_comment.py b/vcp_management/models/vcp_comment.py new file mode 100644 index 0000000..02970b8 --- /dev/null +++ b/vcp_management/models/vcp_comment.py @@ -0,0 +1,44 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class VcpComment(models.Model): + _name = "vcp.comment" + _description = "Comment" + + external_id = fields.Char(readonly=True, required=True, index=True) + body = fields.Html(readonly=True) + user_id = fields.Many2one( + comodel_name="vcp.user", + readonly=True, + ) + partner_id = fields.Many2one( + related="user_id.partner_id", + readonly=True, + ) + organization_id = fields.Many2one( + related="request_id.organization_id", + readonly=True, + store=True, + ) + partner_organization_id = fields.Many2one( + related="request_id.organization_id.partner_id", + string="Organization Partner", + ) + repository_id = fields.Many2one( + related="request_id.repository_id", + readonly=True, + store=True, + ) + created_at = fields.Datetime(readonly=True) + updated_at = fields.Datetime(readonly=True) + request_id = fields.Many2one( + comodel_name="vcp.request", + string="Request", + readonly=True, + ) + _sql_constraints = [ + ("external_id_uniq", "unique(external_id)", "External ID must be unique.") + ] diff --git a/vcp_management/models/vcp_host.py b/vcp_management/models/vcp_host.py new file mode 100644 index 0000000..96955c7 --- /dev/null +++ b/vcp_management/models/vcp_host.py @@ -0,0 +1,54 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models, tools + + +class VcpHost(models.Model): + """ + Source of origin of our platform, + e.g. GitHub, GitLab, My Own Gitlab instance, etc. + """ + + _name = "vcp.host" + _description = "VCP Host" + + name = fields.Char(required=True) + type_id = fields.Many2one( + "vcp.host.type", + ) + active = fields.Boolean(default=True) + + @tools.ormcache("self.id", "username") + def _get_user(self, username): + user = ( + self.env["vcp.user"] + .with_context(active_test=False) + .search([("external_id", "=ilike", username)], limit=1) + ) + if not user: + user = self.env["vcp.user"].create( + { + "name": username, + "external_id": username, + "host_id": self.id, + } + ) + return user.id + + @tools.ormcache("self.id", "organization") + def _get_organization(self, organization): + org = ( + self.env["vcp.organization"] + .with_context(active_test=False) + .search([("external_id", "=ilike", organization)], limit=1) + ) + if not org: + org = self.env["vcp.organization"].create( + { + "name": organization, + "external_id": organization, + "host_id": self.id, + } + ) + return org.id diff --git a/vcp_management/models/vcp_host_type.py b/vcp_management/models/vcp_host_type.py new file mode 100644 index 0000000..7b711ef --- /dev/null +++ b/vcp_management/models/vcp_host_type.py @@ -0,0 +1,13 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class VcpHostType(models.Model): + _name = "vcp.host.type" + _description = "Vcp Host Type" + + name = fields.Char(required=True) + code = fields.Char(required=True) + active = fields.Boolean(default=True) diff --git a/vcp_management/models/vcp_organization.py b/vcp_management/models/vcp_organization.py new file mode 100644 index 0000000..f5aeeea --- /dev/null +++ b/vcp_management/models/vcp_organization.py @@ -0,0 +1,44 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class VcpOrganization(models.Model): + """ + An organization on a platform, e.g. a GitHub organization or GitLab group. + It is not the organization that we manage, it represents organization that relates + somehow with our platform. + For example, if we manage GitHub repositories, these are GitHub organizations. + In GitLab, these are GitLab groups. + + They can be related to partners. + """ + + _name = "vcp.organization" + _description = "Organization" + + name = fields.Char(required=True, readonly=True) + external_id = fields.Char(required=True, readonly=True, index=True) + host_id = fields.Many2one( + comodel_name="vcp.host", + required=True, + readonly=True, + ) + partner_id = fields.Many2one( + "res.partner", + ) + + _sql_constraints = [ + ( + "external_id_uniq", + "unique(external_id, host_id)", + "External ID must be unique.", + ) + ] + + def _get_contributor_url(self): + return False + + def _get_contributors_name(self, kind, **kwargs): + return self.partner_id.name or self.name diff --git a/vcp_management/models/vcp_platform.py b/vcp_management/models/vcp_platform.py new file mode 100644 index 0000000..fe58e55 --- /dev/null +++ b/vcp_management/models/vcp_platform.py @@ -0,0 +1,371 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import logging +import os +from collections import defaultdict +from datetime import datetime + +from dateutil.relativedelta import relativedelta + +from odoo import _, api, fields, models, tools + +_logger = logging.getLogger(__name__) + + +class VcpPlatform(models.Model): + """ + This model should define how to interact with a Version Control Platform + (VCP) such as GitHub, GitLab, etc._get_git_url + 1 platform should correspond to 1 organization/account on the VCP. + """ + + _name = "vcp.platform" + _description = "VCP Platform" + + name = fields.Char(required=True) + description = fields.Char(readonly=True) + short_description = fields.Char(readonly=True) + last_update = fields.Datetime(readonly=True) + active = fields.Boolean(default=True) + update_interval_days = fields.Integer(default=3) + image_1920 = fields.Image() + branch_ids = fields.One2many( + "vcp.branch", + inverse_name="platform_id", + ) + image_128 = fields.Image( + max_width=128, + max_height=128, + store=True, + related="image_1920", + string="Image 128", + ) + image_64 = fields.Image( + max_width=64, max_height=64, store=True, related="image_1920", string="Image 64" + ) + host_id = fields.Many2one( + "vcp.host", + required=True, + ) + kind = fields.Char(related="host_id.type_id.code") + key_ids = fields.One2many( + comodel_name="vcp.platform.key", + inverse_name="platform_id", + string="API Keys", + ) + repository_ids = fields.One2many( + "vcp.repository", + inverse_name="platform_id", + ) + default_update_repository_information = fields.Boolean() + information_update = fields.Boolean() + local_path = fields.Char(compute="_compute_local_path") + rule_ids = fields.Many2many( + "vcp.rule", + string="Processing Rules", + ) + + def _get_source_path(self): + return ( + self.env["ir.config_parameter"] + .sudo() + .get_param("vcp_management.source_code_local_path", "") + or tools.config.get("source_code_local_path", "") + or os.environ.get("SOURCE_CODE_LOCAL_PATH", "") + ) + + @api.depends() + def _compute_local_path(self): + source_path = self._get_source_path() + for record in self: + record.local_path = f"{source_path}/{record.id}" + + def update_information(self): + self.ensure_one() + getattr(self, f"_update_information_{self.kind}")() + self.last_update = fields.Datetime.now() + + def _get_git_url(self, repository): + return getattr(self, f"_get_git_url_{self.kind}")(repository) + + def _cron_update_platforms(self): + for platform in self.search([("information_update", "=", True)]): + try: + platform.update_information() + except Exception as e: + _logger.error("Error updating platform %s: %s", platform.name, str(e)) + raise e + + @tools.ormcache("self.id", "name") + def _get_branch(self, name): + self.ensure_one() + branch = self.env["vcp.branch"].search( + [("platform_id", "=", self.id), ("name", "=", name)], + limit=1, + ) + if not branch: + branch = ( + self.env["vcp.branch"] + .sudo() + .create( + { + "platform_id": self.id, + "name": name, + } + ) + ) + return branch.id + + def _get_merged_domain(self, start, end, **values): + return [ + ("repository_id.platform_id", "in", self.ids), + ("is_merged", "=", True), + ("closed_at", ">=", start), + ("closed_at", "<", end), + ] + + def _get_created_domain(self, start, end, **values): + return [ + ("repository_id.platform_id", "in", self.ids), + ("created_at", ">=", start), + ("created_at", "<", end), + ] + + def _get_comments_domain(self, start, end, **values): + return [ + ("request_id.repository_id.platform_id", "in", self.ids), + ("created_at", ">=", start), + ("created_at", "<", end), + ] + + def _get_reviews_domain(self, start, end, **values): + return [ + ("request_id.repository_id.platform_id", "in", self.ids), + ("submitted_at", ">=", start), + ("submitted_at", "<", end), + ] + + def _get_default_data(self, start, end, field, kind, **values): + return { + "name": "", + "created_requests": 0, + "merged_requests": 0, + "comments": 0, + "reviews": 0, + "developers": 0, + } + + def _generate_data(self, start, end, field, kind, extra_domain=None, **values): + if extra_domain is None: + extra_domain = [] + default_dict = self._get_default_data(start, end, field, kind, **values) + data = defaultdict(lambda: default_dict.copy()) + if not field: + return data + for merged in ( + self.env["vcp.request"] + .sudo() + .read_group( + self._get_merged_domain(start, end, **values) + + extra_domain + + [(field, "!=", False)], + [field], + [field], + ) + ): + data[merged[field][0]]["merged_requests"] = merged[f"{field}_count"] + for pr in ( + self.env["vcp.request"] + .sudo() + .read_group( + self._get_created_domain(start, end, **values) + + extra_domain + + [(field, "!=", False)], + [field, "user_id:count_distinct"] if field != "user_id" else [field], + [field], + ) + ): + data[pr[field][0]]["created_requests"] = pr[f"{field}_count"] + if field != "user_id": + data[pr[field][0]]["developers"] = pr["user_id"] + for comment in ( + self.env["vcp.comment"] + .sudo() + .read_group( + self._get_comments_domain(start, end, **values) + + extra_domain + + [(field, "!=", False)], + [field], + [field], + ) + ): + data[comment[field][0]]["comments"] = comment[f"{field}_count"] + for review in ( + self.env["vcp.review"] + .sudo() + .read_group( + self._get_reviews_domain(start, end, **values) + + extra_domain + + [(field, "!=", False)], + [field], + [field], + ) + ): + data[review[field][0]]["reviews"] = review[f"{field}_count"] + return data + + def _get_dates(self, year, month, period, **values): + if month == 12: + end = datetime(year + 1, 1, 1, 0, 0, 0) + else: + end = datetime(year, month + 1, 1, 0, 0, 0) + if period == "YTD": + start = datetime(year, 1, 1, 0, 0, 0) + elif period == "MAT": + start = end - relativedelta(years=1) + else: + start = datetime(year, month, 1, 0, 0, 0) + return start, end + + def _get_vcp_columns(self, kind): + """ + Returns the columns to display in the VCP contributors view in Portal + We keep it here to avoid glue modules having to override models just to + add columns. + """ + if kind == "contributors": + return [ + {"field": "name", "title": _("Name"), "kind": "name"}, + { + "field": "created_requests", + "title": _("Created Requests"), + "kind": "float", + "decimals": 0, + }, + { + "field": "merged_requests", + "title": _("Merged Requests"), + "kind": "float", + "decimals": 0, + }, + { + "field": "comments", + "title": _("Comments"), + "kind": "float", + "decimals": 0, + }, + { + "field": "reviews", + "title": _("Reviews"), + "kind": "float", + "decimals": 0, + }, + ] + elif kind == "organizations": + return [ + {"field": "name", "title": _("Organization Name"), "kind": "name"}, + { + "field": "created_requests", + "title": _("Created Requests"), + "kind": "float", + "decimals": 0, + }, + { + "field": "merged_requests", + "title": _("Merged Requests"), + "kind": "float", + "decimals": 0, + }, + { + "field": "comments", + "title": _("Comments"), + "kind": "float", + "decimals": 0, + }, + { + "field": "reviews", + "title": _("Reviews"), + "kind": "float", + "decimals": 0, + }, + { + "field": "developers", + "title": _("Developers"), + "kind": "float", + "decimals": 0, + }, + ] + elif kind == "repositories": + return [ + {"field": "name", "title": _("Repository Name"), "kind": "name"}, + { + "field": "created_requests", + "title": _("Created Requests"), + "kind": "float", + "decimals": 0, + }, + { + "field": "merged_requests", + "title": _("Merged Requests"), + "kind": "float", + "decimals": 0, + }, + { + "field": "comments", + "title": _("Comments"), + "kind": "float", + "decimals": 0, + }, + { + "field": "reviews", + "title": _("Reviews"), + "kind": "float", + "decimals": 0, + }, + { + "field": "developers", + "title": _("Developers"), + "kind": "float", + "decimals": 0, + }, + ] + return [] + + def _improve_vcp_data(self, data, kind, **kwargs): + """ + This method improves the raw data generated by _generate_data by adding + names and URLs for each key (contributor, organization, repository). + It is kept here to avoid glue modules having to override models just to + add extra information + """ + for key, values in data.items(): + if kind == "contributors": + partner = self.env["vcp.user"].browse(key) + values["name"] = partner._get_contributors_name(kind, **kwargs) + values["url"] = partner._get_contributor_url() + elif kind == "organizations": + organization = self.env["vcp.organization"].browse(key) + values["name"] = organization._get_contributors_name(kind, **kwargs) + values["url"] = organization._get_contributor_url() + elif kind == "repositories": + repository = self.env["vcp.repository"].browse(key) + values["name"] = repository.name + values["url"] = repository._get_repository_url() + return data + + +class VcpPlatformKey(models.Model): + _name = "vcp.platform.key" + _description = "VCP Platform API Key" # TODO + + platform_id = fields.Many2one( + comodel_name="vcp.platform", + string="Platform", + required=True, + ondelete="cascade", + ) + name = fields.Char(required=True) + + _sql_constraints = [ + ("name_uniq", "unique(name, platform_id)", "API Key must be unique.") + ] diff --git a/vcp_management/models/vcp_repository.py b/vcp_management/models/vcp_repository.py new file mode 100644 index 0000000..eeb44f3 --- /dev/null +++ b/vcp_management/models/vcp_repository.py @@ -0,0 +1,108 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class VcpRepository(models.Model): + """ + Repository of code + """ + + _name = "vcp.repository" + _description = "Repository" + + name = fields.Char(required=True, index=True) + description = fields.Char(readonly=True) + platform_id = fields.Many2one( + comodel_name="vcp.platform", + required=True, + ) + created_at = fields.Datetime(readonly=True) + stargazers_count = fields.Integer(readonly=True) + fork_count = fields.Integer(readonly=True) + watchers_count = fields.Integer(readonly=True) + from_date = fields.Datetime(readonly=True, required=True) + request_ids = fields.One2many("vcp.request", inverse_name="repository_id") + request_count = fields.Integer(compute="_compute_request_count") + test_field = fields.Char() # TODO remove after testing + active = fields.Boolean(default=True) + information_update = fields.Boolean( + compute="_compute_information_update", + store=True, + readonly=False, + ) + branch_update = fields.Boolean(default=False) + branch_update_date = fields.Datetime( + readonly=True, required=True, default=fields.Datetime.now + ) + local_path = fields.Char(compute="_compute_local_path") + rule_ids = fields.Many2many( + "vcp.rule", + string="Processing Rules", + ) + override_parent_rules = fields.Boolean() + branch_ids = fields.One2many( + "vcp.repository.branch", + inverse_name="repository_id", + ) + + def _get_rules(self): + rules = self.rule_ids + if not self.override_parent_rules: + rules |= self.platform_id.rule_ids + return rules + + @api.depends("platform_id.local_path", "name") + def _compute_local_path(self): + for record in self: + record.local_path = f"{record.platform_id.local_path}/{record.name}" + + def _get_git_url(self): + self.ensure_one() + return self.platform_id._get_git_url(self) + + @api.depends("platform_id") + def _compute_information_update(self): + for record in self: + record.information_update = ( + record.platform_id.default_update_repository_information + ) + + @api.depends("request_ids") + def _compute_request_count(self): + for record in self: + record.request_count = len(record.request_ids) + + def update_branches(self): + self.ensure_one() + now = fields.Datetime.now() + getattr(self, f"_update_branches_{self.platform_id.kind}")() + self.branch_update_date = now + + def force_update_information(self): + self.update_information(update_interval_days=365) + + def update_information(self, update_interval_days=None): + self.ensure_one() + getattr(self, f"_update_information_{self.platform_id.kind}")( + update_interval_days=update_interval_days + ) + + def _cron_update_repositories(self, limit=1): + repositories = self.search( + [("information_update", "=", True)], limit=limit, order="from_date ASC" + ) + for repository in repositories: + repository.update_information() + + def _cron_update_branches(self, limit=1): + repositories = self.search( + [("branch_update", "=", True)], limit=limit, order="branch_update_date ASC" + ) + for repository in repositories: + repository.update_branches() + + def _get_repository_url(self): + self.ensure_one() + return False diff --git a/vcp_management/models/vcp_repository_branch.py b/vcp_management/models/vcp_repository_branch.py new file mode 100644 index 0000000..0305e8e --- /dev/null +++ b/vcp_management/models/vcp_repository_branch.py @@ -0,0 +1,98 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import os +import re + +import git + +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError + + +class VcpRepositoryBranch(models.Model): + _name = "vcp.repository.branch" + _inherit = ["vcp.rule.information.mixin"] + _description = "Links Branches with Repositories" + + branch_id = fields.Many2one( + "vcp.branch", + string="Branch", + required=True, + ) + repository_id = fields.Many2one( + "vcp.repository", + required=True, + ) + platform_id = fields.Many2one( + related="repository_id.platform_id", + readonly=True, + ) + last_commit = fields.Char(readonly=True) + rule_ids = fields.Many2many( + "vcp.rule", + string="Processing Rules", + ) + override_parent_rules = fields.Boolean() + update_rule_processing_date = fields.Datetime( + default=fields.Datetime.now, + required=True, + ) + + def _cron_process_branch_rules(self, limit=10): + branches = self.search([], limit=limit, order="update_rule_processing_date asc") + for branch in branches: + branch.process_rules() + + @api.constrains("branch_id", "repository_id") + def _check_branch_repository(self): + for record in self: + if record.branch_id.platform_id != record.repository_id.platform_id: + raise ValidationError( + _("The branch and the repository must belong to the same platform.") + ) + + def _get_rules(self): + rules = self.rule_ids + if not self.override_parent_rules: + rules |= self.repository_id._get_rules() + return rules + + def _get_local_path(self): + return f"{self.repository_id.local_path}/{self.branch_id.name}" + + def process_rules(self): + for record in self: + rules = record._get_rules() + for rule in rules: + if re.match(rule.branch_pattern, record.branch_id.name): + rule._process_rule(record) + + def _download_code(self): + result = super()._download_code() + local_path = self.local_path + try: + os.makedirs(local_path, exist_ok=True) + except PermissionError as err: + raise ValidationError( + _( + "Unable to create a folder in '%(local_path)s'.", + local_path=local_path, + ) + ) from err + + try: + repo = git.Repo(local_path) + for remote in repo.remotes: + if remote.url == self.repository_id._get_git_url(): + remote.fetch(self.branch_id.name) + repo.git.reset("--hard", f"{remote.name}/{self.branch_id.name}") + break + except git.exc.InvalidGitRepositoryError: + # Not cloned yet + repo = git.Repo.clone_from( + self.repository_id._get_git_url(), + local_path, + branch=self.branch_id.name, + depth=1, + ) + return result diff --git a/vcp_management/models/vcp_request.py b/vcp_management/models/vcp_request.py new file mode 100644 index 0000000..6f52b75 --- /dev/null +++ b/vcp_management/models/vcp_request.py @@ -0,0 +1,80 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models, tools + + +class VcpRequest(models.Model): + """ + Request of changes on a repository, e.g. pull request on GitHub + or merge request on GitLab. + """ + + _name = "vcp.request" + _description = "Code Request" + + external_id = fields.Char(string="Externa ID", readonly=True, index=True) + name = fields.Char(readonly=True) + user_id = fields.Many2one( + comodel_name="vcp.user", + string="Contributor", + readonly=True, + ) + partner_id = fields.Many2one( + related="user_id.partner_id", + ) + repository_id = fields.Many2one( + comodel_name="vcp.repository", + readonly=True, + ondelete="cascade", + ) + branch_id = fields.Many2one( + comodel_name="vcp.branch", + readonly=True, + ondelete="restrict", + ) + organization_id = fields.Many2one( + comodel_name="vcp.organization", + readonly=True, + ) + partner_organization_id = fields.Many2one( + related="organization_id.partner_id", + string="Organization Partner", + ) + url = fields.Char(readonly=True) + state = fields.Char(readonly=True) + is_merged = fields.Boolean(readonly=True) + created_at = fields.Datetime(readonly=True) + updated_at = fields.Datetime(readonly=True) + closed_at = fields.Datetime(readonly=True) + number = fields.Integer(readonly=True) + label_ids = fields.Many2many( + comodel_name="vcp.request.label", + string="Labels", + readonly=True, + ) + commits = fields.Integer(readonly=True) + additions = fields.Integer(readonly=True) + deletions = fields.Integer(readonly=True) + total_comments = fields.Integer(readonly=True) + review_comments = fields.Integer(readonly=True) + + _sql_constraints = [ + ("external_id_uniq", "unique(external_id)", "External ID must be unique.") + ] + + +class VcpRequestLabel(models.Model): + _name = "vcp.request.label" + _description = "Vcp Request Label" + + name = fields.Char(required=True) + + _sql_constraints = [("name_uniq", "unique(name)", "Label name must be unique.")] + + @tools.ormcache("name") + def _get_label(self, name): + label = self.search([("name", "=", name)], limit=1) + if not label: + label = self.sudo().create({"name": name}) + return label.id diff --git a/vcp_management/models/vcp_review.py b/vcp_management/models/vcp_review.py new file mode 100644 index 0000000..4e3f6db --- /dev/null +++ b/vcp_management/models/vcp_review.py @@ -0,0 +1,50 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class VcpReview(models.Model): + """ + Reviews of a request, e.g. pull request review on GitHub or + merge request review on GitLab. + """ + + _name = "vcp.review" + _description = "Review" # TODO + + external_id = fields.Char(readonly=True, required=True, index=True) + body = fields.Html(readonly=True) + state = fields.Char(readonly=True) + user_id = fields.Many2one("vcp.user", readonly=True) + partner_id = fields.Many2one( + related="user_id.partner_id", + ) + submitted_at = fields.Datetime(readonly=True) + repository_id = fields.Many2one( + related="request_id.repository_id", + readonly=True, + store=True, + ) + request_id = fields.Many2one( + "vcp.request", + readonly=True, + ) + organization_id = fields.Many2one( + related="request_id.organization_id", + readonly=True, + store=True, + ) + platform_id = fields.Many2one( + related="request_id.repository_id.platform_id", + readonly=True, + store=True, + ) + partner_organization_id = fields.Many2one( + related="request_id.organization_id.partner_id", + string="Organization Partner", + ) + + _sql_constraints = [ + ("external_id_uniq", "unique(external_id)", "External ID must be unique.") + ] diff --git a/vcp_management/models/vcp_rule.py b/vcp_management/models/vcp_rule.py new file mode 100644 index 0000000..43abaef --- /dev/null +++ b/vcp_management/models/vcp_rule.py @@ -0,0 +1,107 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import json +import logging +from subprocess import check_output + +import pathspec + +from odoo import fields, models +from odoo.fields import Command + +_logger = logging.getLogger(__name__) + + +class VcpRule(models.Model): + _name = "vcp.rule" + _description = "Processing Rule" + + name = fields.Char(required=True) + branch_pattern = fields.Char(default=".*", required=True) + active = fields.Boolean(default=True) + paths = fields.Text( + help="Define with pathspec especification", + default="*", + required=True, + ) + rule_type = fields.Selection( + [ + ("cloc", "Cloc Analysis"), + ], + required=True, + default="cloc", + ) + + def _process_rule(self, record): + """ + Process the rule on the given repository and branch. + It will call the corresponding method based on the rule type. + """ + return getattr(self, f"_process_rule_{self.rule_type}")(record) + + def _process_rule_cloc(self, record): + """ + Process the rule as a cloc analysis. + """ + record._download_code() + cloc_response = self._call_cloc_command(record.local_path) + matches = self._cloc_get_matches(record.local_path) + cloc_data = self._action_analysis_process_cloc( + record.local_path, matches, cloc_response + ) + vals = self._prepare_analysis_rule_info_vals(record, cloc_data) + if vals["scanned_files"] == 0: + return False + analysis_rule_item = record.rule_information_ids.filtered( + lambda x: x.rule_id == self + ) + if analysis_rule_item: + analysis_rule_item.write(vals) + else: + record.rule_information_ids = [Command.create(vals)] + + def _prepare_analysis_rule_info_vals(self, record, cloc_data): + """Prepare analysis information values of a rule.""" + return { + "rule_id": self.id, + "res_id": record.id, + "res_model": record._name, + "code_count": cloc_data["code"], + "documentation_count": cloc_data["documentation"], + "empty_count": cloc_data["empty"], + "scanned_files": len(cloc_data["paths"]), + } + + def _action_analysis_process_cloc(self, path, matchs, cloc_response): + """Abstract method to be used in other modules. Values are returned by + iterating each match if it exists in the (already defined) cloc response.""" + res = { + "paths": [], + "code": 0, + "documentation": 0, + "empty": 0, + } + for match in matchs: + if path: + path_item = path + "/" + match + else: + path_item = match + if path_item in cloc_response: + res_file = cloc_response[path_item] + res["paths"].append(path_item) + res["code"] += res_file["code"] + res["documentation"] += res_file["comment"] + res["empty"] += res_file["blank"] + return res + + def _call_cloc_command(self, local_path): + res = check_output(["cloc", "--by-file", "--json", local_path]) + return json.loads(res) + + def _cloc_get_matches(self, path): + """ + Get all matches from rule paths (multiple per line allow in rule) + in a local path + """ + spec = pathspec.PathSpec.from_lines("gitignore", self.paths.splitlines()) + return list(spec.match_tree_files(path)) diff --git a/vcp_management/models/vcp_rule_information.py b/vcp_management/models/vcp_rule_information.py new file mode 100644 index 0000000..0759aee --- /dev/null +++ b/vcp_management/models/vcp_rule_information.py @@ -0,0 +1,27 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import api, fields, models + + +class VcpRuleInformation(models.Model): + _name = "vcp.rule.information" + _description = "Information about the processing of a rule on a repository branch" + + res_id = fields.Integer(required=True) + res_model = fields.Char(required=True) + rule_id = fields.Many2one( + "vcp.rule", + required=True, + ) + code_count = fields.Integer() + documentation_count = fields.Integer() + empty_count = fields.Integer() + total_count = fields.Integer(store=True, compute="_compute_total_count") + scanned_files = fields.Integer() + + @api.depends("code_count", "documentation_count", "empty_count") + def _compute_total_count(self): + for item in self: + item.total_count = ( + item.code_count + item.documentation_count + item.empty_count + ) diff --git a/vcp_management/models/vcp_rule_information_mixin.py b/vcp_management/models/vcp_rule_information_mixin.py new file mode 100644 index 0000000..255e831 --- /dev/null +++ b/vcp_management/models/vcp_rule_information_mixin.py @@ -0,0 +1,27 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class VcpRuleInformation(models.AbstractModel): + _name = "vcp.rule.information.mixin" + _description = "Mixin to link rule information models" + + rule_information_ids = fields.One2many( + "vcp.rule.information", + inverse_name="res_id", + domain=lambda self: [("res_model", "=", self._name)], + ) + local_path = fields.Char(compute="_compute_local_path") + + def _download_code(self): + """To be implemented on each subclass""" + self.ensure_one() + + def _compute_local_path(self): + for record in self: + record.local_path = record._get_local_path() + + def _get_local_path(self): + """To be implemented on each subclass""" + return False diff --git a/vcp_management/models/vcp_user.py b/vcp_management/models/vcp_user.py new file mode 100644 index 0000000..1230e92 --- /dev/null +++ b/vcp_management/models/vcp_user.py @@ -0,0 +1,42 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class VcpUser(models.Model): + """ + Users from the host that relates to our platform. + For example, if we manage GitHub repositories, these are GitHub users. + In GitLab, these are GitLab users. + + They could be related to partners. + """ + + _name = "vcp.user" + _description = "User" + + name = fields.Char(required=True, readonly=True) + external_id = fields.Char(required=True, readonly=True, index=True) + host_id = fields.Many2one( + comodel_name="vcp.host", + required=True, + readonly=True, + ) + partner_id = fields.Many2one( + "res.partner", + ) + + _sql_constraints = [ + ( + "external_id_uniq", + "unique(external_id, host_id)", + "External ID must be unique.", + ) + ] + + def _get_contributor_url(self): + return False + + def _get_contributors_name(self, kind, **kwargs): + return self.partner_id.name or self.name diff --git a/vcp_management/pyproject.toml b/vcp_management/pyproject.toml new file mode 100644 index 0000000..4231d0c --- /dev/null +++ b/vcp_management/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/vcp_management/readme/CONTEXT.md b/vcp_management/readme/CONTEXT.md new file mode 100644 index 0000000..1c22f75 --- /dev/null +++ b/vcp_management/readme/CONTEXT.md @@ -0,0 +1,3 @@ +The aim of this module is to allow any community to import data from a version control system. + +The system should be done in a way that is agnostic to the system and the connections are handled directly by specific modules. diff --git a/vcp_management/readme/CONTRIBUTORS.md b/vcp_management/readme/CONTRIBUTORS.md new file mode 100644 index 0000000..579d94d --- /dev/null +++ b/vcp_management/readme/CONTRIBUTORS.md @@ -0,0 +1,5 @@ +- [Dixmit](https://dixmit.com) + - Enric Tobella + +- [Akretion](https://akretion.com) + - Sebastien Beau diff --git a/vcp_management/readme/DESCRIPTION.md b/vcp_management/readme/DESCRIPTION.md new file mode 100644 index 0000000..f05f973 --- /dev/null +++ b/vcp_management/readme/DESCRIPTION.md @@ -0,0 +1 @@ +Creates a set of modules used for handling a version control patform. diff --git a/vcp_management/security/ir.model.access.csv b/vcp_management/security/ir.model.access.csv new file mode 100644 index 0000000..b6a5de5 --- /dev/null +++ b/vcp_management/security/ir.model.access.csv @@ -0,0 +1,25 @@ +"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" +access_vcp_platform,Access Platform,model_vcp_platform,group_vcp_user,1,0,0,0 +manage_vcp_platform,Manage Platform,model_vcp_platform,group_vcp_manager,1,1,1,0 +manage_vcp_platform_key,Manage Platform Keys,model_vcp_platform_key,group_vcp_manager,1,1,1,1 +access_branch,Access Branch,model_vcp_branch,group_vcp_user,1,0,0,0 +manage_branch,Access Branch,model_vcp_branch,group_vcp_manager,1,1,1,1 +access_repository,Access Repository,model_vcp_repository,group_vcp_user,1,0,0,0 +manage_repository,Access Repository,model_vcp_repository,group_vcp_manager,1,1,1,1 +access_repository_branch,Access Repository Branch,model_vcp_repository_branch,group_vcp_user,1,0,0,0 +manage_repository_branch,Access Repository Branch,model_vcp_repository_branch,group_vcp_manager,1,1,1,1 +access_rule_information,Access Repository Branch Rule information,model_vcp_rule_information,group_vcp_user,1,0,0,0 +manage_rule_information,Access Repository Branch Rule information,model_vcp_rule_information,group_vcp_manager,1,1,1,1 +access_request,Access Pull Requests,model_vcp_request,group_vcp_user,1,0,0,0 +access_request_label,Access Pull Requests Labels,model_vcp_request_label,group_vcp_user,1,0,0,0 +access_review,Access Reviews,model_vcp_review,group_vcp_user,1,0,0,0 +access_comment,Access Comments,model_vcp_comment,group_vcp_user,1,0,0,0 +access_vcp_host_type,Access Host Type,model_vcp_host_type,group_vcp_user,1,0,0,0 +access_vcp_host,Access Hosts,model_vcp_host,group_vcp_user,1,0,0,0 +manage_vcp_host,Nabage Hosts,model_vcp_host,group_vcp_manager,1,1,1,1 +access_user,Access Users,model_vcp_user,group_vcp_user,1,0,0,0 +manage_user,Manage Users,model_vcp_user,group_vcp_manager,1,1,1,1 +access_organization,Access Organizations,model_vcp_organization,group_vcp_user,1,0,0,0 +manage_organization,Manage Organizations,model_vcp_organization,group_vcp_manager,1,1,1,1 +access_vcp_rule,Access VCP Rules,model_vcp_rule,group_vcp_user,1,0,0,0 +manage_vcp_rule,Manage VCP Rules,model_vcp_rule,group_vcp_manager,1,1,1,1 diff --git a/vcp_management/security/security.xml b/vcp_management/security/security.xml new file mode 100644 index 0000000..cd65450 --- /dev/null +++ b/vcp_management/security/security.xml @@ -0,0 +1,24 @@ + + + + + VCP + 20 + + + VCP User + + + + VCP Manager + + + + + diff --git a/vcp_management/static/description/icon.png b/vcp_management/static/description/icon.png new file mode 100644 index 0000000..1fece97 Binary files /dev/null and b/vcp_management/static/description/icon.png differ diff --git a/vcp_management/static/description/icon.svg b/vcp_management/static/description/icon.svg new file mode 100644 index 0000000..261d62c --- /dev/null +++ b/vcp_management/static/description/icon.svg @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + diff --git a/vcp_management/static/description/index.html b/vcp_management/static/description/index.html new file mode 100644 index 0000000..1dfb980 --- /dev/null +++ b/vcp_management/static/description/index.html @@ -0,0 +1,438 @@ + + + + + +VCP Management + + + +
+

VCP Management

+ + +

Beta License: AGPL-3 OCA/version-control-platform Translate me on Weblate Try me on Runboat

+

Creates a set of modules used for handling a version control patform.

+

Table of contents

+ +
+

Use Cases / Context

+

The aim of this module is to allow any community to import data from a +version control system.

+

The system should be done in a way that is agnostic to the system and +the connections are handled directly by specific modules.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Dixmit
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/version-control-platform project on GitHub.

+

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

+
+
+
+ + diff --git a/vcp_management/templates/templates.xml b/vcp_management/templates/templates.xml new file mode 100644 index 0000000..2e91c9c --- /dev/null +++ b/vcp_management/templates/templates.xml @@ -0,0 +1,24 @@ + + + + + diff --git a/vcp_management/tests/__init__.py b/vcp_management/tests/__init__.py new file mode 100644 index 0000000..fb90f33 --- /dev/null +++ b/vcp_management/tests/__init__.py @@ -0,0 +1,3 @@ +from . import test_vcp_crons +from . import test_vcp_data +from . import test_vcp_rule diff --git a/vcp_management/tests/test_vcp_crons.py b/vcp_management/tests/test_vcp_crons.py new file mode 100644 index 0000000..a1d0583 --- /dev/null +++ b/vcp_management/tests/test_vcp_crons.py @@ -0,0 +1,166 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import tempfile +from unittest.mock import patch + +from odoo.fields import Date +from odoo.tools import mute_logger + +from odoo.addons.base.tests.common import TransactionCase + + +class TestVcpRules(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls._tmp_dir = tempfile.TemporaryDirectory(prefix="vcp-git") + cls.env["ir.config_parameter"].sudo().set_param( + "vcp_management.source_code_local_path", cls._tmp_dir.name + ) + cls.addClassCleanup(cls._tmp_dir.cleanup) + cls.host_type = cls.env["vcp.host.type"].create( + { + "name": "Dummy", + "code": "dummy", + } + ) + cls.host = cls.env["vcp.host"].create( + { + "name": "Dummy Platform", + "type_id": cls.host_type.id, + } + ) + # disable updates to avoid unwanted side effects during tests + cls.env["vcp.platform"].search([]).write({"information_update": False}) + cls.env["vcp.repository"].search([]).write( + {"information_update": False, "branch_update": False} + ) + # be sure some expected values are set otherwise homepage may fail + cls.platform = cls.env["vcp.platform"].create( + { + "name": "oca", + "short_description": "OCA", + "description": "OCA", + "host_id": cls.host.id, + "information_update": True, + } + ) + + def test_repository_update_no_definition(self): + self.env["vcp.repository"].create( + { + "name": "test_repo", + "description": "Test Repository", + "platform_id": self.platform.id, + "information_update": True, + "from_date": Date.today(), + } + ) + with ( + self.assertRaises(AttributeError), + mute_logger("odoo.addons.vcp_management.models.vcp_platform"), + ): + self.env["vcp.repository"]._cron_update_platforms() + + def test_platform_branch_update_no_definition(self): + self.env["vcp.repository"].create( + { + "name": "test_repo", + "description": "Test Repository", + "platform_id": self.platform.id, + "branch_update": True, + "from_date": Date.today(), + } + ) + with ( + self.assertRaises(AttributeError), + mute_logger("odoo.addons.vcp_management.models.vcp_platform"), + ): + self.env["vcp.repository"]._cron_update_branches() + + def test_platform_update_no_definition(self): + with ( + self.assertRaises(AttributeError), + mute_logger("odoo.addons.vcp_management.models.vcp_platform"), + ): + self.env["vcp.platform"]._cron_update_platforms() + + def test_repository_branch_rules_check_definition(self): + def dummy_update_information(oself, *args, **kwargs): + if oself.repository_ids: + return + oself.env["vcp.repository"].create( + { + "name": "test_repo", + "description": "Test Repository", + "platform_id": oself.id, + "information_update": True, + "branch_update": True, + "from_date": Date.today(), + } + ) + + self.assertFalse(self.platform.repository_ids) + with patch( + "odoo.addons.vcp_management.models.vcp_platform.VcpPlatform._update_information_dummy", + dummy_update_information, + create=True, + ): + self.env["vcp.platform"]._cron_update_platforms() + self.assertTrue(self.platform.repository_ids) + + def dummy_repository_update_information(oself, *args, **kwargs): + if oself.request_ids: + return + oself.env["vcp.request"].create( + { + "external_id": 1, + "name": "Test PR", + "repository_id": oself.id, + "user_id": oself.env["vcp.user"] + .create( + { + "name": "Test User", + "external_id": "testuser", + "host_id": oself.platform_id.host_id.id, + } + ) + .id, + "created_at": Date.today(), + } + ) + + repository = self.platform.repository_ids[0] + self.assertTrue(repository) + self.assertFalse(repository.request_ids) + + with patch( + "odoo.addons.vcp_management.models.vcp_repository.VcpRepository._update_information_dummy", + dummy_repository_update_information, + create=True, + ): + self.env["vcp.repository"]._cron_update_repositories() + repository.invalidate_recordset() + self.assertTrue(repository.request_ids) + self.assertFalse(repository.branch_ids) + + def dummy_repository_update_branches(oself, *args, **kwargs): + if oself.branch_ids: + return + oself.env["vcp.repository.branch"].create( + { + "branch_id": oself.platform_id._get_branch("main"), + "repository_id": oself.id, + } + ) + + with patch( + "odoo.addons.vcp_management.models.vcp_repository.VcpRepository._update_branches_dummy", + dummy_repository_update_branches, + create=True, + ): + self.env["vcp.repository"]._cron_update_branches() + + self.assertTrue(repository.branch_ids) + self.assertEqual(repository.branch_ids.branch_id.name, "main") diff --git a/vcp_management/tests/test_vcp_data.py b/vcp_management/tests/test_vcp_data.py new file mode 100644 index 0000000..b7e9575 --- /dev/null +++ b/vcp_management/tests/test_vcp_data.py @@ -0,0 +1,189 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from datetime import timedelta + +from odoo.fields import Date + +from odoo.addons.base.tests.common import TransactionCase + + +class TestVcpPartner(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.host_type = cls.env["vcp.host.type"].create( + { + "name": "Dummy", + "code": "dummy", + } + ) + cls.host = cls.env["vcp.host"].create( + { + "name": "Dummy Platform", + "type_id": cls.host_type.id, + } + ) + # be sure some expected values are set otherwise homepage may fail + date = Date.today() + date = date - timedelta(days=date.day + 1) + platform = cls.env["vcp.platform"].create( + { + "name": "oca", + "short_description": "OCA", + "description": "OCA", + "host_id": cls.host.id, + } + ) + cls.repository = cls.env["vcp.repository"].create( + { + "name": "contributors-module", + "description": "OCA/contributors-module", + "platform_id": platform.id, + "from_date": date, + } + ) + cls.partner_01 = cls.env["res.partner"].create( + { + "name": "Enric Tobella", + } + ) + user_01 = cls.env["vcp.user"].create( + { + "name": "Enric Tobella", + "external_id": "etobella", + "host_id": cls.host.id, + "partner_id": cls.partner_01.id, + } + ) + cls.partner_02 = cls.env["res.partner"].create( + { + "name": "Luis Rodriguez", + } + ) + user_02 = cls.env["vcp.user"].create( + { + "name": "Luis Rodriguez", + "external_id": "lrodriguez", + "host_id": cls.host.id, + "partner_id": cls.partner_02.id, + } + ) + cls.partner_03 = cls.env["res.partner"].create( + { + "name": "Jordi Ballester", + } + ) + user_03 = cls.env["vcp.user"].create( + { + "name": "Jordi Ballester", + "external_id": "jballester", + "host_id": cls.host.id, + "partner_id": cls.partner_03.id, + } + ) + + cls.partner_org_01 = cls.env["res.partner"].create( + { + "name": "Dixmit", + } + ) + org_01 = cls.env["vcp.organization"].create( + { + "name": "Dixmit", + "external_id": "dixmit", + "host_id": cls.host.id, + "partner_id": cls.partner_org_01.id, + } + ) + cls.partner_org_02 = cls.env["res.partner"].create( + { + "name": "ForgeFlow", + } + ) + org_02 = cls.env["vcp.organization"].create( + { + "name": "ForgeFlow", + "external_id": "forgeflow", + "host_id": cls.host.id, + "partner_id": cls.partner_org_02.id, + } + ) + pull_request_01 = cls.env["vcp.request"].create( + { + "external_id": 1, + "name": "Test PR", + "repository_id": cls.repository.id, + "user_id": user_01.id, + "organization_id": org_01.id, + "created_at": date, + "closed_at": date, + "is_merged": True, + } + ) + cls.env["vcp.request"].create( + { + "external_id": 2, + "name": "Test PR", + "repository_id": cls.repository.id, + "user_id": user_02.id, + "organization_id": org_01.id, + "created_at": date, + "is_merged": False, + } + ) + cls.env["vcp.request"].create( + { + "external_id": 3, + "name": "Test PR", + "repository_id": cls.repository.id, + "user_id": user_03.id, + "organization_id": org_02.id, + "created_at": date, + "is_merged": False, + } + ) + cls.env["vcp.review"].create( + { + "external_id": 1, + "body": "Test Review", + "state": "APPROVED", + "request_id": pull_request_01.id, + "user_id": user_01.id, + "submitted_at": date, + } + ) + cls.env["vcp.comment"].create( + { + "external_id": 1, + "body": "Test Comment", + "request_id": pull_request_01.id, + "user_id": user_01.id, + "created_at": date, + } + ) + + def test_partner_request_count(self): + self.assertEqual(self.partner_01.vcp_comments, 1) + self.assertEqual(self.partner_01.vcp_created_requests, 1) + self.assertEqual(self.partner_01.vcp_merged_requests, 1) + self.assertEqual(self.partner_01.vcp_reviews, 1) + self.assertEqual(self.partner_02.vcp_comments, 0) + self.assertEqual(self.partner_02.vcp_created_requests, 1) + self.assertEqual(self.partner_02.vcp_merged_requests, 0) + self.assertEqual(self.partner_02.vcp_reviews, 0) + self.assertEqual(self.partner_03.vcp_comments, 0) + self.assertEqual(self.partner_03.vcp_created_requests, 1) + self.assertEqual(self.partner_03.vcp_merged_requests, 0) + self.assertEqual(self.partner_03.vcp_reviews, 0) + self.assertEqual(self.partner_org_01.vcp_comments, 1) + self.assertEqual(self.partner_org_01.vcp_created_requests, 2) + self.assertEqual(self.partner_org_01.vcp_merged_requests, 1) + self.assertEqual(self.partner_org_01.vcp_reviews, 1) + self.assertEqual(self.partner_org_02.vcp_comments, 0) + self.assertEqual(self.partner_org_02.vcp_created_requests, 1) + self.assertEqual(self.partner_org_02.vcp_merged_requests, 0) + self.assertEqual(self.partner_org_02.vcp_reviews, 0) + + def test_repository_data(self): + self.assertEqual(self.repository.request_count, 3) diff --git a/vcp_management/tests/test_vcp_rule.py b/vcp_management/tests/test_vcp_rule.py new file mode 100644 index 0000000..e4392bf --- /dev/null +++ b/vcp_management/tests/test_vcp_rule.py @@ -0,0 +1,184 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import os +import tempfile +from unittest.mock import MagicMock, patch + +from odoo.exceptions import ValidationError +from odoo.fields import Date + +from odoo.addons.base.tests.common import TransactionCase + + +class TestVcpRules(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.host_type = cls.env["vcp.host.type"].create( + { + "name": "Dummy", + "code": "dummy", + } + ) + cls.host = cls.env["vcp.host"].create( + { + "name": "Dummy Platform", + "type_id": cls.host_type.id, + } + ) + # be sure some expected values are set otherwise homepage may fail + cls.platform = cls.env["vcp.platform"].create( + { + "name": "oca", + "short_description": "OCA", + "description": "OCA", + "host_id": cls.host.id, + } + ) + cls.repository = cls.env["vcp.repository"].create( + { + "name": "contributors-module", + "description": "OCA/contributors-module", + "platform_id": cls.platform.id, + "from_date": Date.today(), + } + ) + cls.branch = cls.env["vcp.branch"].create( + { + "name": "main", + "platform_id": cls.platform.id, + } + ) + cls.repository_branch = cls.env["vcp.repository.branch"].create( + { + "repository_id": cls.repository.id, + "branch_id": cls.branch.id, + } + ) + cls.rule = cls.env["vcp.rule"].create( + { + "name": "Test Rule", + "rule_type": "cloc", + } + ) + + def setUp(self): + super().setUp() + self._tmp_dir = tempfile.TemporaryDirectory(prefix="vcp-git") + self.env["ir.config_parameter"].sudo().set_param( + "vcp_management.source_code_local_path", self._tmp_dir.name + ) + self.addCleanup(self._tmp_dir.cleanup) + + def test_assign_rules(self): + self.platform.rule_ids = self.rule + self.assertIn(self.rule, self.repository_branch._get_rules()) + self.repository.override_parent_rules = True + self.assertNotIn(self.rule, self.repository_branch._get_rules()) + self.repository.rule_ids = self.rule + self.assertIn(self.rule, self.repository_branch._get_rules()) + self.repository_branch.override_parent_rules = True + self.assertNotIn(self.rule, self.repository_branch._get_rules()) + self.repository_branch.rule_ids = self.rule + self.assertIn(self.rule, self.repository_branch._get_rules()) + + def test_branch_constrain(self): + platform = self.env["vcp.platform"].create( + { + "name": "test", + "short_description": "Test", + "description": "Test", + "host_id": self.host.id, + } + ) + repository = self.env["vcp.repository"].create( + { + "name": "test-repo", + "description": "Test/test-repo", + "platform_id": platform.id, + "from_date": Date.today(), + } + ) + with self.assertRaises(ValidationError): + self.env["vcp.repository.branch"].create( + { + "repository_id": repository.id, + "branch_id": self.branch.id, + } + ) + + def test_process_rules(self): + self.platform.rule_ids = self.rule + self.assertFalse(os.path.exists(self.repository_branch.local_path)) + self.assertFalse(self.repository_branch.rule_information_ids) + with ( + patch( + "odoo.addons.vcp_management.models.vcp_platform.VcpPlatform._get_git_url" + ) as mock_git_url, + patch( + "odoo.addons.vcp_management.models.vcp_repository_branch.git.Repo.clone_from" + ) as mock_clone_from, + ): + os.makedirs(self.repository_branch.local_path, exist_ok=True) + with open(f"{self.repository_branch.local_path}/demofile.py", "w") as f: + f.write(""" +print('Hello World') + +# This is a comment + +print('Bye bye world') +""") + self.repository_branch.process_rules() + mock_git_url.assert_called_once() + mock_clone_from.assert_called_once() + self.repository_branch.invalidate_recordset() + self.assertTrue(self.repository_branch.rule_information_ids) + rule_info = self.repository_branch.rule_information_ids.filtered( + lambda x: x.rule_id == self.rule + ) + self.assertEqual(rule_info.scanned_files, 1) + self.assertEqual(rule_info.code_count, 2) + self.assertEqual(rule_info.documentation_count, 1) + self.assertEqual(rule_info.empty_count, 3) + self.assertEqual(rule_info.total_count, 6) + + def test_process_rules_update(self): + self.platform.rule_ids = self.rule + self.assertFalse(os.path.exists(self.repository_branch.local_path)) + self.assertFalse(self.repository_branch.rule_information_ids) + with ( + patch( + "odoo.addons.vcp_management.models.vcp_platform.VcpPlatform._get_git_url" + ) as mock_git_url, + patch( + "odoo.addons.vcp_management.models.vcp_repository_branch.git.Repo" + ) as mock_git_repo, + ): + mock_git_url.return_value = "https://example.com/repo.git" + os.makedirs(self.repository_branch.local_path, exist_ok=True) + with open(f"{self.repository_branch.local_path}/demofile.py", "w") as f: + f.write(""" +print('Hello World') + +# This is a comment + +print('Bye bye world') +""") + + mock_git_repo.return_value.remotes = [ + MagicMock(name="origin", url="https://example.com/repo.git") + ] + self.repository_branch.process_rules() + mock_git_url.assert_called_once() + mock_git_repo.assert_called_once() + self.repository_branch.invalidate_recordset() + self.assertTrue(self.repository_branch.rule_information_ids) + rule_info = self.repository_branch.rule_information_ids.filtered( + lambda x: x.rule_id == self.rule + ) + self.assertEqual(rule_info.scanned_files, 1) + self.assertEqual(rule_info.code_count, 2) + self.assertEqual(rule_info.documentation_count, 1) + self.assertEqual(rule_info.empty_count, 3) + self.assertEqual(rule_info.total_count, 6) diff --git a/vcp_management/views/menu.xml b/vcp_management/views/menu.xml new file mode 100644 index 0000000..1d785b5 --- /dev/null +++ b/vcp_management/views/menu.xml @@ -0,0 +1,17 @@ + + + + + + diff --git a/vcp_management/views/vcp_branch.xml b/vcp_management/views/vcp_branch.xml new file mode 100644 index 0000000..f5b6041 --- /dev/null +++ b/vcp_management/views/vcp_branch.xml @@ -0,0 +1,27 @@ + + + + + vcp.branch + +
+
+ + + + + + + + + + + vcp.branch + + + + + + + diff --git a/vcp_management/views/vcp_comment.xml b/vcp_management/views/vcp_comment.xml new file mode 100644 index 0000000..c43cec9 --- /dev/null +++ b/vcp_management/views/vcp_comment.xml @@ -0,0 +1,26 @@ + + + + + vcp.comment + +
+
+ + + + + + + + + + vcp.comment + + + + + + + diff --git a/vcp_management/views/vcp_host.xml b/vcp_management/views/vcp_host.xml new file mode 100644 index 0000000..d82675e --- /dev/null +++ b/vcp_management/views/vcp_host.xml @@ -0,0 +1,56 @@ + + + + + vcp.host + +
+
+ + + + + + + + + + + + vcp.host + + + + + + + + + vcp.host + + + + + + + + + + Platform Types + vcp.host + list,form + [] + {} + + + + Platform Types + + + + + diff --git a/vcp_management/views/vcp_organization.xml b/vcp_management/views/vcp_organization.xml new file mode 100644 index 0000000..e27b22e --- /dev/null +++ b/vcp_management/views/vcp_organization.xml @@ -0,0 +1,54 @@ + + + + + vcp.organization + +
+
+ + + + + + + + + + + + + + vcp.organization + + + + + + + + + vcp.organization + + + + + + + + + Organizations + vcp.organization + list,form + [] + {} + + + + Organizations + + + + + diff --git a/vcp_management/views/vcp_platform.xml b/vcp_management/views/vcp_platform.xml new file mode 100644 index 0000000..7df0195 --- /dev/null +++ b/vcp_management/views/vcp_platform.xml @@ -0,0 +1,86 @@ + + + + + vcp.platform + +
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + vcp.platform + + + + + + + + + + vcp.platform + + + + + + + + + Platforms + vcp-platforms + vcp.platform + list,form + [] + {} + + + + Platforms + + + + + diff --git a/vcp_management/views/vcp_repository.xml b/vcp_management/views/vcp_repository.xml new file mode 100644 index 0000000..94f82b1 --- /dev/null +++ b/vcp_management/views/vcp_repository.xml @@ -0,0 +1,161 @@ + + + + + vcp.repository + +
+
+
+ +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + MTD + YTD + MAT + + +
+
+ +
+
+ +
+
+ +
+ + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + + + + + + +
+ + + + diff --git a/vcp_portal/static/tests/tours/portal.esm.js b/vcp_portal/static/tests/tours/portal.esm.js new file mode 100644 index 0000000..73e187b --- /dev/null +++ b/vcp_portal/static/tests/tours/portal.esm.js @@ -0,0 +1,112 @@ +import {registry} from "@web/core/registry"; + +console.log("Registering portal_load_vcp tour"); +registry.category("web_tour.tours").add("portal_load_vcp", { + url: "/my", + steps: () => [ + { + content: "Check portal is loaded and Find Contributors menu", + trigger: 'a[href*="/vcp"]:contains("Virtual Control Platforms"):first', + run: "click", + expectUnloadPage: true, + }, + { + content: "Check Contributors Page", + trigger: 'a[href*="/vcp/oca"]:contains("OCA"):first', + run: "click", + expectUnloadPage: true, + }, + { + content: "Check Contributors Page", + trigger: "owl-component", + }, + { + content: "Check Etobella", + trigger: 'span:contains("Enric Tobella"):first', + }, + { + content: "Check LuisDixmit", + trigger: 'span:contains("Luis Rodriguez"):first', + }, + { + content: "Check JordiBForgeFlow", + trigger: 'span:contains("Jordi Ballester"):first', + }, + { + content: "Check Etobella Created Value", + trigger: 'tr:contains("Enric Tobella") td:nth-child(2):contains("1"):first', + }, + { + content: "Check LuisDixmit Created Value", + trigger: + 'tr:contains("Luis Rodriguez") td:nth-child(2):contains("1"):first', + }, + { + content: "Check JordiBForgeFlow Created Value", + trigger: + 'tr:contains("Jordi Ballester") td:nth-child(2):contains("1"):first', + }, + { + content: "Check Etobella Merged Value", + trigger: 'tr:contains("Enric Tobella") td:nth-child(3):contains("1"):first', + }, + { + content: "Check LuisDixmit Merged Value", + trigger: + 'tr:contains("Luis Rodriguez") td:nth-child(3):contains("0"):first', + }, + { + content: "Check JordiBForgeFlow Merged Value", + trigger: + 'tr:contains("Jordi Ballester") td:nth-child(3):contains("0"):first', + }, + { + content: "Change to Repositories", + trigger: ".o_vcp_repositories button", + run: "click", + }, + { + content: "Check Repository", + trigger: 'span:contains("contributors-module"):first', + }, + { + content: "Check Created Requests Value", + trigger: + 'tr:contains("contributors-module") td:nth-child(2):contains("3"):first', + }, + { + content: "Check Merged Requests Value", + trigger: + 'tr:contains("contributors-module") td:nth-child(3):contains("1"):first', + }, + { + content: "Change to Organizations", + trigger: ".o_vcp_organizations button", + run: "click", + }, + { + content: "Check Dixmit", + trigger: 'tr:contains("Dixmit"):first', + }, + { + content: "Check ForgeFlow", + trigger: 'tr:contains("ForgeFlow"):first', + }, + { + content: "Check Dixmit Created Pull Requests Value", + trigger: 'tr:contains("Dixmit") td:nth-child(2):contains("2"):first', + }, + { + content: "Check ForgeFlow Created Pull Requests Value", + trigger: 'tr:contains("ForgeFlow") td:nth-child(2):contains("1"):first', + }, + { + content: "Check Dixmit Merged Pull Requests Value", + trigger: 'tr:contains("Dixmit") td:nth-child(3):contains("1"):first', + }, + { + content: "Check ForgeFlow Merged Pull Requests Value", + trigger: 'tr:contains("ForgeFlow") td:nth-child(3):contains("0"):first', + }, + ], +}); diff --git a/vcp_portal/templates/templates.xml b/vcp_portal/templates/templates.xml new file mode 100644 index 0000000..a77b7d8 --- /dev/null +++ b/vcp_portal/templates/templates.xml @@ -0,0 +1,88 @@ + + + + + + + + + diff --git a/vcp_portal/tests/__init__.py b/vcp_portal/tests/__init__.py new file mode 100644 index 0000000..8307da4 --- /dev/null +++ b/vcp_portal/tests/__init__.py @@ -0,0 +1 @@ +from . import test_portal diff --git a/vcp_portal/tests/test_portal.py b/vcp_portal/tests/test_portal.py new file mode 100644 index 0000000..901fbe2 --- /dev/null +++ b/vcp_portal/tests/test_portal.py @@ -0,0 +1,148 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from datetime import timedelta + +from odoo.fields import Date +from odoo.tests import tagged + +from odoo.addons.base.tests.common import HttpCaseWithUserDemo, HttpCaseWithUserPortal + + +@tagged("post_install", "-at_install") +class TestUi(HttpCaseWithUserDemo, HttpCaseWithUserPortal): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.host_type = cls.env["vcp.host.type"].create( + { + "name": "Dummy", + "code": "dummy", + } + ) + cls.host = cls.env["vcp.host"].create( + { + "name": "Dummy Platform", + "type_id": cls.host_type.id, + } + ) + # be sure some expected values are set otherwise homepage may fail + date = Date.today() + date = date - timedelta(days=date.day + 1) + cls.partner_portal.write( + { + "city": "Bayonne", + "company_name": "YourCompany", + "country_id": cls.env.ref("base.us").id, + "phone": "(683)-556-5104", + "street": "858 Lynn Street", + "zip": "07002", + } + ) + platform = cls.env["vcp.platform"].create( + { + "name": "oca", + "short_description": "OCA", + "description": "OCA", + "host_id": cls.host.id, + } + ) + repository = cls.env["vcp.repository"].create( + { + "name": "contributors-module", + "description": "OCA/contributors-module", + "platform_id": platform.id, + "from_date": date, + } + ) + user_01 = cls.env["vcp.user"].create( + { + "name": "Enric Tobella", + "external_id": "etobella", + "host_id": cls.host.id, + } + ) + user_02 = cls.env["vcp.user"].create( + { + "name": "Luis Rodriguez", + "external_id": "lrodriguez", + "host_id": cls.host.id, + } + ) + user_03 = cls.env["vcp.user"].create( + { + "name": "Jordi Ballester", + "external_id": "jballester", + "host_id": cls.host.id, + } + ) + org_01 = cls.env["vcp.organization"].create( + { + "name": "Dixmit", + "external_id": "dixmit", + "host_id": cls.host.id, + } + ) + org_02 = cls.env["vcp.organization"].create( + { + "name": "ForgeFlow", + "external_id": "forgeflow", + "host_id": cls.host.id, + } + ) + pull_request_01 = cls.env["vcp.request"].create( + { + "external_id": 1, + "name": "Test PR", + "repository_id": repository.id, + "user_id": user_01.id, + "organization_id": org_01.id, + "created_at": date, + "closed_at": date, + "is_merged": True, + } + ) + cls.env["vcp.request"].create( + { + "external_id": 2, + "name": "Test PR", + "repository_id": repository.id, + "user_id": user_02.id, + "organization_id": org_01.id, + "created_at": date, + "is_merged": False, + } + ) + cls.env["vcp.request"].create( + { + "external_id": 3, + "name": "Test PR", + "repository_id": repository.id, + "user_id": user_03.id, + "organization_id": org_02.id, + "created_at": date, + "is_merged": False, + } + ) + cls.env["vcp.review"].create( + { + "external_id": 1, + "body": "Test Review", + "state": "APPROVED", + "request_id": pull_request_01.id, + "user_id": user_01.id, + "submitted_at": date, + } + ) + cls.env["vcp.comment"].create( + { + "external_id": 1, + "body": "Test Comment", + "request_id": pull_request_01.id, + "user_id": user_01.id, + "created_at": date, + } + ) + + def test_01_portal_load_tour(self): + self.start_tour("/", "portal_load_vcp", login="portal") diff --git a/vcp_website/README.rst b/vcp_website/README.rst new file mode 100644 index 0000000..83636f0 --- /dev/null +++ b/vcp_website/README.rst @@ -0,0 +1,82 @@ +================================ +Version Control Platform Website +================================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:fc63310fd3dc2d79e35eb27c50cd083cfcd5822270ce0d3f750e8cf51c0b8ca9 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fversion--control--platform-lightgray.png?logo=github + :target: https://github.com/OCA/version-control-platform/tree/18.0/vcp_website + :alt: OCA/version-control-platform +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/version-control-platform-18-0/version-control-platform-18-0-vcp_website + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/version-control-platform&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Glue module for showing VCP data in partner website. + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Dixmit + +Contributors +------------ + +- `Dixmit `__ + + - Enric Tobella + +- `GRAP `__ + + - Sylvain le Gal + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/version-control-platform `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/vcp_website/__init__.py b/vcp_website/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/vcp_website/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/vcp_website/__manifest__.py b/vcp_website/__manifest__.py new file mode 100644 index 0000000..82875c7 --- /dev/null +++ b/vcp_website/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2026 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Version Control Platform Website", + "summary": """Adds integration of VCP with Odoo Website""", + "version": "18.0.1.0.0", + "license": "AGPL-3", + "author": "Dixmit,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/version-control-platform", + "depends": [ + "vcp_management", + "website_partner", + ], + "data": [ + "templates/templates.xml", + ], + "demo": [], +} diff --git a/vcp_website/models/__init__.py b/vcp_website/models/__init__.py new file mode 100644 index 0000000..a26148b --- /dev/null +++ b/vcp_website/models/__init__.py @@ -0,0 +1,2 @@ +from . import vcp_user +from . import vcp_organization diff --git a/vcp_website/models/vcp_organization.py b/vcp_website/models/vcp_organization.py new file mode 100644 index 0000000..1f4acfd --- /dev/null +++ b/vcp_website/models/vcp_organization.py @@ -0,0 +1,19 @@ +# Copyright 2025 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class VcpOrganization(models.Model): + _inherit = "vcp.organization" + + def _get_contributor_url(self): + result = super()._get_contributor_url() + if ( + not result + and self.partner_id + and self.partner_id.is_published + and self.partner_id.website_url + ): + return self.partner_id.website_url + return result diff --git a/vcp_website/models/vcp_user.py b/vcp_website/models/vcp_user.py new file mode 100644 index 0000000..64291e2 --- /dev/null +++ b/vcp_website/models/vcp_user.py @@ -0,0 +1,19 @@ +# Copyright 2025 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class VcpUser(models.Model): + _inherit = "vcp.user" + + def _get_contributor_url(self): + result = super()._get_contributor_url() + if ( + not result + and self.partner_id + and self.partner_id.is_published + and self.partner_id.website_url + ): + return self.partner_id.website_url + return result diff --git a/vcp_website/pyproject.toml b/vcp_website/pyproject.toml new file mode 100644 index 0000000..4231d0c --- /dev/null +++ b/vcp_website/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/vcp_website/readme/CONTRIBUTORS.md b/vcp_website/readme/CONTRIBUTORS.md new file mode 100644 index 0000000..6d06eb2 --- /dev/null +++ b/vcp_website/readme/CONTRIBUTORS.md @@ -0,0 +1,5 @@ +- [Dixmit](https://dixmit.com) + - Enric Tobella + +- [GRAP](https://www.grap.coop/) + - Sylvain le Gal \ No newline at end of file diff --git a/vcp_website/readme/DESCRIPTION.md b/vcp_website/readme/DESCRIPTION.md new file mode 100644 index 0000000..bb370a4 --- /dev/null +++ b/vcp_website/readme/DESCRIPTION.md @@ -0,0 +1 @@ +Glue module for showing VCP data in partner website. diff --git a/vcp_website/static/description/icon.png b/vcp_website/static/description/icon.png new file mode 100644 index 0000000..3a0328b Binary files /dev/null and b/vcp_website/static/description/icon.png differ diff --git a/vcp_website/static/description/index.html b/vcp_website/static/description/index.html new file mode 100644 index 0000000..35c6d42 --- /dev/null +++ b/vcp_website/static/description/index.html @@ -0,0 +1,430 @@ + + + + + +Version Control Platform Website + + + +
+

Version Control Platform Website

+ + +

Beta License: AGPL-3 OCA/version-control-platform Translate me on Weblate Try me on Runboat

+

Glue module for showing VCP data in partner website.

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Dixmit
  • +
+
+
+

Contributors

+
    +
  • Dixmit
      +
    • Enric Tobella
    • +
    +
  • +
  • GRAP
      +
    • Sylvain le Gal
    • +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/version-control-platform project on GitHub.

+

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

+
+
+
+ + diff --git a/vcp_website/templates/templates.xml b/vcp_website/templates/templates.xml new file mode 100644 index 0000000..a26b43e --- /dev/null +++ b/vcp_website/templates/templates.xml @@ -0,0 +1,8 @@ + + + +