Update webhook and setup #1
No reviewers
Labels
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: Bitmessage/buildbot-transifex#1
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "shekhar-cis/buildbot-transifex:transifex-webhook"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Remove gitea and add transifex, update setup and webhook.py
4f412af6d9
tof2587e071d
@ -22,0 +85,4 @@
# debug("Unknown command %s" % (environ.get("HTTP_X_GITHUB_EVENT")))
# output, responseHeaders = returnMessage(True, "Unknown command, ignoring")
def __init__(self, transifex_dict=None):
super(TransifexHandler, self).__init__(*args, **kwargs)
master
transifex_dict
secret
also missing@ -74,3 +145,4 @@
pass
# Only handle potential new stuff, ignore close/.
# Merge itself is handled by the regular branch push message
if action not in ['opened', 'synchronized', 'edited', 'reopened']:
this is github syntax, needs to be translated into transifex syntax, maybe even ignored as transifex may not have this kind of variable
@ -89,2 +159,4 @@
# base = pull_request['base']
# head = pull_request['head']
repository = payload['repository']
change = {
@ -8,30 +8,21 @@ with open("README.md", "r") as fh:
VERSION = "1.7.2"
change version, say 0.1
@ -16,2 +13,2 @@
url='https://github.com/lab132/buildbot-gitea',
long_description=long_description,
description='buildbot plugin for integration with transifex.',
author='',
should fill out
f0f715b342
to4b38bcc252
@ -13,3 +24,3 @@
from dateutil.parser import parse as dateparse
_HEADER_USER_AGENT = 'User-Agent'
HTTP_USER_AGENT = 'User-Agent'
why?
@ -16,3 +27,3 @@
_HEADER_SIGNATURE = 'X-TX-Signature'
_EVENT_KEY = 'event'
branch = 'v0.6'
should be inside the map
@ -17,2 +28,3 @@
_EVENT_KEY = 'event'
branch = 'v0.6'
transifexSecret = ""
should be arguments passed to constructor
@ -19,0 +30,4 @@
transifexSecret = ""
transifexUsername = ""
transifexPassword = ""
transifex_webhook_url = 'https://buildbot.bitmessage.org/change_hook/transifex'
should be extracted from properties or buildbot runtime variables
@ -30,2 +107,2 @@
log.msg("Ignoring refname '{}': Not a branch or tag".format(refname))
return changes
# match = re.match(r"^refs/(heads|tags)/(.+)$", refname)
if "Transifex" in os.environ.get("HTTP_USER_AGENT"):
4b38bcc252
to1e92388b78
1e92388b78
to1b29a5639c
@ -1,8 +1,19 @@
import sys
isort
@ -15,129 +26,157 @@ from dateutil.parser import parse as dateparse
_HEADER_USER_AGENT = 'User-Agent'
_HEADER_SIGNATURE = 'X-TX-Signature'
_EVENT_KEY = 'event'
transifexSecret = ""
we don't need any of this
@ -18,1 +33,4 @@
secret = ""
master = ""
gitHubToken = os.environ('gitHubToken')
no
@ -24,0 +46,4 @@
def returnMessage(self, status = False, message = "Unimplemented"):
output = json.dumps({"status": "OK" if status else "FAIL", "message": message})
return [output, [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))
application/json
@ -24,0 +50,4 @@
]]
def verifyTransifexSignature(
self, request, content, rendered_secret, signature, header_signature
rendered_secret can be extracted directly, no need to pass it
@ -24,0 +53,4 @@
self, request, content, rendered_secret, signature, header_signature
):
http_verb = 'POST'
http_url_path = request.headers('X-TX-Url')
should use constant
@ -24,0 +54,4 @@
):
http_verb = 'POST'
http_url_path = request.headers('X-TX-Url')
http_gmt_date = request.headers('Date')
here also
@ -24,0 +66,4 @@
digestmod=hashlib.sha256
).digest()
)
if tx_signature() != header_signature:
tx_signature
isn't a function/method@ -24,0 +67,4 @@
).digest()
)
if tx_signature() != header_signature:
raise ValueError('Invalid secret')
return False
@ -24,0 +70,4 @@
raise ValueError('Invalid secret')
try:
if signature != os.environ.get('HTTP_X_TX_SIGNATURE'):
@ -24,0 +76,4 @@
except:
return False
def downloadTranslatedLanguage(self, ts, lang):
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@ -133,0 +162,4 @@
def _transform_variables(self, payload, transifex_dict):
transifex_variables = {
Probably something like:
@ -145,34 +184,20 @@ class TransifexHandler(BaseHookHandler):
except Exception as exception:
raise ValueError('Error loading JSON: ' + str(exception))
@ -174,4 +201,2 @@
if tx_signature() != header_signature:
raise ValueError('Invalid secret')
event_type = bytes2unicode(payload.get(_EVENT_KEY), "None")
maybe we don't need(leftover from gitea hook)bytes2unicode
?@ -175,4 +201,3 @@
raise ValueError('Invalid secret')
event_type = bytes2unicode(payload.get(_EVENT_KEY), "None")
log.msg("Received event '{}' from transifex".format(event_type))
project
can be extracted fromrepository
(is a substring)revision
let's ignore it for nowbranch
is in the map, just likerepository
43d59d537b
to89305ec602
@ -25,0 +42,4 @@
output = json.dumps({"status": "OK" if status else "FAIL", "message": message})
return [output, [('Content-type', 'application/json')]]
def verifyTransifexSignature(
_verifyTransifexSignature
@ -25,0 +64,4 @@
if signature != request.getHeader(_HEADER_SIGNATURE):
return False
return True
missing@ -88,2 +70,2 @@
head = pull_request['head']
repository = payload['repository']
transifex_response = self._transform_variables(payload, transifex_dict)
if 'pybitmessage-test' in transifex_response['project'] and 'messagespot' in transifex_response['resource']:
don't have weird constants here, rather process is through the map.
@ -90,0 +71,4 @@
if 'pybitmessage-test' in transifex_response['project'] and 'messagespot' in transifex_response['resource']:
if 'translation_completed' in transifex_response['event']:
ts = int(time.time())
lang = transifex_response['language']
error handling missing here
@ -102,2 +85,2 @@
'project': repository['full_name'],
'category': event_type,
'author': 'buildbot-transifex,
'resource': transifex_response['resource'],
this is a sub-property
@ -103,1 +85,3 @@
'category': event_type,
'author': 'buildbot-transifex,
'resource': transifex_response['resource'],
'branch': transifex_dict['branch'],
from map
@ -104,0 +85,4 @@
'author': 'buildbot-transifex,
'resource': transifex_response['resource'],
'branch': transifex_dict['branch'],
'project': transifex_response['project'],
from map
@ -178,0 +143,4 @@
project = payload.get("project", 'None')
resource = payload.get("resource", 'None')
transifex_request_data['branch'] = "v0.6"
from the map
@ -178,0 +145,4 @@
transifex_request_data['branch'] = "v0.6"
transifex_request_data['revision'] = ""
transifex_request_data["properties"] = "langugage"
@ -189,5 +214,4 @@ class TransifexHandler(BaseHookHandler):
return (changes, 'transifex')
Additional properties needed:
language
resource
transifex_branch
(for PR)@ -16,2 +13,2 @@
url='https://github.com/lab132/buildbot-gitea',
long_description=long_description,
description='buildbot plugin for integration with transifex.',
author='',
author
andauthor-email
should represent someone who can be in theory contacted for more information.url
is where the plugin can be downloaded from@ -15,2 +23,4 @@
_HEADER_USER_AGENT = 'User-Agent'
_HEADER_SIGNATURE = 'X-TX-Signature'
_HEADER_URL_PATH = 'X-TX-Url'
HTTP_DATE = 'date'
_HEADER_DATE
@ -17,1 +25,4 @@
_HEADER_URL_PATH = 'X-TX-Url'
HTTP_DATE = 'date'
_EVENT_KEY = 'event'
transifex_request_data = {}
This is specific to a request so it shouldn't be a module variable. Wrong scope. At the very least, if there are multiple requests in parallel, this will cause collisions.
@ -25,0 +36,4 @@
self.secret = secret
self.master = master
self.options = options
self.transifex_dict = transifex_dict
something like
transifex_to_github_map
is a better name@ -26,0 +73,4 @@
# if 'pybitmessage-test' in transifex_response['project'] and 'messagespot' in transifex_response['resource']:
# if 'translation_completed' in transifex_response['event']:
try:
lang = transifex_response['language']
if you use
.get
with a default value, you can avoidtry
/except
@ -133,0 +99,4 @@
def _transform_variables(self, payload, transifex_dict):
project = payload.get('project', 'None')
transform_values = {
project: {
this shouldn't be here
@ -170,3 +132,1 @@
msg=msg,
digestmod=hashlib.sha256
).digest()
self._verifyTransifexSignature(
we're not doing anything with the return value of the verification
@ -178,0 +139,4 @@
project = payload.get("project", 'None')
resource = payload.get("resource", 'None')
transifex_request_data['branch'] = transifex_dict['branch']
we shouldn't be modifying
request_data
, that's inputdbf00e0ed5
to1a54f3b81d
@ -23,2 +33,3 @@
refname = payload["ref"]
class TransifexHandler(BaseHookHandler):
def __init__(self, master, secret, options, transifex_to_github_map):
options
should probably be the last and default toNone
or something@ -25,0 +69,4 @@
return False
return True
def process_translation_completed(self, payload, transifex_to_github_map, event_type, codebase):
transifex_to_github_map
is an object attribute, no need to pass it around@ -26,0 +74,4 @@
transifex_response = self._transform_variables(payload, transifex_to_github_map)
# if 'pybitmessage-test' in transifex_response['project'] and 'messagespot' in transifex_response['resource']:
# if 'translation_completed' in transifex_response['event']:
language = transifex_response.get['language']
language = payload.get('language', "None")
@ -102,2 +80,2 @@
'project': repository['full_name'],
'category': event_type,
'author': "buildbot-transifex",
'resource': transifex_to_github_map["resource"],
not translating anything. There is nothing here that translates transifex payload information into github information.
@ -175,3 +131,1 @@
raise ValueError('Invalid secret')
event_type = bytes2unicode(payload.get(_EVENT_KEY), "None")
if not self._verifyTransifexSignature(request, content, self.rendered_secret, signature, header_signature):
this is incomplete, we shouldn't proceed if the verification fails
@ -178,0 +144,4 @@
change["changes"] = {
"author": "buildbot-transifex",
"repository": transifex_to_github_map['repository'],
not doing anything useful
1a54f3b81d
to23931cf91f
@ -6,0 +7,4 @@
import requests
import time
import logging
no need
logging
no need for
logging
@ -6,0 +10,4 @@
import logging
from subprocess import call
from base64 import b64encode
we already imported base64
@ -25,0 +63,4 @@
).digest()
)
if tx_signature != header_signature:
return False
maybe just
raise ValueError("Signature mismatch")
, then it will propagate up@ -102,2 +78,2 @@
'project': repository['full_name'],
'category': event_type,
'author': "buildbot-transifex",
'resource': transifex_response[resource],
this line (
'resource': ...
) should be remove@ -103,1 +78,3 @@
'category': event_type,
'author': "buildbot-transifex",
'resource': transifex_response[resource],
'branch': transifex_response["branch"],
something like
translated_request
ormapped_request
would be more understandable. There is not response coming from transifex.@ -132,1 +94,3 @@
branch = payload.get('language')
def _transform_variables(self, transifex_project, transifex_resource):
key = "{}/{}".format(transifex_project, transifex_resource)
_map = self.map[key]
maybe add error handling, e.g.
raise ValueError("Unknown project %s from transifex".format(transifex_project)"
@ -133,0 +95,4 @@
key = "{}/{}".format(transifex_project, transifex_resource)
_map = self.map[key]
repository = _map["repository"]
project = transifex_project
missing functionality, the project should be extracted from the
repository
variable@ -151,2 +120,3 @@
p.master = self.master
rendered_secret = yield p.render(secret)
option = self.options
self.rendered_secret = yield p.render(self.secret)
we can just use
rendered_secret
, notself.rendered_secret
@ -175,3 +129,1 @@
raise ValueError('Invalid secret')
event_type = bytes2unicode(payload.get(_EVENT_KEY), "None")
if not self._verifyTransifexSignature(request, content, self.rendered_secret, signature, header_signature):
since we're raising inside the
_verifyTransifexSignature
, no need forif
here anymore@ -178,0 +134,4 @@
event_type = payload.get("event", "None")
change["properties"] = {
duplicate
@ -178,0 +140,4 @@
"transifex_project": payload.get("project", "None"),
"transifex_resource": payload.get("resource", "None")
}
transiform_map = self._transform_variables(payload['project'], payload['resource'])
maybe
mapped_request
@ -178,0 +143,4 @@
transiform_map = self._transform_variables(payload['project'], payload['resource'])
change["changes"] = {
"author": "buildbot-transifex",
maybe make
"buildbot-transifex
" a class variable or a module variable?transifex_branch
missing23931cf91f
to4ecb3b9cb9
4ecb3b9cb9
toab6d1083ec
@ -102,2 +70,2 @@
'project': repository['full_name'],
'category': event_type,
'author': "buildbot-transifex",
'branch': translated_request["branch"],
repository
missing@ -123,0 +75,4 @@
"transifex_event": payload.get("event", "None"),
"transifex_project": payload.get("project", "None"),
"transifex_resource": payload.get("resource", "None"),
"transifex_branch": "v0.6"
this should be the randomly generated one, the branch of the PR
@ -178,0 +123,4 @@
self._verifyTransifexSignature(request, content, rendered_secret, signature, header_signature)
event_type = payload.get("event", "None")
mapped_request = self._transform_variables(payload['project'], payload['resource'])
duplicate
now only minor changes left
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Gitea.