From 00bf03ee76e8aa04def01d911cc0668fc352d3ff Mon Sep 17 00:00:00 2001 From: Anjeel Haria Date: Wed, 18 Sep 2024 16:06:47 +0530 Subject: [PATCH] [ADD] gitlab --- gitlab/README.rst | 85 ++++++ gitlab/__init__.py | 1 + gitlab/__manifest__.py | 12 + gitlab/menuitems.xml | 9 + gitlab/models/__init__.py | 1 + gitlab/models/gitlab.py | 47 +++ gitlab/readme/CONTRIBUTORS.rst | 1 + gitlab/readme/DESCRIPTION.rst | 2 + gitlab/readme/USAGE.rst | 4 + gitlab/security/ir_model_access.xml | 12 + gitlab/static/description/index.html | 433 +++++++++++++++++++++++++++ gitlab/tests/__init__.py | 1 + gitlab/tests/test_gitlab.py | 32 ++ gitlab/views/gitlab_view.xml | 37 +++ requirements.txt | 2 + setup/gitlab/odoo/addons/gitlab | 1 + setup/gitlab/setup.py | 6 + 17 files changed, 686 insertions(+) create mode 100644 gitlab/README.rst create mode 100644 gitlab/__init__.py create mode 100644 gitlab/__manifest__.py create mode 100644 gitlab/menuitems.xml create mode 100644 gitlab/models/__init__.py create mode 100644 gitlab/models/gitlab.py create mode 100644 gitlab/readme/CONTRIBUTORS.rst create mode 100644 gitlab/readme/DESCRIPTION.rst create mode 100644 gitlab/readme/USAGE.rst create mode 100644 gitlab/security/ir_model_access.xml create mode 100644 gitlab/static/description/index.html create mode 100644 gitlab/tests/__init__.py create mode 100644 gitlab/tests/test_gitlab.py create mode 100644 gitlab/views/gitlab_view.xml create mode 100644 requirements.txt create mode 120000 setup/gitlab/odoo/addons/gitlab create mode 100644 setup/gitlab/setup.py diff --git a/gitlab/README.rst b/gitlab/README.rst new file mode 100644 index 000000000..4d9982861 --- /dev/null +++ b/gitlab/README.rst @@ -0,0 +1,85 @@ +====== +Gitlab +====== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:5fe540da3a23a490321ee98260fbc37dcc03fb8ceac994d75890e7b2af7753b3 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fvertical--association-lightgray.png?logo=github + :target: https://github.com/OCA/vertical-association/tree/16.0/gitlab + :alt: OCA/vertical-association +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/vertical-association-16-0/vertical-association-16-0-gitlab + :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/vertical-association&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module does not provide a functionality by itself but a model +to implement gitlab related features + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +#. Go to *Settings > Technical > Gitlab Connections*. +#. Create new gitlab connections by filling in the details and then you can test the gitlab connection by clicking on "Test Connection" button. + +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 +~~~~~~~ + +* Onestein + +Contributors +~~~~~~~~~~~~ + +* `Onestein `_ + +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/vertical-association `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/gitlab/__init__.py b/gitlab/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/gitlab/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/gitlab/__manifest__.py b/gitlab/__manifest__.py new file mode 100644 index 000000000..f56a65aa0 --- /dev/null +++ b/gitlab/__manifest__.py @@ -0,0 +1,12 @@ +{ + "name": "Gitlab", + "summary": "Base module for implementing gitlab related features", + "category": "Technical", + "version": "16.0.1.0.0", + "author": "Onestein, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/vertical-association", + "license": "AGPL-3", + "depends": ["base"], + "external_dependencies": {"python": ["gitlab"]}, + "data": ["security/ir_model_access.xml", "views/gitlab_view.xml", "menuitems.xml"], +} diff --git a/gitlab/menuitems.xml b/gitlab/menuitems.xml new file mode 100644 index 000000000..db16a39d6 --- /dev/null +++ b/gitlab/menuitems.xml @@ -0,0 +1,9 @@ + + + + diff --git a/gitlab/models/__init__.py b/gitlab/models/__init__.py new file mode 100644 index 000000000..873b96e07 --- /dev/null +++ b/gitlab/models/__init__.py @@ -0,0 +1 @@ +from . import gitlab diff --git a/gitlab/models/gitlab.py b/gitlab/models/gitlab.py new file mode 100644 index 000000000..ceb3ee99d --- /dev/null +++ b/gitlab/models/gitlab.py @@ -0,0 +1,47 @@ +from odoo import _, fields, models + +import gitlab + + +class Gitlab(models.Model): + _name = "gitlab" + _description = "Gitlab Connection" + + url = fields.Char(string="URL", default="https://gitlab.com") + private_token = fields.Char(string="Private / Personal Token", required=True) + debug = fields.Boolean(string="Enable Debug Mode") + + def name_get(self): + res = [] + for record in self: + res.append((record.id, record.url)) + return res + + def get_server_connection(self): + self.ensure_one() + gl = gitlab.Gitlab(url=self.url, private_token=self.private_token) + if self.debug: + gl.enable_debug() + return gl + + def validate(self): + gl = self.get_server_connection() + try: + gl.auth() + title = _("Connection Test Succeeded!") + message = _("Everything seems properly set up!") + msg_type = "success" + except Exception as e: + title = _("Connection Test Failed!") + message = str(e) + msg_type = "danger" + return { + "type": "ir.actions.client", + "tag": "display_notification", + "params": { + "title": title, + "message": message, + "type": msg_type, + "sticky": False, + }, + } diff --git a/gitlab/readme/CONTRIBUTORS.rst b/gitlab/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..85125abb2 --- /dev/null +++ b/gitlab/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* `Onestein `_ diff --git a/gitlab/readme/DESCRIPTION.rst b/gitlab/readme/DESCRIPTION.rst new file mode 100644 index 000000000..00bac5241 --- /dev/null +++ b/gitlab/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module does not provide a functionality by itself but a model +to implement gitlab related features \ No newline at end of file diff --git a/gitlab/readme/USAGE.rst b/gitlab/readme/USAGE.rst new file mode 100644 index 000000000..6dd083c83 --- /dev/null +++ b/gitlab/readme/USAGE.rst @@ -0,0 +1,4 @@ +To use this module, you need to: + +#. Go to *Settings > Technical > Gitlab Connections*. +#. Create new gitlab connections by filling in the details and then you can test the gitlab connection by clicking on "Test Connection" button. diff --git a/gitlab/security/ir_model_access.xml b/gitlab/security/ir_model_access.xml new file mode 100644 index 000000000..c7a32b9b9 --- /dev/null +++ b/gitlab/security/ir_model_access.xml @@ -0,0 +1,12 @@ + + + + gitlab_access + + + + + + + + diff --git a/gitlab/static/description/index.html b/gitlab/static/description/index.html new file mode 100644 index 000000000..d5223c8d7 --- /dev/null +++ b/gitlab/static/description/index.html @@ -0,0 +1,433 @@ + + + + + +Gitlab + + + +
+

