Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Jérome Perrin
erp5
Commits
60532d2e
Commit
60532d2e
authored
Feb 20, 2015
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Work in progress web hook to run tests on a merge request
parent
5749f190
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
159 additions
and
0 deletions
+159
-0
bt5/erp5_test_result/SkinTemplateItem/portal_skins/erp5_test_result/ERP5Site_getGitlabWebHook.xml
...rtal_skins/erp5_test_result/ERP5Site_getGitlabWebHook.xml
+159
-0
No files found.
bt5/erp5_test_result/SkinTemplateItem/portal_skins/erp5_test_result/ERP5Site_getGitlabWebHook.xml
0 → 100644
View file @
60532d2e
<?xml version="1.0"?>
<ZopeData>
<record
id=
"1"
aka=
"AAAAAAAAAAE="
>
<pickle>
<global
name=
"PythonScript"
module=
"Products.PythonScripts.PythonScript"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
Script_magic
</string>
</key>
<value>
<int>
3
</int>
</value>
</item>
<item>
<key>
<string>
_bind_names
</string>
</key>
<value>
<object>
<klass>
<global
name=
"NameAssignments"
module=
"Shared.DC.Scripts.Bindings"
/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key>
<string>
_asgns
</string>
</key>
<value>
<dictionary>
<item>
<key>
<string>
name_container
</string>
</key>
<value>
<string>
container
</string>
</value>
</item>
<item>
<key>
<string>
name_context
</string>
</key>
<value>
<string>
context
</string>
</value>
</item>
<item>
<key>
<string>
name_m_self
</string>
</key>
<value>
<string>
script
</string>
</value>
</item>
<item>
<key>
<string>
name_subpath
</string>
</key>
<value>
<string>
traverse_subpath
</string>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key>
<string>
_body
</string>
</key>
<value>
<string
encoding=
"cdata"
>
<![CDATA[
"""Endpoint for gitlab merge requests web hook\n
\n
TODO:\n
invalidate test suite after run\n
post a message on gitlab\n
where to define custom parameters ?\n
cleanup aferClone\n
"""\n
\n
import json\n
\n
portal = context.getPortalObject()\n
request = container.REQUEST\n
received_body = request[\'BODY\']\n
body = json.loads(received_body)\n
\n
from pprint import pformat\n
context.log("received gitlab web hook", pformat(body))\n
\n
assert body[\'object_kind\'] == \'merge_request\'\n
\n
# gitlab does not send the merge request URL, but we can easily guess it from repository http url\n
# http://gitlab/user/project.git ->
http://gitlab/user/project/merge_requests/{id}\n
merge_request_url = \'%s/merge_requests/%s\' % (\n
body[\'object_attributes\'][\'source\'][\'http_url\'][:-4],\n
body[\'object_attributes\'][\'id\'] )\n
\n
# same thing for the gitlab API to add a note\n
# POST /projects/:id/merge_requests/:merge_request_id/notes\n
scheme = merge_request_url.split(\':\')[0]\n
host = merge_request_url.replace(\'%s://\' % scheme, \'\', 1).split(\'/\')[0]\n
add_note_api_url = \'%s://%s/api/v3/projects/%s/merge_requests/%s/notes\' % (\n
scheme,\n
host,\n
body[\'object_attributes\'][\'source_project_id\'],\n
body[\'object_attributes\'][\'id\'])\n
\n
# To add a note :\n
# curl -X POST -d body=ahaha -H PRIVATE-TOKEN:oxUWj1uxWsMCGGMaxBu7 http://localhost:10080/api/v3/projects/9/merge_requests/4/notes\n
\n
\n
# We should only accept merge requests from our official gitlab mirror\n
# assert body[\'object_attributes\'][\'source\'][\'http_url\'] == ""\n
\n
\n
if portal.portal_catalog(portal_type=\'Test Suite\',\n
validation_state=\'validated\',\n
source_reference=merge_request_url):\n
context.log("Test suite already created")\n
return\n
\n
test_suite = portal.test_suite_module.newContent(\n
portal_type=\'Test Suite\',\n
title=\'ERP5 - %s \' % body[\'object_attributes\'][\'title\'],\n
test_suite=\'ERP5\', # XXX customize\n
source_project=\'project_module/7\', # XXX customize\n
specialise=\'portal_task_distribution/erp5_project\',\n
source_reference=merge_request_url,\n
destination_reference=add_note_api_url,\n
description="Created from Merge Request: %s\\n%s" % ( merge_request_url, body[\'object_attributes\'][\'description\']),\n
received_body=received_body # XXX this can help troubleshouting\n
)\n
\n
# ERP5 test suite needs to clone slapos, because ERP5\'s software.cfg is in slapos.git\n
test_suite.newContent(\n
portal_type=\'Test Suite Repository\',\n
profile_path=\'software/erp5/software.cfg\',\n
git_url=\'http://git.erp5.org/repos/slapos.git\',\n
branch=\'erp5\',\n
)\n
\n
test_suite.newContent(\n
portal_type=\'Test Suite Repository\',\n
git_url=body[\'object_attributes\'][\'source\'][\'http_url\'],\n
buildout_section_id=\'erp5\', # XXX customize\n
branch=body[\'object_attributes\'][\'source_branch\']\n
)\n
\n
test_suite.validate()\n
\n
return\n
]]>
</string>
</value>
</item>
<item>
<key>
<string>
_params
</string>
</key>
<value>
<string></string>
</value>
</item>
<item>
<key>
<string>
_proxy_roles
</string>
</key>
<value>
<tuple>
<string>
Manager
</string>
</tuple>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
ERP5Site_getGitlabWebHook
</string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment