[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 git_issue
|
||||
from . import git_repo
|
||||
from . import git_platform
|
||||
|
@@ -8,7 +8,10 @@ class GitIssue(models.Model):
|
||||
_description = "Issue Git"
|
||||
|
||||
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(
|
||||
[
|
||||
("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"
|
||||
_description = "Repository Git"
|
||||
|
||||
platform_id = fields.Many2one("git.platform", string="Git platform", required=True)
|
||||
name = fields.Char(string="Name", required=True)
|
||||
owner = fields.Char(string="Owner", required=True)
|
||||
displayed_name = fields.Char(
|
||||
|
@@ -3,3 +3,5 @@ access_git_issue_user,git.issue.user,dev_git_project_task_connector.model_git_is
|
||||
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_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>
|
||||
<field name="name" />
|
||||
<field name="task_id" />
|
||||
<field name="platform" />
|
||||
<field name="repo" />
|
||||
<field name="url" />
|
||||
<field name="status" />
|
||||
|
@@ -5,6 +5,7 @@
|
||||
<field name="model">git.repo</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree editable="bottom">
|
||||
<field name="platform_id" />
|
||||
<field name="owner" />
|
||||
<field name="name" />
|
||||
<field name="displayed_name" readonly="1" />
|
||||
|
@@ -14,6 +14,8 @@
|
||||
<field name="issue_ids" nolabel="1" mode="tree">
|
||||
<tree create="0" delete="1">
|
||||
<field name="name" />
|
||||
<field name="platform" />
|
||||
<field name="repo" />
|
||||
<field name="status" />
|
||||
<field name="url" widget="url" />
|
||||
</tree>
|
||||
|
@@ -7,6 +7,7 @@ class CreateGitIssue(models.TransientModel):
|
||||
_name = "create.git.issue"
|
||||
_description = "Create a Git Issue"
|
||||
|
||||
issue_platform = fields.Many2one("git.platform", required=True)
|
||||
issue_name = fields.Char(string="Title", required=True)
|
||||
issue_description = fields.Html(string="Description", required=False)
|
||||
issue_repo = fields.Many2one("git.repo", required=True)
|
||||
@@ -17,8 +18,9 @@ class CreateGitIssue(models.TransientModel):
|
||||
|
||||
# Function to inherit in Git platform connector addons
|
||||
def _create_git_issue(self):
|
||||
return {}
|
||||
return None
|
||||
|
||||
def create_issue(self):
|
||||
values = self._create_git_issue()
|
||||
if values:
|
||||
self.env["git.issue"].create(values)
|
||||
|
@@ -7,7 +7,8 @@
|
||||
<field name="arch" type="xml">
|
||||
<form string="create a new Git issue linked to the current task">
|
||||
<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_description" />
|
||||
</group>
|
||||
|
@@ -7,13 +7,19 @@ class LinkGitIssue(models.TransientModel):
|
||||
_name = "link.git.issue"
|
||||
_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_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
|
||||
def _compute_issue_values(self):
|
||||
return {}
|
||||
return None
|
||||
|
||||
def link_issue(self):
|
||||
values = self._compute_issue_values()
|
||||
if values:
|
||||
self.env["git.issue"].create(values)
|
||||
|
@@ -7,7 +7,8 @@
|
||||
<field name="arch" type="xml">
|
||||
<form string="Link an existing Git issue to the current task">
|
||||
<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" />
|
||||
</group>
|
||||
<footer>
|
||||
|
@@ -66,6 +66,7 @@ This module is maintained by ELABORE.
|
||||
# always loaded
|
||||
"data": [
|
||||
"views/res_user.xml",
|
||||
"data/git_platform.xml",
|
||||
],
|
||||
# only loaded in demonstration mode
|
||||
"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 -*-
|
||||
|
||||
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,11 +17,15 @@ class CreateGitIssue(models.TransientModel):
|
||||
|
||||
def _create_git_issue(self):
|
||||
values = super(CreateGitIssue, self)._create_git_issue()
|
||||
if self.issue_platform.tool == "github":
|
||||
github = Github(self.env.user.github_token)
|
||||
repo = github.get_repo(self.issue_repo.displayed_name)
|
||||
issue = repo.create_issue(title=self.issue_name, body=self.issue_description)
|
||||
issue = repo.create_issue(
|
||||
title=self.issue_name, body=self.issue_description
|
||||
)
|
||||
values = {
|
||||
"name": issue.title,
|
||||
"platform": self.issue_platform.id,
|
||||
"repo": self.issue_repo.id,
|
||||
"status": self._convert_issue_status(issue.state),
|
||||
"url": issue.html_url,
|
||||
|
@@ -7,15 +7,25 @@ from github import Github
|
||||
class LinkGitIssue(models.TransientModel):
|
||||
_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):
|
||||
values = super(LinkGitIssue, self)._compute_issue_values()
|
||||
if self.issue_platform.tool == "github":
|
||||
github = Github()
|
||||
repo = github.get_repo(self.issue_repo.displayed_name)
|
||||
issue = repo.get_issue(number=self.issue_number)
|
||||
values = {
|
||||
"name": issue.title,
|
||||
"platform": self.issue_platform.id,
|
||||
"repo": self.issue_repo.id,
|
||||
"status": issue.state,
|
||||
"status": self._convert_issue_status(issue.state),
|
||||
"url": issue.html_url,
|
||||
"task_id": self.env["project.task"]
|
||||
.browse(self._context.get("active_ids"))
|
||||
|
Reference in New Issue
Block a user