Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 162 additions & 0 deletions gitlab/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
======
Gitlab
======

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:06e5b29fb96bdc9d0896b700277e1e3d90761579ee8dabcfe21b4cf8bbe50073
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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%2Fserver--backend-lightgray.png?logo=github
:target: https://github.com/OCA/server-backend/tree/18.0/gitlab
:alt: OCA/server-backend
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-backend-18-0/server-backend-18-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/server-backend&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module integrates Odoo with GitLab, allowing you to synchronize
GitLab projects, notes, issues, and merge requests directly in Odoo. You
can handle multiple GitLab instances. The module leverages the
``queue_job`` module for fast and efficient background job processing,
ensuring that data synchronization does not interfere with regular Odoo
operations.

**Features:**

- Import GitLab groups and projects
- Import GitLab issues and merge requests
- Import GitLab notes on issues and merge requests
- Throughput calculation for issues and merge requests

You can use this module on it self or use to build more complex
integrations with GitLab.

**Table of contents**

.. contents::
:local:

Installation
============

Be sure to have the library ``python-gitlab`` installed in your Odoo
environment. You can install it using pip:

.. code:: bash

pip install python-gitlab

Configuration
=============

To configure this module please follow the steps below:

1. Make sure you have configured the ``queue_job`` module, as it is
required for background jobs processing.

- See https://github.com/OCA/queue/tree/18.0/queue_job for instructions.

2. **GitLab Instance Configuration**:

- Ensure you have access to a GitLab instance (self-hosted or
GitLab.com).
- Create a Personal Access Token (PAT) with the ``api`` scope.

3. **Odoo Configuration**:

- Navigate to the GitLab connection settings (Settings > Technical >
Gitlab > Connections).
- Enter the GitLab instance URL and the Personal Token.
- Test the connection to ensure it is working correctly.

4. **Group Setup**:

- Create an GitLab group in Odoo (Settings > Technical > Gitlab >
Groups).
- After creating the group you can import subgroups automatically
using the "Import Subgroups" button.

5. **Project Setup**:

- Create an GitLab project in Odoo (Settings > Technical > Gitlab >
Projects).
- Or import projects directly from the linked GitLab group. This is
recursive and will import all projects of all subgroups.

6. **Enable Scheduled Actions**:

- To keep data synchronized, ensure that the scheduled action
"Gitlab: Scheduled Import" is enabled (Settings > Technical >
Automation > Scheduled Actions). by default, this action is
disabled.

7. **Job Queue Channel**:

- It is recommended to set up a dedicated job queue channel for
GitLab synchronization tasks to avoid interference with other
background jobs.

Usage
=====

The import data is found in Settings > Technical > Gitlab where you can
filter and group by different fields.

Known issues / Roadmap
======================

- Support write operations on GitLab issues and merge requests from Odoo

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-backend/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 <https://github.com/OCA/server-backend/issues/new?body=module:%20gitlab%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* Onestein

Contributors
------------

- Dennis Sluijk d.sluijk@onestein.nl

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/server-backend <https://github.com/OCA/server-backend/tree/18.0/gitlab>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions gitlab/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
26 changes: 26 additions & 0 deletions gitlab/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "Gitlab",
"category": "Tools",
"version": "18.0.1.0.0",
"author": "Onestein, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/server-backend",
"license": "AGPL-3",
"depends": ["base", "queue_job"],
"external_dependencies": {"python": ["python-gitlab"]},
"demo": ["demo/gitlab_data.xml"],
"data": [
"security/ir_model_access.xml",
"data/ir_cron_data.xml",
"data/queue_job_function_data.xml",
"views/gitlab_view.xml",
"views/group_view.xml",
"views/project_view.xml",
"views/commit_view.xml",
"views/issue_view.xml",
"views/merge_request_view.xml",
"views/note_view.xml",
"views/merge_request_approval_view.xml",
"views/res_partner_view.xml",
"menuitems.xml",
],
}
22 changes: 22 additions & 0 deletions gitlab/data/ir_cron_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record model="ir.cron" id="cron_import">
<field name="name">Gitlab: Scheduled Import</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="active">False</field>
<field name="model_id" ref="gitlab.model_gitlab" />
<field name="state">code</field>
<field name="code">model.cron_import()</field>
</record>

