-
-
Notifications
You must be signed in to change notification settings - Fork 76
/
github_comment.py
70 lines (55 loc) · 2.05 KB
/
github_comment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-
# Copyright (C) 2016-Today: Odoo Community Association (OCA)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import logging
from openerp import models, fields, api
_logger = logging.getLogger(__name__)
try:
import markdown
except ImportError:
_logger.debug("Cannot import 'markdown' python library.")
class GithubComment(models.Model):
_name = 'github.comment'
_inherit = ['abstract.github.model.author']
_order = 'github_id'
_github_type = 'issue'
_github_login_field = False
_OPINION_SELECTION = [
('neutral', 'Neutral'),
('approved', 'Approved'),
('disapproved', 'Disapproved'),
]
# Column Section
issue_id = fields.Many2one(
comodel_name='github.issue', string='Issue / PR', readonly=True,
required=True, ondelete='cascade')
body = fields.Char(string='Body', readonly=True)
html_body = fields.Html(
string='HTML Body', readonly=True, compute='_compute_by_body',
multi='body', store=True)
opinion = fields.Selection(
string='Opinion', readonly=True, compute='_compute_by_body',
multi='body', store=True, selection=_OPINION_SELECTION,
default='neutral')
is_bot_comment = fields.Boolean(
string='Is Bot Comment', related='author_id.is_bot_account',
store=True)
# Compute section
@api.multi
@api.depends('body')
def _compute_by_body(self):
for comment in self:
if comment.body:
comment.html_body = markdown.markdown(comment.body)
if ':-1:' in comment.body:
comment.opinion = 'disapproved'
elif ':+1:' in comment.body:
comment.opinion = 'approved'
else:
comment.opinion = 'neutral'
# Overloadable Section
def get_odoo_data_from_github(self, data):
res = super(GithubComment, self).get_odoo_data_from_github(data)
res.update({'body': data['body']})
return res