Update webhook and setup #1
|
@ -66,16 +66,18 @@ class TransifexHandler(BaseHookHandler):
|
||||||
def process_translation_completed(self, payload, codebase):
|
def process_translation_completed(self, payload, codebase):
|
||||||
|
|||||||
changes = []
|
changes = []
|
||||||
PeterSurda
commented
`return True` missing
|
|||||||
translated_request = self._transform_variables(payload['project'], payload['resource'])
|
translated_request = self._transform_variables(payload['project'], payload['resource'])
|
||||||
|
ts = int(time.time())
|
||||||
PeterSurda
commented
`tx_signature` isn't a function/method
|
|||||||
change = {
|
change = {
|
||||||
PeterSurda marked this conversation as resolved
Outdated
|
|||||||
'author': "buildbot-transifex",
|
'author': author,
|
||||||
PeterSurda
commented
don't have weird constants here, rather process is through the map. don't have weird constants here, rather process is through the map.
PeterSurda
commented
`repository` missing
|
|||||||
'branch': translated_request["branch"],
|
'branch': translated_request["branch"],
|
||||||
PeterSurda
commented
`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
PeterSurda
commented
- use constant
- use a default value, then no need for try/except
|
|||||||
'project': translated_request["project"],
|
'project': translated_request["project"],
|
||||||
PeterSurda
commented
error handling missing here error handling missing here
|
|||||||
'properties': {
|
'properties': {
|
||||||
"transifex_language": payload.get("language", "None"),
|
"transifex_language": payload.get("language", "None"),
|
||||||
PeterSurda
commented
if you use if you use `.get` with a default value, you can avoid `try`/`except`
|
|||||||
"transifex_event": payload.get("event", "None"),
|
"transifex_event": payload.get("event", "None"),
|
||||||
PeterSurda
commented
`language = payload.get('language', "None")`
|
|||||||
"transifex_project": payload.get("project", "None"),
|
"transifex_project": payload.get("project", "None"),
|
||||||
PeterSurda
commented
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"),
|
"transifex_resource": payload.get("resource", "None"),
|
||||||
PeterSurda marked this conversation as resolved
Outdated
PeterSurda
commented
This should be in the buildbot job, not here. The webhook only transforms data structures and puts them into a database.
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
PeterSurda
commented
this line ( this line (`'resource': ...`) should be remove
|
|||||||
"transifex_branch": "v0.6"
|
"transifex_branch": "translate_" + payload['language'] + "_" + str(ts)
|
||||||
PeterSurda
commented
something like something like `translated_request` or `mapped_request` would be more understandable. There is not response coming from transifex.
|
|||||||
}
|
}
|
||||||
PeterSurda
commented
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:
|
if codebase is not None:
|
||||||
|
@ -83,10 +85,10 @@ class TransifexHandler(BaseHookHandler):
|
||||||
changes.insert(0, change)
|
changes.insert(0, change)
|
||||||
return changes
|
return changes
|
||||||
PeterSurda
commented
this is a sub-property this is a sub-property
|
|||||||
|
|
||||||
PeterSurda
commented
from map from map
|
|||||||
def _transform_variables(self, transifex_project, transifex_resource):
|
def _transform_variables(self, transifex_project):
|
||||||
PeterSurda
commented
- no need super
- needs `master`
- doesn't save `transifex_dict`
- `secret` also missing
PeterSurda
commented
from map from map
|
|||||||
if transifex_project is None:
|
if transifex_project is None:
|
||||||
raise ValueError("Unknown project %s from transifex".format(transifex_project))
|
raise ValueError("Unknown project %s from transifex".format(transifex_project))
|
||||||
key = "{}/{}".format(transifex_project, transifex_resource)
|
key = transifex_project
|
||||||
_map = self.map[key]
|
_map = self.map[key]
|
||||||
repository = _map["repository"]
|
repository = _map["repository"]
|
||||||
project = re.sub(r'^.*/(.*?)(\.git)?$', r'\1', repository)
|
project = re.sub(r'^.*/(.*?)(\.git)?$', r'\1', repository)
|
||||||
|
@ -122,16 +124,6 @@ class TransifexHandler(BaseHookHandler):
|
||||||
request.getHeader(_HEADER_SIGNATURE))
|
request.getHeader(_HEADER_SIGNATURE))
|
||||||
self._verifyTransifexSignature(request, content, rendered_secret, signature, header_signature)
|
self._verifyTransifexSignature(request, content, rendered_secret, signature, header_signature)
|
||||||
event_type = payload.get("event", "None")
|
event_type = payload.get("event", "None")
|
||||||
PeterSurda
commented
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))
|
log.msg("Received event '{}' from transifex".format(event_type))
|
||||||
|
|
||||||
codebase = ""
|
codebase = ""
|
||||||
PeterSurda
commented
since we're raising inside the since we're raising inside the `_verifyTransifexSignature`, no need for `if` here anymore
|
|||||||
|
|
maybe just
raise ValueError("Signature mismatch")
, then it will propagate up