Fix handling of Gitlab payloads with multiple commits

Gitlab sends multiple commits in the order reversed from Github. As this only broke recently, I suspect that they may have changed the ordering. This change makes the code order-agnostic to hopefully remove the problem going forward.

Fixes #1900
This commit is contained in:
Joseph Schorr 2016-09-30 12:14:32 +02:00
parent c43173576a
commit 26e8e241da
3 changed files with 143 additions and 4 deletions

View file

@ -364,6 +364,34 @@ class TestPrepareTrigger(unittest.TestCase):
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',