<record model="ir.cron" id="cron_update_throughtput_times">
<field name="name">Gitlab: Update Throughput Times</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="active">True</field>
<field name="model_id" ref="gitlab.model_gitlab" />
<field name="state">code</field>
<field name="code">model.cron_update_throughtput_times()</field>
</record>
</odoo>
35 changes: 35 additions & 0 deletions gitlab/data/queue_job_function_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record model="queue.job.function" id="job_function_import_projects">
<field name="model_id" ref="model_gitlab_group" />
<field name="method">_import_projects</field>
</record>
<record model="queue.job.function" id="job_function_import_subgroups">
<field name="model_id" ref="model_gitlab_group" />
<field name="method">_import_subgroups</field>
</record>
<record model="queue.job.function" id="job_function_import_issue_notes">
<field name="model_id" ref="model_gitlab_issue" />
<field name="method">_import_notes</field>
</record>
<record model="queue.job.function" id="job_function_import_merge_request_notes">
<field name="model_id" ref="model_gitlab_merge_request" />
<field name="method">_import_notes</field>
</record>
<record model="queue.job.function" id="job_function_import_merge_request_approvals">
<field name="model_id" ref="model_gitlab_merge_request" />
<field name="method">_import_approvals</field>
</record>
<record model="queue.job.function" id="job_function_import_merge_requests">
<field name="model_id" ref="model_gitlab_project" />
<field name="method">_import_merge_requests</field>
</record>
<record model="queue.job.function" id="job_function_import_issues">
<field name="model_id" ref="model_gitlab_project" />
<field name="method">_import_issues</field>
</record>
<record model="queue.job.function" id="job_function_import_commits">
<field name="model_id" ref="model_gitlab_project" />
<field name="method">_import_commits</field>
</record>
</odoo>
7 changes: 7 additions & 0 deletions gitlab/demo/gitlab_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="gitlab_demo" model="gitlab">
<field name="url">https://gitlab.com</field>
<field name="private_token">fake_token</field>
</record>
</odoo>
53 changes: 53 additions & 0 deletions gitlab/menuitems.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<menuitem id="gitlab_root_menu" parent="base.menu_custom" name="Gitlab" />
<menuitem
id="gitlab_menu"
parent="gitlab_root_menu"
action="gitlab_action"
name="Connections"
/>

<menuitem
id="group_menu"
parent="gitlab_root_menu"
action="group_action"
name="Groups"
/>
<menuitem
id="project_menu"
parent="gitlab_root_menu"
action="project_action"
name="Projects"
/>
<menuitem
id="commit_menu"
parent="gitlab_root_menu"
action="commit_action"
name="Commits"
/>
<menuitem
id="issue_menu"
parent="gitlab_root_menu"
action="issue_action"
name="Issues"
/>
<menuitem
id="merge_request_menu"
parent="gitlab_root_menu"
action="merge_request_action"
name="Merge Requests"
/>
<menuitem
id="note_menu"
parent="gitlab_root_menu"
action="note_action"
name="Notes"
/>
<menuitem
id="merge_request_approval_menu"
parent="gitlab_root_menu"
action="merge_request_approval_action"
name="Merge Request Approvals"
/>
</odoo>
9 changes: 9 additions & 0 deletions gitlab/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from . import gitlab
from . import group
from . import project
from . import commit
from . import issue
from . import merge_request
from . import note
from . import merge_request_approval
from . import res_partner
42 changes: 42 additions & 0 deletions gitlab/models/commit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from odoo import api, fields, models


class Commit(models.Model):
_name = "gitlab.commit"
_description = "Gitlab Commit"
_rec_name = "external_id"

project_id = fields.Many2one(
comodel_name="gitlab.project", string="Project", required=True
)
external_id = fields.Char(string="External ID", required=True)
message = fields.Text()
author_name = fields.Char()
author_email = fields.Char()
committed_date = fields.Datetime(required=True)
url = fields.Char(string="URL", required=True)
partner_id = fields.Many2one(
comodel_name="res.partner",
string="Author Partner",
compute="_compute_partner_id",
store=True,
)

@api.depends("author_email")
def _compute_partner_id(self):
for commit in self:
partner_id = self.env["res.partner"].get_by_gitlab_email(
commit.author_email
)
commit.partner_id = partner_id

def reconcile_partner(self):
self._compute_partner_id()

_sql_constraints = [
(
"unique_commit_per_project",
"unique(project_id, external_id)",
"The commit must be unique per project.",
),
]
Loading
Loading