[UPD] Add git.platform model
to manage connection with other Git softwares
This commit is contained in:
@@ -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,16 +17,20 @@ class CreateGitIssue(models.TransientModel):
|
||||
|
||||
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,
|
||||
}
|
||||
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
|
||||
)
|
||||
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,
|
||||
"task_id": self.env["project.task"]
|
||||
.browse(self._context.get("active_ids"))
|
||||
.id,
|
||||
}
|
||||
return values
|
||||
|
@@ -7,18 +7,28 @@ 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()
|
||||
github = Github()
|
||||
repo = github.get_repo(self.issue_repo.displayed_name)
|
||||
issue = repo.get_issue(number=self.issue_number)
|
||||
values = {
|
||||
"name": issue.title,
|
||||
"repo": self.issue_repo.id,
|
||||
"status": issue.state,
|
||||
"url": issue.html_url,
|
||||
"task_id": self.env["project.task"]
|
||||
.browse(self._context.get("active_ids"))
|
||||
.id,
|
||||
}
|
||||
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": 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