Gitlab

+ + +

Beta License: AGPL-3 OCA/vertical-association Translate me on Weblate Try me on Runboat

+

This module does not provide a functionality by itself but a model +to implement gitlab related features

+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  1. Go to Settings > Technical > Gitlab Connections.
  2. +
  3. Create new gitlab connections by filling in the details and then you can test the gitlab connection by clicking on “Test Connection” button.
  4. +
+
+
+

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

+
    +
  • Onestein
  • +
+
+ +
+

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/vertical-association project on GitHub.

+

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

+
+
+
+ + diff --git a/gitlab/tests/__init__.py b/gitlab/tests/__init__.py new file mode 100644 index 000000000..15d045949 --- /dev/null +++ b/gitlab/tests/__init__.py @@ -0,0 +1 @@ +from . import test_gitlab diff --git a/gitlab/tests/test_gitlab.py b/gitlab/tests/test_gitlab.py new file mode 100644 index 000000000..0c6a5e708 --- /dev/null +++ b/gitlab/tests/test_gitlab.py @@ -0,0 +1,32 @@ +# Copyright 2024 Onestein +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from unittest.mock import patch + +from odoo import _ +from odoo.tests.common import TransactionCase + +from gitlab.client import Gitlab + + +class TestGitlab(TransactionCase): + def setUp(self): + super().setUp() + self.gitlab = self.env["gitlab"].create({"private_token": "test"}) + + def test_name_get(self): + self.assertTrue(self.gitlab.name_get()) + + def test_gitlab_connection(self): + action = self.gitlab.validate() + self.assertEqual(action["params"]["title"], _("Connection Test Failed!")) + + def auth(self): + return True + + with patch.object( + Gitlab, + "auth", + auth, + ): + action = self.gitlab.validate() + self.assertEqual(action["params"]["title"], _("Connection Test Succeeded!")) diff --git a/gitlab/views/gitlab_view.xml b/gitlab/views/gitlab_view.xml new file mode 100644 index 000000000..e542e23c1 --- /dev/null +++ b/gitlab/views/gitlab_view.xml @@ -0,0 +1,37 @@ + + + + gitlab + +
+
+
+ + + + + + + +
+
+
+ + + gitlab + + + + + + + + + + Gitlab Connections + gitlab + tree,form + + +
diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000..68f9e5a1a --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +# generated from manifests external_dependencies +gitlab diff --git a/setup/gitlab/odoo/addons/gitlab b/setup/gitlab/odoo/addons/gitlab new file mode 120000 index 000000000..bc856988e --- /dev/null +++ b/setup/gitlab/odoo/addons/gitlab @@ -0,0 +1 @@ +../../../../gitlab \ No newline at end of file diff --git a/setup/gitlab/setup.py b/setup/gitlab/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/gitlab/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)