Skip to content

Commit

Permalink
[REF] project_git_github: Black python code
Browse files Browse the repository at this point in the history
  • Loading branch information
mathben committed Dec 18, 2019
1 parent 047db80 commit 4af60ec
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 50 deletions.
13 changes: 3 additions & 10 deletions project_git_github/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,9 @@
"license": "LGPL-3",
"author": "Odoo Community Association (OCA), Modoolar",
"website": "https://www.modoolar.com/",
"depends": [
"project_git"
],
"data": [
"views/project_git_github_views.xml"
],

"depends": ["project_git"],
"data": ["views/project_git_github_views.xml"],
"demo": [],
"qweb": [

],
"qweb": [],
"application": True,
}
28 changes: 18 additions & 10 deletions project_git_github/controllers/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import urllib.parse

from odoo import http, _
from odoo.addons.project_git.controller.controller\
import GitController, GitContext
from odoo.addons.project_git.controller.controller import (
GitController,
GitContext,
)

import logging

Expand All @@ -15,15 +17,19 @@

class GitHubContext(GitContext):
def __init__(self, token, payload):
GitContext.__init__(self, 'github', token, payload)
GitContext.__init__(self, "github", token, payload)


class GitHubController(GitController):
@http.route([
'/github/payload/<string:token>'
], methods=['post'], type='http', auth='public', csrf=False)
@http.route(
["/github/payload/<string:token>"],
methods=["post"],
type="http",
auth="public",
csrf=False,
)
def process_github(self, token, *args, **kw):
payload = json.loads(http.request.httprequest.form['payload'])
payload = json.loads(http.request.httprequest.form["payload"])
return self.process_request(GitHubContext(token, payload))

def validate_github_payload(self, context):
Expand All @@ -32,14 +38,16 @@ def validate_github_payload(self, context):
if not context.has_signature and not context.repository.secret:
return True

payload = http.request.httprequest.form['payload'].encode("utf-8")
payload = http.request.httprequest.form["payload"].encode("utf-8")
payload = "payload=" + urllib.parse.quote_plus(payload)
payload_valid = context.validate_payload(payload)

if not payload_valid:
_logger.warning(
_("GitHub (delivery='%s'): received for repository (id='%s') "
"which could not be validated!.")
_(
"GitHub (delivery='%s'): received for repository (id='%s') "
"which could not be validated!."
)
% (context.delivery, context.repository.id)
)
return payload_valid
50 changes: 20 additions & 30 deletions project_git_github/models/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,19 @@

from odoo import models, fields, http

TYPE = [('github', 'GitHub')]
TYPE = [("github", "GitHub")]


class GitUser(models.Model):
_inherit = 'project.git.user'
_inherit = "project.git.user"

type = fields.Selection(
selection_add=TYPE,
)
type = fields.Selection(selection_add=TYPE,)


class GitRepository(models.Model):
_inherit = 'project.git.repository'
_inherit = "project.git.repository"

type = fields.Selection(
selection_add=TYPE,
)
type = fields.Selection(selection_add=TYPE,)

def _secret_visible_for_types(self):
types = super(GitRepository, self)._secret_visible_for_types()
Expand All @@ -30,23 +26,19 @@ def _secret_visible_for_types(self):


class GitCommit(models.Model):
_inherit = 'project.git.commit'
_inherit = "project.git.commit"

type = fields.Selection(
selection_add=TYPE,
)
type = fields.Selection(selection_add=TYPE,)


class GitBranch(models.Model):
_inherit = 'project.git.branch'
_inherit = "project.git.branch"

type = fields.Selection(
selection_add=TYPE,
)
type = fields.Selection(selection_add=TYPE,)


class GitPayloadParser(models.AbstractModel):
_inherit = 'project.git.payload.parser'
_inherit = "project.git.payload.parser"

# -------------------------------------------
# Header
Expand Down Expand Up @@ -93,28 +85,26 @@ def parse_github_push(self, context):
return {
"repository": self.parse_github_repository(context),
"branches": [self.parse_github_branch(context)],
"sender": self.parse_github_sender(context)
"sender": self.parse_github_sender(context),
}

# -------------------------------------------
# Action Delete
# -------------------------------------------
def parse_github_delete(self, context):
return {
"branches": [self.parse_github_branch(context, False)]
}
return {"branches": [self.parse_github_branch(context, False)]}

# -------------------------------------------
# Paring methods
# -------------------------------------------
def parse_github_branch(self, context, commits=True):
payload = context.raw_payload
name = payload["ref"] and payload["ref"].rsplit('/', 1)[-1] or "None"
name = payload["ref"] and payload["ref"].rsplit("/", 1)[-1] or "None"
data = {
"name": name,
"url": payload["compare"],
"type": context.type,
"repository_id": context.repository.id
"repository_id": context.repository.id,
}

if commits:
Expand All @@ -131,11 +121,11 @@ def parse_github_commits(self, context):
def parse_github_commit(self, context, commit):
return {
"name": commit["id"][:8],
"message": commit["message"] and commit["message"].strip() or '',
"message": commit["message"] and commit["message"].strip() or "",
"url": commit["url"],
"type": context.type,
"date": fields.Datetime.to_string(parse(commit["timestamp"])),
'author': self.parse_github_commit_author(context, commit),
"author": self.parse_github_commit_author(context, commit),
}

def parse_github_commit_author(self, context, commit):
Expand Down Expand Up @@ -164,9 +154,9 @@ def parse_github_sender(self, context):
return {
"username": sender["login"],
"type": context.type,
"avatar": sender['avatar_url'],
"url": sender['html_url'],
"uuid": sender['id'],
"avatar": sender["avatar_url"],
"url": sender["html_url"],
"uuid": sender["id"],
}

def parse_github_repository(self, context):
Expand All @@ -176,7 +166,7 @@ def parse_github_repository(self, context):
"uuid": repository["id"],
"url": repository["html_url"],
"type": context.type,
'owner': self.parse_github_repository_owner(context)
"owner": self.parse_github_repository_owner(context),
}

def parse_github_repository_owner(self, context):
Expand Down

0 comments on commit 4af60ec

Please sign in to comment.