Update webhook and setup
This commit is contained in:
parent
5885c8cbbe
commit
f2587e071d
|
@ -16,16 +16,87 @@ _HEADER_USER_AGENT = 'User-Agent'
|
||||||
_HEADER_SIGNATURE = 'X-TX-Signature'
|
_HEADER_SIGNATURE = 'X-TX-Signature'
|
||||||
_EVENT_KEY = 'event'
|
_EVENT_KEY = 'event'
|
||||||
|
|
||||||
|
|
||||||
class TransifexHandler(BaseHookHandler):
|
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):
|
def process_translation_completed(self, payload, event_type, codebase):
|
||||||
refname = payload["ref"]
|
refname = payload["ref"]
|
||||||
|
|
||||||
changes = []
|
changes = []
|
||||||
|
|
||||||
# We only care about regular heads or tags
|
# We only care about regular heads or tags
|
||||||
match = re.match(r"^refs/(heads|tags)/(.+)$", refname)
|
match = re.match(r"^refs/(heads|tags)/(.+)$", refname)
|
||||||
|
if event_type == 'translation_completed':
|
||||||
|
pass
|
||||||
|
|
||||||
if not match:
|
if not match:
|
||||||
log.msg("Ignoring refname '{}': Not a branch or tag".format(refname))
|
log.msg("Ignoring refname '{}': Not a branch or tag".format(refname))
|
||||||
return changes
|
return changes
|
||||||
|
@ -68,36 +139,37 @@ class TransifexHandler(BaseHookHandler):
|
||||||
changes.insert(0, change)
|
changes.insert(0, change)
|
||||||
return changes
|
return changes
|
||||||
|
|
||||||
def process_review_compoleted(self, payload, event_type, codebase):
|
def process_review_completed(self, payload, event_type, codebase):
|
||||||
action = payload['action']
|
action = payload['action']
|
||||||
|
if event_type == 'review_completed':
|
||||||
|
pass
|
||||||
# Only handle potential new stuff, ignore close/.
|
# Only handle potential new stuff, ignore close/.
|
||||||
# Merge itself is handled by the regular branch push message
|
# Merge itself is handled by the regular branch push message
|
||||||
if action not in ['opened', 'synchronized', 'edited', 'reopened']:
|
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 []
|
return []
|
||||||
pull_request = payload['pull_request']
|
# pull_request = payload['pull_request']
|
||||||
if not pull_request['mergeable']:
|
# if not pull_request['mergeable']:
|
||||||
log.msg("Gitea Pull Request ignored because it is not mergeable.")
|
# log.msg("Transifex Pull Request ignored because it is not mergeable.")
|
||||||
return []
|
# return []
|
||||||
if pull_request['merged']:
|
# if pull_request['merged']:
|
||||||
log.msg("Gitea Pull Request ignored because it is already merged.")
|
# log.msg("Transifex Pull Request ignored because it is already merged.")
|
||||||
return []
|
# return []
|
||||||
timestamp = dateparse(pull_request['updated_at'])
|
# timestamp = dateparse(pull_request['updated_at'])
|
||||||
base = pull_request['base']
|
# base = pull_request['base']
|
||||||
head = pull_request['head']
|
# head = pull_request['head']
|
||||||
repository = payload['repository']
|
repository = payload['repository']
|
||||||
change = {
|
change = {
|
||||||
'author': '{} <{}>'.format(pull_request['user']['full_name'],
|
'author': '{} <{}>'.format(pull_request['user']['full_name'],
|
||||||
pull_request['user']['email']),
|
pull_request['user']['email']),
|
||||||
'comments': 'PR#{}: {}\n\n{}'.format(
|
# 'comments': 'PR#{}: {}\n\n{}'.format(
|
||||||
pull_request['number'],
|
# pull_request['number'],
|
||||||
pull_request['title'],
|
# pull_request['title'],
|
||||||
pull_request['body']),
|
# pull_request['body']),
|
||||||
'revision': base['sha'],
|
'revision': base['sha'],
|
||||||
'when_timestamp': timestamp,
|
'when_timestamp': timestamp,
|
||||||
'branch': base['ref'],
|
'branch': base['ref'],
|
||||||
'revlink': pull_request['html_url'],
|
# 'revlink': pull_request['html_url'],
|
||||||
'repository': base['repo']['ssh_url'],
|
'repository': base['repo']['ssh_url'],
|
||||||
'project': repository['full_name'],
|
'project': repository['full_name'],
|
||||||
'category': event_type,
|
'category': event_type,
|
||||||
|
@ -115,8 +187,8 @@ class TransifexHandler(BaseHookHandler):
|
||||||
'head_git_ssh_url': head['repo']['ssh_url'],
|
'head_git_ssh_url': head['repo']['ssh_url'],
|
||||||
'head_owner': head['repo']['owner']['username'],
|
'head_owner': head['repo']['owner']['username'],
|
||||||
'head_reponame': head['repo']['name'],
|
'head_reponame': head['repo']['name'],
|
||||||
'pr_id': pull_request['id'],
|
# 'pr_id': pull_request['id'],
|
||||||
'pr_number': pull_request['number'],
|
# 'pr_number': pull_request['number'],
|
||||||
'repository_name': repository['name'],
|
'repository_name': repository['name'],
|
||||||
'owner': repository["owner"]["username"],
|
'owner': repository["owner"]["username"],
|
||||||
},
|
},
|
||||||
|
@ -189,5 +261,4 @@ class TransifexHandler(BaseHookHandler):
|
||||||
return (changes, 'transifex')
|
return (changes, 'transifex')
|
||||||
|
|
||||||
|
|
||||||
# Plugin name
|
transifex = TransifexHandler(transifex_dict)
|
||||||
transifex = TransifexHandler
|
|
||||||
|
|
27
setup.py
27
setup.py
|
@ -6,32 +6,23 @@ from setuptools import setup
|
||||||
with open("README.md", "r") as fh:
|
with open("README.md", "r") as fh:
|
||||||
long_description = fh.read()
|
long_description = fh.read()
|
||||||
|
|
||||||
VERSION = "1.7.2"
|
VERSION = "0.1"
|
||||||
|
|
||||||
setup(name='buildbot-gitea',
|
setup(name='buildbot-transifex',
|
||||||
version=VERSION,
|
version=VERSION,
|
||||||
description='buildbot plugin for integration with Gitea.',
|
description='buildbot plugin for integration with transifex.',
|
||||||
author='Marvin Pohl',
|
author='',
|
||||||
author_email='hello@lab132.com',
|
author_email='',
|
||||||
url='https://github.com/lab132/buildbot-gitea',
|
url='',
|
||||||
long_description=long_description,
|
long_description='Transifex webhook',
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
packages=['buildbot_gitea'],
|
packages=['buildbot_transifex'],
|
||||||
install_requires=[
|
install_requires=[
|
||||||
"buildbot>=3.0.0"
|
"buildbot>=3.0.0"
|
||||||
],
|
],
|
||||||
entry_points={
|
entry_points={
|
||||||
"buildbot.webhooks": [
|
"buildbot.webhooks": [
|
||||||
"gitea = buildbot_gitea.webhook:gitea"
|
"transifex = buildbot_transifex.webhook:transifex"
|
||||||
],
|
|
||||||
"buildbot.steps": [
|
|
||||||
"Gitea = buildbot_gitea.step_source:Gitea"
|
|
||||||
],
|
|
||||||
"buildbot.reporters": [
|
|
||||||
"GiteaStatusPush = buildbot_gitea.reporter:GiteaStatusPush"
|
|
||||||
],
|
|
||||||
"buildbot.util": [
|
|
||||||
"GiteaAuth = buildbot_gitea.auth:GiteaAuth"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
classifiers=[
|
classifiers=[
|
||||||
|
|
Loading…
Reference in New Issue
Block a user