[UPD] Add git.platform model
to manage connection with other Git softwares
This commit is contained in:
@@ -3,3 +3,4 @@
|
|||||||
from . import project_task
|
from . import project_task
|
||||||
from . import git_issue
|
from . import git_issue
|
||||||
from . import git_repo
|
from . import git_repo
|
||||||
|
from . import git_platform
|
||||||
|
@@ -8,7 +8,10 @@ class GitIssue(models.Model):
|
|||||||
_description = "Issue Git"
|
_description = "Issue Git"
|
||||||
|
|
||||||
name = fields.Char(string="Title", required=True, copy=True)
|
name = fields.Char(string="Title", required=True, copy=True)
|
||||||
repo = fields.Many2one("git.repo", required=True, copy=True)
|
platform = fields.Many2one("git.platform", string="Git platform", required=True)
|
||||||
|
repo = fields.Many2one(
|
||||||
|
"git.repo", string="Git repository", required=True, copy=True
|
||||||
|
)
|
||||||
status = fields.Selection(
|
status = fields.Selection(
|
||||||
[
|
[
|
||||||
("opened", "Opened"),
|
("opened", "Opened"),
|
||||||
|
12
dev_git_project_task_connector/models/git_platform.py
Normal file
12
dev_git_project_task_connector/models/git_platform.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from odoo import models, fields
|
||||||
|
|
||||||
|
|
||||||
|
class GitPlatform(models.Model):
|
||||||
|
_name = "git.platform"
|
||||||
|
_description = "Git Platform"
|
||||||
|
|
||||||
|
name = fields.Char(string="Name", required=True)
|
||||||
|
tool = fields.Selection([], string="Tool", required=True)
|
||||||
|
url = fields.Char(string="URL", required=True, copy=False)
|
@@ -7,6 +7,7 @@ class GitRepository(models.Model):
|
|||||||
_name = "git.repo"
|
_name = "git.repo"
|
||||||
_description = "Repository Git"
|
_description = "Repository Git"
|
||||||
|
|
||||||
|
platform_id = fields.Many2one("git.platform", string="Git platform", required=True)
|
||||||
name = fields.Char(string="Name", required=True)
|
name = fields.Char(string="Name", required=True)
|
||||||
owner = fields.Char(string="Owner", required=True)
|
owner = fields.Char(string="Owner", required=True)
|
||||||
displayed_name = fields.Char(
|
displayed_name = fields.Char(
|
||||||
|
@@ -2,4 +2,6 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
|||||||
access_git_issue_user,git.issue.user,dev_git_project_task_connector.model_git_issue,project.group_project_user,1,0,0,0
|
access_git_issue_user,git.issue.user,dev_git_project_task_connector.model_git_issue,project.group_project_user,1,0,0,0
|
||||||
access_git_issue_manager,git.issue.manager,dev_git_project_task_connector.model_git_issue,project.group_project_manager,1,1,1,1
|
access_git_issue_manager,git.issue.manager,dev_git_project_task_connector.model_git_issue,project.group_project_manager,1,1,1,1
|
||||||
access_git_repo_user,git.repo.user,dev_git_project_task_connector.model_git_repo,project.group_project_user,1,0,0,0
|
access_git_repo_user,git.repo.user,dev_git_project_task_connector.model_git_repo,project.group_project_user,1,0,0,0
|
||||||
access_git_repo_manager,git.repo.manager,dev_git_project_task_connector.model_git_repo,project.group_project_manager,1,1,1,1
|
access_git_repo_manager,git.repo.manager,dev_git_project_task_connector.model_git_repo,project.group_project_manager,1,1,1,1
|
||||||
|
access_git_platform_user,git.platform.user,dev_git_project_task_connector.model_git_platform,project.group_project_user,1,0,0,0
|
||||||
|
access_git_platform_manager,git.platform.manager,dev_git_project_task_connector.model_git_platform,project.group_project_manager,1,1,1,1
|
|
@@ -7,6 +7,7 @@
|
|||||||
<tree>
|
<tree>
|
||||||
<field name="name" />
|
<field name="name" />
|
||||||
<field name="task_id" />
|
<field name="task_id" />
|
||||||
|
<field name="platform" />
|
||||||
<field name="repo" />
|
<field name="repo" />
|
||||||
<field name="url" />
|
<field name="url" />
|
||||||
<field name="status" />
|
<field name="status" />
|
||||||
|
@@ -5,6 +5,7 @@
|
|||||||
<field name="model">git.repo</field>
|
<field name="model">git.repo</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree editable="bottom">
|
<tree editable="bottom">
|
||||||
|
<field name="platform_id" />
|
||||||
<field name="owner" />
|
<field name="owner" />
|
||||||
<field name="name" />
|
<field name="name" />
|
||||||
<field name="displayed_name" readonly="1" />
|
<field name="displayed_name" readonly="1" />
|
||||||
|
@@ -14,6 +14,8 @@
|
|||||||
<field name="issue_ids" nolabel="1" mode="tree">
|
<field name="issue_ids" nolabel="1" mode="tree">
|
||||||
<tree create="0" delete="1">
|
<tree create="0" delete="1">
|
||||||
<field name="name" />
|
<field name="name" />
|
||||||
|
<field name="platform" />
|
||||||
|
<field name="repo" />
|
||||||
<field name="status" />
|
<field name="status" />
|
||||||
<field name="url" widget="url" />
|
<field name="url" widget="url" />
|
||||||
</tree>
|
</tree>
|
||||||
|
@@ -7,6 +7,7 @@ class CreateGitIssue(models.TransientModel):
|
|||||||
_name = "create.git.issue"
|
_name = "create.git.issue"
|
||||||
_description = "Create a Git Issue"
|
_description = "Create a Git Issue"
|
||||||
|
|
||||||
|
issue_platform = fields.Many2one("git.platform", required=True)
|
||||||
issue_name = fields.Char(string="Title", required=True)
|
issue_name = fields.Char(string="Title", required=True)
|
||||||
issue_description = fields.Html(string="Description", required=False)
|
issue_description = fields.Html(string="Description", required=False)
|
||||||
issue_repo = fields.Many2one("git.repo", required=True)
|
issue_repo = fields.Many2one("git.repo", required=True)
|
||||||
@@ -17,8 +18,9 @@ class CreateGitIssue(models.TransientModel):
|
|||||||
|
|
||||||
# Function to inherit in Git platform connector addons
|
# Function to inherit in Git platform connector addons
|
||||||
def _create_git_issue(self):
|
def _create_git_issue(self):
|
||||||
return {}
|
return None
|
||||||
|
|
||||||
def create_issue(self):
|
def create_issue(self):
|
||||||
values = self._create_git_issue()
|
values = self._create_git_issue()
|
||||||
self.env["git.issue"].create(values)
|
if values:
|
||||||
|
self.env["git.issue"].create(values)
|
||||||
|
@@ -7,7 +7,8 @@
|
|||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form string="create a new Git issue linked to the current task">
|
<form string="create a new Git issue linked to the current task">
|
||||||
<group>
|
<group>
|
||||||
<field name="issue_repo" widget="selection" placeholder="Choose the repository of the issue" />
|
<field name="issue_platform" widget="selection" placeholder="Choose the platform for the issue" />
|
||||||
|
<field name="issue_repo" domain="[('platform_id', '=', issue_platform)]" widget="selection" placeholder="Choose the repository for the issue" />
|
||||||
<field name="issue_name" />
|
<field name="issue_name" />
|
||||||
<field name="issue_description" />
|
<field name="issue_description" />
|
||||||
</group>
|
</group>
|
||||||
|
@@ -7,13 +7,19 @@ class LinkGitIssue(models.TransientModel):
|
|||||||
_name = "link.git.issue"
|
_name = "link.git.issue"
|
||||||
_description = "Link a Git Issue to a project task"
|
_description = "Link a Git Issue to a project task"
|
||||||
|
|
||||||
|
issue_platform = fields.Many2one("git.platform", required=True)
|
||||||
issue_repo = fields.Many2one("git.repo", string="Repository", required=True)
|
issue_repo = fields.Many2one("git.repo", string="Repository", required=True)
|
||||||
issue_number = fields.Integer("Issue number", required=True)
|
issue_number = fields.Integer("Issue number", required=True)
|
||||||
|
|
||||||
|
# Function to inherit in Git platform connector addons
|
||||||
|
def _convert_issue_status(self, status):
|
||||||
|
return status
|
||||||
|
|
||||||
# Function to inherit in Git platform connector addons
|
# Function to inherit in Git platform connector addons
|
||||||
def _compute_issue_values(self):
|
def _compute_issue_values(self):
|
||||||
return {}
|
return None
|
||||||
|
|
||||||
def link_issue(self):
|
def link_issue(self):
|
||||||
values = self._compute_issue_values()
|
values = self._compute_issue_values()
|
||||||
self.env["git.issue"].create(values)
|
if values:
|
||||||
|
self.env["git.issue"].create(values)
|
||||||
|
@@ -7,7 +7,8 @@
|
|||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form string="Link an existing Git issue to the current task">
|
<form string="Link an existing Git issue to the current task">
|
||||||
<group>
|
<group>
|
||||||
<field name="issue_repo" widget="selection" placeholder="Choose the repository of the issue" />
|
<field name="issue_platform" widget="selection" placeholder="Choose the platform of the issue" />
|
||||||
|
<field name="issue_repo" domain="[('platform_id', '=', issue_platform)]" widget="selection" placeholder="Choose the repository of the issue" />
|
||||||
<field name="issue_number" />
|
<field name="issue_number" />
|
||||||
</group>
|
</group>
|
||||||
<footer>
|
<footer>
|
||||||
|
@@ -66,6 +66,7 @@ This module is maintained by ELABORE.
|
|||||||
# always loaded
|
# always loaded
|
||||||
"data": [
|
"data": [
|
||||||
"views/res_user.xml",
|
"views/res_user.xml",
|
||||||
|
"data/git_platform.xml",
|
||||||
],
|
],
|
||||||
# only loaded in demonstration mode
|
# only loaded in demonstration mode
|
||||||
"demo": [],
|
"demo": [],
|
||||||
|
10
dev_github_connector/data/git_platform.xml
Normal file
10
dev_github_connector/data/git_platform.xml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<record id="github_platform" model="git.platform">
|
||||||
|
<field name="name">Github</field>
|
||||||
|
<field name="tool">github</field>
|
||||||
|
<field name="url">https://github.com</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
@@ -1,3 +1,4 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from . import res_user
|
from . import res_user
|
||||||
|
from . import git_platform
|
||||||
|
9
dev_github_connector/models/git_platform.py
Normal file
9
dev_github_connector/models/git_platform.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from odoo import models, fields
|
||||||
|
|
||||||
|
|
||||||
|
class GitPlatform(models.Model):
|
||||||
|
_inherit = "git.platform"
|
||||||
|
|
||||||
|
tool = fields.Selection(selection_add=[("github", "Github")])
|
@@ -17,16 +17,20 @@ class CreateGitIssue(models.TransientModel):
|
|||||||
|
|
||||||
def _create_git_issue(self):
|
def _create_git_issue(self):
|
||||||
values = super(CreateGitIssue, self)._create_git_issue()
|
values = super(CreateGitIssue, self)._create_git_issue()
|
||||||
github = Github(self.env.user.github_token)
|
if self.issue_platform.tool == "github":
|
||||||
repo = github.get_repo(self.issue_repo.displayed_name)
|
github = Github(self.env.user.github_token)
|
||||||
issue = repo.create_issue(title=self.issue_name, body=self.issue_description)
|
repo = github.get_repo(self.issue_repo.displayed_name)
|
||||||
values = {
|
issue = repo.create_issue(
|
||||||
"name": issue.title,
|
title=self.issue_name, body=self.issue_description
|
||||||
"repo": self.issue_repo.id,
|
)
|
||||||
"status": self._convert_issue_status(issue.state),
|
values = {
|
||||||
"url": issue.html_url,
|
"name": issue.title,
|
||||||
"task_id": self.env["project.task"]
|
"platform": self.issue_platform.id,
|
||||||
.browse(self._context.get("active_ids"))
|
"repo": self.issue_repo.id,
|
||||||
.id,
|
"status": self._convert_issue_status(issue.state),
|
||||||
}
|
"url": issue.html_url,
|
||||||
|
"task_id": self.env["project.task"]
|
||||||
|
.browse(self._context.get("active_ids"))
|
||||||
|
.id,
|
||||||
|
}
|
||||||
return values
|
return values
|
||||||
|
@@ -7,18 +7,28 @@ from github import Github
|
|||||||
class LinkGitIssue(models.TransientModel):
|
class LinkGitIssue(models.TransientModel):
|
||||||
_inherit = "link.git.issue"
|
_inherit = "link.git.issue"
|
||||||
|
|
||||||
|
def _convert_issue_status(self, status):
|
||||||
|
if status == "open":
|
||||||
|
return "opened"
|
||||||
|
elif status == "closed":
|
||||||
|
return "closed"
|
||||||
|
else:
|
||||||
|
return super(LinkGitIssue, self)._convert_issue_status(status)
|
||||||
|
|
||||||
def _compute_issue_values(self):
|
def _compute_issue_values(self):
|
||||||
values = super(LinkGitIssue, self)._compute_issue_values()
|
values = super(LinkGitIssue, self)._compute_issue_values()
|
||||||
github = Github()
|
if self.issue_platform.tool == "github":
|
||||||
repo = github.get_repo(self.issue_repo.displayed_name)
|
github = Github()
|
||||||
issue = repo.get_issue(number=self.issue_number)
|
repo = github.get_repo(self.issue_repo.displayed_name)
|
||||||
values = {
|
issue = repo.get_issue(number=self.issue_number)
|
||||||
"name": issue.title,
|
values = {
|
||||||
"repo": self.issue_repo.id,
|
"name": issue.title,
|
||||||
"status": issue.state,
|
"platform": self.issue_platform.id,
|
||||||
"url": issue.html_url,
|
"repo": self.issue_repo.id,
|
||||||
"task_id": self.env["project.task"]
|
"status": self._convert_issue_status(issue.state),
|
||||||
.browse(self._context.get("active_ids"))
|
"url": issue.html_url,
|
||||||
.id,
|
"task_id": self.env["project.task"]
|
||||||
}
|
.browse(self._context.get("active_ids"))
|
||||||
|
.id,
|
||||||
|
}
|
||||||
return values
|
return values
|
||||||
|
Reference in New Issue
Block a user