Update webhook and setup
This commit is contained in:
parent
5885c8cbbe
commit
f2587e071d
|
@ -16,9 +16,77 @@ _HEADER_USER_AGENT = 'User-Agent'
|
|||
_HEADER_SIGNATURE = 'X-TX-Signature'
|
||||
_EVENT_KEY = 'event'
|
||||
|
||||
|
||||
class TransifexHandler(BaseHookHandler):
|
||||
|
||||
# def verifyGitHubSignature (environ, payload_body):
|
||||
# signature = 'sha1=' + hmac.new(gitHubSecret, payload_body, sha1).hexdigest()
|
||||
# try:
|
||||
# if signature != environ.get('X-TX-Signature'):
|
||||
# return False
|
||||
# return True
|
||||
# except:
|
||||
# return False
|
||||
|
||||
# def verifyTransifexSignature (environ, payload_body):
|
||||
# signature = b64encode(hmac.new(transifexSecret, payload_body, sha1).digest())
|
||||
# try:
|
||||
# debug(signature)
|
||||
# if signature != environ.get('HTTP_X_TX_SIGNATURE'):
|
||||
# return False
|
||||
# return True
|
||||
# except:
|
||||
# return False
|
||||
|
||||
# def returnMessage(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)))
|
||||
# ]]
|
||||
|
||||
# def application(environ, start_response):
|
||||
# status = '200 OK'
|
||||
# output = ''
|
||||
# lockWait()
|
||||
# length = int(environ.get('CONTENT_LENGTH', '0'))
|
||||
# body = environ['wsgi.input'].read(length)
|
||||
|
||||
# if "Transifex" in environ.get("HTTP_USER_AGENT"):
|
||||
# # debug(environ)
|
||||
# # debug(body)
|
||||
# if not verifyTransifexSignature(environ, body):
|
||||
# debug ("Verify Transifex Signature fail, but fuck them")
|
||||
# else:
|
||||
# debug ("Verify Transifex Signature ok")
|
||||
# # output, responseHeaders = returnMessage(False, "Checksum bad")
|
||||
# # start_response(status, responseHeaders)
|
||||
# # unlock()
|
||||
# # return [output]
|
||||
# try:
|
||||
# # debug(body)
|
||||
# payload = parse_qs(body)
|
||||
# # debug(payload)
|
||||
# if 'pybitmessage' in payload['project'] and 'pybitmessage' in payload['resource']:
|
||||
# if 'translated' in payload and '100' in payload['translated']:
|
||||
# ts = int(time.time())
|
||||
# updateLocalTranslationDestination(ts, payload['language'][0].lower())
|
||||
# downloadTranslatedLanguage(ts, payload['language'][0])
|
||||
# response = commitTranslatedLanguage(ts, payload['language'][0].lower())
|
||||
# if response.ok:
|
||||
# output, responseHeaders = returnMessage(True, "Processed.")
|
||||
# else:
|
||||
# output, responseHeaders = returnMessage(False, "Error: %i." % (response.status_code))
|
||||
# else:
|
||||
# output, responseHeaders = returnMessage(False, "Nothing to do")
|
||||
# else:
|
||||
# output, responseHeaders = returnMessage(False, "Nothing to do")
|
||||
# except:
|
||||
# output, responseHeaders = returnMessage(True, "Not processing")
|
||||
# else:
|
||||
# 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)
|
||||
|
||||
def process_translation_completed(self, payload, event_type, codebase):
|
||||
refname = payload["ref"]
|
||||
|
||||
|
@ -26,6 +94,9 @@ class TransifexHandler(BaseHookHandler):
|
|||
|
||||
# We only care about regular heads or tags
|
||||
match = re.match(r"^refs/(heads|tags)/(.+)$", refname)
|
||||
if event_type == 'translation_completed':
|
||||
pass
|
||||
|
||||
if not match:
|
||||
log.msg("Ignoring refname '{}': Not a branch or tag".format(refname))
|
||||
return changes
|
||||
|
@ -68,36 +139,37 @@ class TransifexHandler(BaseHookHandler):
|
|||
changes.insert(0, change)
|
||||
return changes
|
||||
|
||||
def process_review_compoleted(self, payload, event_type, codebase):
|
||||
def process_review_completed(self, payload, event_type, codebase):
|
||||
action = payload['action']
|
||||
|
||||
if event_type == 'review_completed':
|
||||
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']:
|
||||
log.msg("Gitea Pull Request event '{}' ignored".format(action))
|
||||
log.msg("Transifex Pull Request event '{}' ignored".format(action))
|
||||
return []
|
||||
pull_request = payload['pull_request']
|
||||
if not pull_request['mergeable']:
|
||||
log.msg("Gitea Pull Request ignored because it is not mergeable.")
|
||||
return []
|
||||
if pull_request['merged']:
|
||||
log.msg("Gitea Pull Request ignored because it is already merged.")
|
||||
return []
|
||||
timestamp = dateparse(pull_request['updated_at'])
|
||||
base = pull_request['base']
|
||||
head = pull_request['head']
|
||||
# pull_request = payload['pull_request']
|
||||
# if not pull_request['mergeable']:
|
||||
# log.msg("Transifex Pull Request ignored because it is not mergeable.")
|
||||
# return []
|
||||
# if pull_request['merged']:
|
||||
# log.msg("Transifex Pull Request ignored because it is already merged.")
|
||||
# return []
|
||||
# timestamp = dateparse(pull_request['updated_at'])
|
||||
# base = pull_request['base']
|
||||
# head = pull_request['head']
|
||||
repository = payload['repository']
|
||||
change = {
|
||||
'author': '{} <{}>'.format(pull_request['user']['full_name'],
|
||||
pull_request['user']['email']),
|
||||
'comments': 'PR#{}: {}\n\n{}'.format(
|
||||
pull_request['number'],
|
||||
pull_request['title'],
|
||||
pull_request['body']),
|
||||
# 'comments': 'PR#{}: {}\n\n{}'.format(
|
||||
# pull_request['number'],
|
||||
# pull_request['title'],
|
||||
# pull_request['body']),
|
||||
'revision': base['sha'],
|
||||
'when_timestamp': timestamp,
|
||||
'branch': base['ref'],
|
||||
'revlink': pull_request['html_url'],
|
||||
# 'revlink': pull_request['html_url'],
|
||||
'repository': base['repo']['ssh_url'],
|
||||
'project': repository['full_name'],
|
||||
'category': event_type,
|
||||
|
@ -115,8 +187,8 @@ class TransifexHandler(BaseHookHandler):
|
|||
'head_git_ssh_url': head['repo']['ssh_url'],
|
||||
'head_owner': head['repo']['owner']['username'],
|
||||
'head_reponame': head['repo']['name'],
|
||||
'pr_id': pull_request['id'],
|
||||
'pr_number': pull_request['number'],
|
||||
# 'pr_id': pull_request['id'],
|
||||
# 'pr_number': pull_request['number'],
|
||||
'repository_name': repository['name'],
|
||||
'owner': repository["owner"]["username"],
|
||||
},
|
||||
|
@ -189,5 +261,4 @@ class TransifexHandler(BaseHookHandler):
|
|||
return (changes, 'transifex')
|
||||
|
||||
|
||||
# Plugin name
|
||||
transifex = TransifexHandler
|
||||
transifex = TransifexHandler(transifex_dict)
|
||||
|
|
27
setup.py
27
setup.py
|
@ -6,32 +6,23 @@ from setuptools import setup
|
|||
with open("README.md", "r") as fh:
|
||||
long_description = fh.read()
|
||||
|
||||
VERSION = "1.7.2"
|
||||
VERSION = "0.1"
|
||||
|
||||
setup(name='buildbot-gitea',
|
||||
setup(name='buildbot-transifex',
|
||||
version=VERSION,
|
||||
description='buildbot plugin for integration with Gitea.',
|
||||
author='Marvin Pohl',
|
||||
author_email='hello@lab132.com',
|
||||
url='https://github.com/lab132/buildbot-gitea',
|
||||
long_description=long_description,
|
||||
description='buildbot plugin for integration with transifex.',
|
||||
author='',
|
||||
author_email='',
|
||||
url='',
|
||||
long_description='Transifex webhook',
|
||||
long_description_content_type="text/markdown",
|
||||
packages=['buildbot_gitea'],
|
||||
packages=['buildbot_transifex'],
|
||||
install_requires=[
|
||||
"buildbot>=3.0.0"
|
||||
],
|
||||
entry_points={
|
||||
"buildbot.webhooks": [
|
||||
"gitea = buildbot_gitea.webhook:gitea"
|
||||
],
|
||||
"buildbot.steps": [
|
||||
"Gitea = buildbot_gitea.step_source:Gitea"
|
||||
],
|
||||
"buildbot.reporters": [
|
||||
"GiteaStatusPush = buildbot_gitea.reporter:GiteaStatusPush"
|
||||
],
|
||||
"buildbot.util": [
|
||||
"GiteaAuth = buildbot_gitea.auth:GiteaAuth"
|
||||
"transifex = buildbot_transifex.webhook:transifex"
|
||||
]
|
||||
},
|
||||
classifiers=[
|
||||
|
|
Loading…
Reference in New Issue
Block a user