Update webhook and setup #1

Open
shekhar-cis wants to merge 5 commits from shekhar-cis/buildbot-transifex:transifex-webhook into master
Showing only changes of commit 8091be197d - Show all commits

View File

@ -66,16 +66,18 @@ class TransifexHandler(BaseHookHandler):
def process_translation_completed(self, payload, codebase):

maybe just raise ValueError("Signature mismatch"), then it will propagate up

maybe just `raise ValueError("Signature mismatch")`, then it will propagate up
changes = []

return True missing

`return True` missing
translated_request = self._transform_variables(payload['project'], payload['resource'])
ts = int(time.time())

tx_signature isn't a function/method

`tx_signature` isn't a function/method
change = {
PeterSurda marked this conversation as resolved Outdated

return False

`return False`
'author': "buildbot-transifex",
'author': author,

don't have weird constants here, rather process is through the map.

don't have weird constants here, rather process is through the map.

repository missing

`repository` missing
'branch': translated_request["branch"],

transifex_to_github_map is an object attribute, no need to pass it around

`transifex_to_github_map` is an object attribute, no need to pass it around
'branch': translated_request["repository"],
PeterSurda marked this conversation as resolved Outdated
  • use constant
  • use a default value, then no need for try/except
- use constant - use a default value, then no need for try/except
'project': translated_request["project"],

error handling missing here

error handling missing here
'properties': {
"transifex_language": payload.get("language", "None"),

if you use .get with a default value, you can avoid try/except

if you use `.get` with a default value, you can avoid `try`/`except`
"transifex_event": payload.get("event", "None"),

language = payload.get('language', "None")

`language = payload.get('language', "None")`
"transifex_project": payload.get("project", "None"),
Review

this should be the randomly generated one, the branch of the PR

this should be the randomly generated one, the branch of the PR
"transifex_resource": payload.get("resource", "None"),
PeterSurda marked this conversation as resolved Outdated

This should be in the buildbot job, not here. The webhook only transforms data structures and puts them into a database.

  • "tx pull -l language {}".format(options["language"). or something like that
This should be in the buildbot job, not here. The webhook only transforms data structures and puts them into a database. - `"tx pull -l language {}".format(options["language").` or something like that

this line ('resource': ...) should be remove

this line (`'resource': ...`) should be remove
"transifex_branch": "v0.6"
"transifex_branch": "translate_" + payload['language'] + "_" + str(ts)

something like translated_request or mapped_request would be more understandable. There is not response coming from transifex.

something like `translated_request` or `mapped_request` would be more understandable. There is not response coming from transifex.
}

not translating anything. There is nothing here that translates transifex payload information into github information.

not translating anything. There is nothing here that translates transifex payload information into github information.
}
if codebase is not None:
@ -83,10 +85,10 @@ class TransifexHandler(BaseHookHandler):
changes.insert(0, change)
return changes

this is a sub-property

this is a sub-property

from map

from map
def _transform_variables(self, transifex_project, transifex_resource):
def _transform_variables(self, transifex_project):
  • no need super
  • needs master
  • doesn't save transifex_dict
  • secret also missing
- no need super - needs `master` - doesn't save `transifex_dict` - `secret` also missing

from map

from map
if transifex_project is None:
raise ValueError("Unknown project %s from transifex".format(transifex_project))
key = "{}/{}".format(transifex_project, transifex_resource)
key = transifex_project
_map = self.map[key]
repository = _map["repository"]
project = re.sub(r'^.*/(.*?)(\.git)?$', r'\1', repository)
@ -122,16 +124,6 @@ class TransifexHandler(BaseHookHandler):
request.getHeader(_HEADER_SIGNATURE))
self._verifyTransifexSignature(request, content, rendered_secret, signature, header_signature)
event_type = payload.get("event", "None")

duplicate

duplicate
mapped_request = self._transform_variables(payload['project'], payload['resource'])
change["changes"] = {
"author": author,
"repository": mapped_request["repository"],
"project": mapped_request["project"],
"branch": mapped_request["branch"]
}
log.msg("Received event '{}' from transifex".format(event_type))
codebase = ""

since we're raising inside the _verifyTransifexSignature, no need for if here anymore

since we're raising inside the `_verifyTransifexSignature`, no need for `if` here anymore