[NEW] Add Git issue creation functionnality
This commit is contained in:
@@ -70,6 +70,7 @@ This module is maintained by ELABORE.
|
||||
"data": [
|
||||
"security/ir.model.access.csv",
|
||||
"wizard/link_issue.xml",
|
||||
"wizard/create_issue.xml",
|
||||
"views/project_task.xml",
|
||||
"views/git_issue.xml",
|
||||
"views/git_repository.xml",
|
||||
|
@@ -7,7 +7,7 @@ class GitRepository(models.Model):
|
||||
_name = "git.repo"
|
||||
_description = "Repository Git"
|
||||
|
||||
name = fields.Char(string="name", required=True)
|
||||
name = fields.Char(string="Name", required=True)
|
||||
owner = fields.Char(string="Owner", required=True)
|
||||
displayed_name = fields.Char(
|
||||
string="Displayed name", compute="_compute_displayed_name"
|
||||
|
@@ -16,3 +16,12 @@ class Task(models.Model):
|
||||
"res_model": "link.git.issue",
|
||||
"target": "new",
|
||||
}
|
||||
|
||||
def create_issue(self):
|
||||
return {
|
||||
"name": "Create a Git issue",
|
||||
"type": "ir.actions.act_window",
|
||||
"view_mode": "form",
|
||||
"res_model": "create.git.issue",
|
||||
"target": "new",
|
||||
}
|
||||
|
@@ -8,7 +8,8 @@
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//notebook" position="inside">
|
||||
<page name="git_issues" string="Git Issues">
|
||||
<button string="Link an issue" name="link_issue" type="object" class="oe_stat_button" icon="fa-link" />
|
||||
<button string="Create an issue" name="create_issue" type="object" class="oe_stat_button" icon="fa-plus-circle" style="margin: 0px 4px 0px 0px" />
|
||||
<button string="Link an issue" name="link_issue" type="object" class="oe_stat_button" icon="fa-link" style="margin: 0px 4px 0px 0px" />
|
||||
<separator string="Current linked issues" />
|
||||
<field name="issue_ids" nolabel="1" mode="tree">
|
||||
<tree create="0" delete="1">
|
||||
|
@@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import link_issue
|
||||
from . import create_issue
|
||||
|
24
dev_git_project_task_connector/wizard/create_issue.py
Normal file
24
dev_git_project_task_connector/wizard/create_issue.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import models, fields
|
||||
|
||||
|
||||
class CreateGitIssue(models.TransientModel):
|
||||
_name = "create.git.issue"
|
||||
_description = "Create a Git Issue"
|
||||
|
||||
issue_name = fields.Char(string="Title", required=True)
|
||||
issue_description = fields.Html(string="Description", required=False)
|
||||
issue_repo = fields.Many2one("git.repo", 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 _create_git_issue(self):
|
||||
return {}
|
||||
|
||||
def create_issue(self):
|
||||
values = self._create_git_issue()
|
||||
self.env["git.issue"].create(values)
|
22
dev_git_project_task_connector/wizard/create_issue.xml
Normal file
22
dev_git_project_task_connector/wizard/create_issue.xml
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="create_issue_wizard" model="ir.ui.view">
|
||||
<field name="name">create_issue.wizard</field>
|
||||
<field name="model">create.git.issue</field>
|
||||
<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_name" />
|
||||
<field name="issue_description" />
|
||||
</group>
|
||||
<footer>
|
||||
<button string="Create" name="create_issue" type="object" class="btn-primary" />
|
||||
<button string="Cancel" class="btn-secondary" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
@@ -10,8 +10,8 @@ class LinkGitIssue(models.TransientModel):
|
||||
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 _compute_issue_values(self):
|
||||
# Function to inherit in Git platform connector addons
|
||||
return {}
|
||||
|
||||
def link_issue(self):
|
||||
|
@@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import models
|
||||
from . import wizard
|
||||
|
@@ -64,7 +64,9 @@ This module is maintained by ELABORE.
|
||||
"python": [],
|
||||
},
|
||||
# always loaded
|
||||
"data": [],
|
||||
"data": [
|
||||
"views/res_user.xml",
|
||||
],
|
||||
# only loaded in demonstration mode
|
||||
"demo": [],
|
||||
"js": [],
|
||||
|
3
dev_github_connector/models/__init__.py
Normal file
3
dev_github_connector/models/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import res_user
|
9
dev_github_connector/models/res_user.py
Normal file
9
dev_github_connector/models/res_user.py
Normal file
@@ -0,0 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import models, fields
|
||||
|
||||
|
||||
class Users(models.Model):
|
||||
_inherit = "res.users"
|
||||
|
||||
github_token = fields.Char(string="Github token")
|
17
dev_github_connector/views/res_user.xml
Normal file
17
dev_github_connector/views/res_user.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
<record id="view_users_form_simple_gitub_token" model="ir.ui.view">
|
||||
<field name="name">res.users.github.preferences.form</field>
|
||||
<field name="model">res.users</field>
|
||||
<field name="inherit_id" ref="base.view_users_form_simple_modif" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//group[@name='preferences']" position="after">
|
||||
<group string="Github credentials">
|
||||
<field name="github_token" readonly="0" />
|
||||
</group>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
@@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import link_issue
|
||||
from . import create_issue
|
||||
|
32
dev_github_connector/wizard/create_issue.py
Normal file
32
dev_github_connector/wizard/create_issue.py
Normal file
@@ -0,0 +1,32 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import models
|
||||
from github import Github
|
||||
|
||||
|
||||
class CreateGitIssue(models.TransientModel):
|
||||
_inherit = "create.git.issue"
|
||||
|
||||
def _convert_issue_status(self, status):
|
||||
if status == "open":
|
||||
return "opened"
|
||||
elif status == "closed":
|
||||
return "closed"
|
||||
else:
|
||||
return super(CreateGitIssue, self)._convert_issue_status(status)
|
||||
|
||||
def _create_git_issue(self):
|
||||
values = super(CreateGitIssue, self)._create_git_issue()
|
||||
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)
|
||||
values = {
|
||||
"name": issue.title,
|
||||
"repo": self.issue_repo.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
|
Reference in New Issue
Block a user