Merge pull request #1906 from coreos-inc/gitlab-bug
Gitlab trigger payload bug fixes
This commit is contained in:
commit
2d9ce6dbe3
4 changed files with 209 additions and 7 deletions
|
@ -8,8 +8,20 @@ from buildtrigger.bitbuckethandler import get_transformed_webhook_payload as bb_
|
|||
from buildtrigger.bitbuckethandler import get_transformed_commit_info as bb_commit
|
||||
from buildtrigger.githubhandler import get_transformed_webhook_payload as gh_webhook
|
||||
from buildtrigger.gitlabhandler import get_transformed_webhook_payload as gl_webhook
|
||||
from buildtrigger.triggerutil import SkipRequestException
|
||||
|
||||
class TestPrepareTrigger(unittest.TestCase):
|
||||
def assertSkipped(self, filename, processor, *args, **kwargs):
|
||||
with open('test/triggerjson/%s.json' % filename) as f:
|
||||
payload = json.loads(f.read())
|
||||
|
||||
nargs = [payload]
|
||||
nargs.extend(args)
|
||||
|
||||
with self.assertRaises(SkipRequestException):
|
||||
processor(*nargs, **kwargs)
|
||||
|
||||
|
||||
def assertSchema(self, filename, expected, processor, *args, **kwargs):
|
||||
with open('test/triggerjson/%s.json' % filename) as f:
|
||||
payload = json.loads(f.read())
|
||||
|
@ -349,6 +361,37 @@ class TestPrepareTrigger(unittest.TestCase):
|
|||
self.assertSchema('github_webhook_missing', expected, gh_webhook)
|
||||
|
||||
|
||||
def test_gitlab_webhook_nocommit_payload(self):
|
||||
self.assertSkipped('gitlab_webhook_nocommit', gl_webhook)
|
||||
|
||||
|
||||
def test_gitlab_webhook_multiple_commits(self):
|
||||
expected = {
|
||||
'commit': u'9a052a0b2fbe01d4a1a88638dd9fe31c1c56ef53',
|
||||
'ref': u'refs/heads/master',
|
||||
'git_url': u'git@gitlab.com:joseph.schorr/some-test-project.git',
|
||||
'commit_info': {
|
||||
'url': u'https://gitlab.com/joseph.schorr/some-test-project/commit/9a052a0b2fbe01d4a1a88638dd9fe31c1c56ef53',
|
||||
'date': u'2016-09-29T15:02:41+00:00',
|
||||
'message': u"Merge branch 'foobar' into 'master'\r\n\r\nAdd changelog\r\n\r\nSome merge thing\r\n\r\nSee merge request !1",
|
||||
'author': {
|
||||
'username': 'josephschorr',
|
||||
'url': 'http://gitlab.com/josephschorr',
|
||||
'avatar_url': 'http://some/avatar/url'
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
def lookup_user(_):
|
||||
return {
|
||||
'username': 'josephschorr',
|
||||
'html_url': 'http://gitlab.com/josephschorr',
|
||||
'avatar_url': 'http://some/avatar/url',
|
||||
}
|
||||
|
||||
self.assertSchema('gitlab_webhook_multicommit', expected, gl_webhook, lookup_user=lookup_user)
|
||||
|
||||
|
||||
def test_gitlab_webhook_payload_with_lookup(self):
|
||||
expected = {
|
||||
'commit': u'fb88379ee45de28a0a4590fddcbd8eff8b36026e',
|
||||
|
|
100
test/triggerjson/gitlab_webhook_multicommit.json
Normal file
100
test/triggerjson/gitlab_webhook_multicommit.json
Normal file
|
@ -0,0 +1,100 @@
|
|||
{
|
||||
"object_kind": "push",
|
||||
"event_name": "push",
|
||||
"before": "0da5b5ebb397f0a8569c97f28e266c718607e8da",
|
||||
"after": "9a052a0b2fbe01d4a1a88638dd9fe31c1c56ef53",
|
||||
"ref": "refs\/heads\/master",
|
||||
"checkout_sha": "9a052a0b2fbe01d4a1a88638dd9fe31c1c56ef53",
|
||||
"message": null,
|
||||
"user_id": 750047,
|
||||
"user_name": "Joseph Schorr",
|
||||
"user_email": "joseph.schorr@coreos.com",
|
||||
"user_avatar": "https:\/\/secure.gravatar.com\/avatar\/63e4521c07d2312d8e20c3a6cad36f57?s=80&d=identicon",
|
||||
"project_id": 1756744,
|
||||
"project": {
|
||||
"name": "some-test-project",
|
||||
"description": "",
|
||||
"web_url": "https:\/\/gitlab.com\/joseph.schorr\/some-test-project",
|
||||
"avatar_url": null,
|
||||
"git_ssh_url": "git@gitlab.com:joseph.schorr\/some-test-project.git",
|
||||
"git_http_url": "https:\/\/gitlab.com\/joseph.schorr\/some-test-project.git",
|
||||
"namespace": "joseph.schorr",
|
||||
"visibility_level": 0,
|
||||
"path_with_namespace": "joseph.schorr\/some-test-project",
|
||||
"default_branch": "master",
|
||||
"homepage": "https:\/\/gitlab.com\/joseph.schorr\/some-test-project",
|
||||
"url": "git@gitlab.com:joseph.schorr\/some-test-project.git",
|
||||
"ssh_url": "git@gitlab.com:joseph.schorr\/some-test-project.git",
|
||||
"http_url": "https:\/\/gitlab.com\/joseph.schorr\/some-test-project.git"
|
||||
},
|
||||
"commits": [
|
||||
{
|
||||
"id": "f00a0a6a71118721ac1f586bf79650170042609f",
|
||||
"message": "Add changelog",
|
||||
"timestamp": "2016-09-29T14:59:23+00:00",
|
||||
"url": "https:\/\/gitlab.com\/joseph.schorr\/some-test-project\/commit\/f00a0a6a71118721ac1f586bf79650170042609f",
|
||||
"author": {
|
||||
"name": "Joseph Schorr",
|
||||
"email": "joseph.schorr@coreos.com"
|
||||
},
|
||||
"added": [
|
||||
"CHANGELOG"
|
||||
],
|
||||
"modified": [
|
||||
|
||||
],
|
||||
"removed": [
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "cc66287314cb154c986665a6c29377ef42edee60",
|
||||
"message": "Add new file",
|
||||
"timestamp": "2016-09-29T15:02:01+00:00",
|
||||
"url": "https:\/\/gitlab.com\/joseph.schorr\/some-test-project\/commit\/cc66287314cb154c986665a6c29377ef42edee60",
|
||||
"author": {
|
||||
"name": "Joseph Schorr",
|
||||
"email": "joseph.schorr@coreos.com"
|
||||
},
|
||||
"added": [
|
||||
"YetAnotherFIle"
|
||||
],
|
||||
"modified": [
|
||||
|
||||
],
|
||||
"removed": [
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "9a052a0b2fbe01d4a1a88638dd9fe31c1c56ef53",
|
||||
"message": "Merge branch 'foobar' into 'master'\r\n\r\nAdd changelog\r\n\r\nSome merge thing\r\n\r\nSee merge request !1",
|
||||
"timestamp": "2016-09-29T15:02:41+00:00",
|
||||
"url": "https:\/\/gitlab.com\/joseph.schorr\/some-test-project\/commit\/9a052a0b2fbe01d4a1a88638dd9fe31c1c56ef53",
|
||||
"author": {
|
||||
"name": "Joseph Schorr",
|
||||
"email": "joseph.schorr@coreos.com"
|
||||
},
|
||||
"added": [
|
||||
"CHANGELOG",
|
||||
"YetAnotherFIle"
|
||||
],
|
||||
"modified": [
|
||||
|
||||
],
|
||||
"removed": [
|
||||
|
||||
]
|
||||
}
|
||||
],
|
||||
"total_commits_count": 3,
|
||||
"repository": {
|
||||
"name": "some-test-project",
|
||||
"url": "git@gitlab.com:joseph.schorr\/some-test-project.git",
|
||||
"description": "",
|
||||
"homepage": "https:\/\/gitlab.com\/joseph.schorr\/some-test-project",
|
||||
"git_http_url": "https:\/\/gitlab.com\/joseph.schorr\/some-test-project.git",
|
||||
"git_ssh_url": "git@gitlab.com:joseph.schorr\/some-test-project.git",
|
||||
"visibility_level": 0
|
||||
}
|
||||
}
|
44
test/triggerjson/gitlab_webhook_nocommit.json
Normal file
44
test/triggerjson/gitlab_webhook_nocommit.json
Normal file
|
@ -0,0 +1,44 @@
|
|||
{
|
||||
"object_kind": "push",
|
||||
"event_name": "push",
|
||||
"before": "cc66287314cb154c986665a6c29377ef42edee60",
|
||||
"after": "0000000000000000000000000000000000000000",
|
||||
"ref": "refs\/heads\/foobar",
|
||||
"checkout_sha": null,
|
||||
"message": null,
|
||||
"user_id": 750047,
|
||||
"user_name": "Joseph Schorr",
|
||||
"user_email": "joseph.schorr@coreos.com",
|
||||
"user_avatar": "https:\/\/secure.gravatar.com\/avatar\/63e4521c07d2312d8e20c3a6cad36f57?s=80&d=identicon",
|
||||
"project_id": 1756744,
|
||||
"project": {
|
||||
"name": "some-test-project",
|
||||
"description": "",
|
||||
"web_url": "https:\/\/gitlab.com\/joseph.schorr\/some-test-project",
|
||||
"avatar_url": null,
|
||||
"git_ssh_url": "git@gitlab.com:joseph.schorr\/some-test-project.git",
|
||||
"git_http_url": "https:\/\/gitlab.com\/joseph.schorr\/some-test-project.git",
|
||||
"namespace": "joseph.schorr",
|
||||
"visibility_level": 0,
|
||||
"path_with_namespace": "joseph.schorr\/some-test-project",
|
||||
"default_branch": "master",
|
||||
"homepage": "https:\/\/gitlab.com\/joseph.schorr\/some-test-project",
|
||||
"url": "git@gitlab.com:joseph.schorr\/some-test-project.git",
|
||||
"ssh_url": "git@gitlab.com:joseph.schorr\/some-test-project.git",
|
||||
"http_url": "https:\/\/gitlab.com\/joseph.schorr\/some-test-project.git"
|
||||
},
|
||||
"commits": [
|
||||
|
||||
],
|
||||
"total_commits_count": 0,
|
||||
"repository": {
|
||||
"name": "some-test-project",
|
||||
"url": "git@gitlab.com:joseph.schorr\/some-test-project.git",
|
||||
"description": "",
|
||||
"homepage": "https:\/\/gitlab.com\/joseph.schorr\/some-test-project",
|
||||
"git_http_url": "https:\/\/gitlab.com\/joseph.schorr\/some-test-project.git",
|
||||
"git_ssh_url": "git@gitlab.com:joseph.schorr\/some-test-project.git",
|
||||
"visibility_level": 0
|
||||
}
|
||||
}
|
||||
|
Reference in a new issue