Repository: smarkets/marge-bot

Issue:
Errors parsing version of current gitlab versions
Got an an error when parsing the version of newer gitlab versions. Looks like the "edition" part of the version is missing but expected.

``` 24.7.2017 23:49:212017-07-24 21:49:21,799 DEBUG http://gitlab:80 "GET /api/v4/version HTTP/1.1" 200 None
24.7.2017 23:49:212017-07-24 21:49:21,800 DEBUG RESPONSE CODE: 200
24.7.2017 23:49:212017-07-24 21:49:21,800 DEBUG RESPONSE BODY: {'version': '9.4.0', 'revision': '9bbe2ac'}
24.7.2017 23:49:212017-07-24 21:49:21,800 ERROR Unexpected Exception
24.7.2017 23:49:21Traceback (most recent call last):
24.7.2017 23:49:21  File "/nix/store/0yjvdhpw9cpmahw6ndfgby9n4pz8m79i-python3.6-marge-0.1.1/lib/python3.6/site-packages/marge/job.py", line 56, in execute
24.7.2017 23:49:21    approvals = merge_request.fetch_approvals()
24.7.2017 23:49:21  File "/nix/store/0yjvdhpw9cpmahw6ndfgby9n4pz8m79i-python3.6-marge-0.1.1/lib/python3.6/site-packages/marge/merge_request.py", line 121, in fetch_approvals
24.7.2017 23:49:21    approvals.refetch_info()
24.7.2017 23:49:21  File "/nix/store/0yjvdhpw9cpmahw6ndfgby9n4pz8m79i-python3.6-marge-0.1.1/lib/python3.6/site-packages/marge/approvals.py", line 10, in refetch_info
24.7.2017 23:49:21    if self._api.version().release >= (9, 2, 2):
24.7.2017 23:49:21  File "/nix/store/0yjvdhpw9cpmahw6ndfgby9n4pz8m79i-python3.6-marge-0.1.1/lib/python3.6/site-packages/marge/gitlab.py", line 72, in version
24.7.2017 23:49:21    return Version.parse(response['version'])
24.7.2017 23:49:21  File "/nix/store/0yjvdhpw9cpmahw6ndfgby9n4pz8m79i-python3.6-marge-0.1.1/lib/python3.6/site-packages/marge/gitlab.py", line 207, in parse
24.7.2017 23:49:21    release_string, edition = string.split('-', maxsplit=1)
24.7.2017 23:49:21ValueError: not enough values to unpack (expected 2, got 1)
24.7.2017 23:49:212017-07-24 21:49:21,800 DEBUG REQUEST: GET http://gitlab/api/v4/version {'PRIVATE-TOKEN': 'HW9c_BJgwgoK5cEmwsSr'} {'params': {}}
24.7.2017 23:49:212017-07-24 21:49:21,802 DEBUG Starting new HTTP connection (1): gitlab
24.7.2017 23:49:212017-07-24 21:49:21,810 DEBUG http://gitlab:80 "GET /api/v4/version HTTP/1.1" 200 None
24.7.2017 23:49:212017-07-24 21:49:21,811 DEBUG RESPONSE CODE: 200
24.7.2017 23:49:212017-07-24 21:49:21,811 DEBUG RESPONSE BODY: {'version': '9.4.0', 'revision': '9bbe2ac'}
24.7.2017 23:49:21Traceback (most recent call last):
24.7.2017 23:49:21  File "/nix/store/0yjvdhpw9cpmahw6ndfgby9n4pz8m79i-python3.6-marge-0.1.1/lib/python3.6/site-packages/marge/job.py", line 56, in execute
24.7.2017 23:49:21    approvals = merge_request.fetch_approvals()
24.7.2017 23:49:21  File "/nix/store/0yjvdhpw9cpmahw6ndfgby9n4pz8m79i-python3.6-marge-0.1.1/lib/python3.6/site-packages/marge/merge_request.py", line 121, in fetch_approvals
24.7.2017 23:49:21    approvals.refetch_info()
24.7.2017 23:49:21  File "/nix/store/0yjvdhpw9cpmahw6ndfgby9n4pz8m79i-python3.6-marge-0.1.1/lib/python3.6/site-packages/marge/approvals.py", line 10, in refetch_info
24.7.2017 23:49:21    if self._api.version().release >= (9, 2, 2):
24.7.2017 23:49:21  File "/nix/store/0yjvdhpw9cpmahw6ndfgby9n4pz8m79i-python3.6-marge-0.1.1/lib/python3.6/site-packages/marge/gitlab.py", line 72, in version
24.7.2017 23:49:21    return Version.parse(response['version'])
24.7.2017 23:49:21  File "/nix/store/0yjvdhpw9cpmahw6ndfgby9n4pz8m79i-python3.6-marge-0.1.1/lib/python3.6/site-packages/marge/gitlab.py", line 207, in parse
24.7.2017 23:49:21    release_string, edition = string.split('-', maxsplit=1)
24.7.2017 23:49:21ValueError: not enough values to unpack (expected 2, got 1)
24.7.2017 23:49:21
24.7.2017 23:49:21During handling of the above exception, another exception occurred:
24.7.2017 23:49:21
24.7.2017 23:49:21Traceback (most recent call last):
24.7.2017 23:49:21  File "/nix/store/0yjvdhpw9cpmahw6ndfgby9n4pz8m79i-python3.6-marge-0.1.1/bin/.marge.app-wrapped", line 4, in <module>
24.7.2017 23:49:21    marge.app.main()
24.7.2017 23:49:21  File "/nix/store/0yjvdhpw9cpmahw6ndfgby9n4pz8m79i-python3.6-marge-0.1.1/lib/python3.6/site-packages/marge/app.py", line 114, in main
24.7.2017 23:49:21    marge_bot.start()
24.7.2017 23:49:21  File "/nix/store/0yjvdhpw9cpmahw6ndfgby9n4pz8m79i-python3.6-marge-0.1.1/lib/python3.6/site-packages/marge/bot.py", line 50, in start
24.7.2017 23:49:21    self._run(repo_manager)
24.7.2017 23:49:21  File "/nix/store/0yjvdhpw9cpmahw6ndfgby9n4pz8m79i-python3.6-marge-0.1.1/lib/python3.6/site-packages/marge/bot.py", line 92, in _run
24.7.2017 23:49:21    job.execute()
24.7.2017 23:49:21  File "/nix/store/0yjvdhpw9cpmahw6ndfgby9n4pz8m79i-python3.6-marge-0.1.1/lib/python3.6/site-packages/marge/job.py", line 70, in execute
24.7.2017 23:49:21    merge_request.comment("I'm broken on the inside, please somebody fix me... :cry:")
24.7.2017 23:49:21  File "/nix/store/0yjvdhpw9cpmahw6ndfgby9n4pz8m79i-python3.6-marge-0.1.1/lib/python3.6/site-packages/marge/merge_request.py", line 90, in comment
24.7.2017 23:49:21    if self._api.version().release >= (9, 2, 2):
24.7.2017 23:49:21  File "/nix/store/0yjvdhpw9cpmahw6ndfgby9n4pz8m79i-python3.6-marge-0.1.1/lib/python3.6/site-packages/marge/gitlab.py", line 72, in version
24.7.2017 23:49:21    return Version.parse(response['version'])
24.7.2017 23:49:21  File "/nix/store/0yjvdhpw9cpmahw6ndfgby9n4pz8m79i-python3.6-marge-0.1.1/lib/python3.6/site-packages/marge/gitlab.py", line 207, in parse
24.7.2017 23:49:21    release_string, edition = string.split('-', maxsplit=1)
24.7.2017 23:49:21ValueError: not enough values to unpack (expected 2, got 1)
```

**Versions**
GitLab: 9.4.0
GitLab API: v4
marge-bot: 0.1.1

Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0e2c68f..33fcdd7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,2 +1,3 @@
+* 0.1.2: Fix parsing of gitlab versions #28
 * 0.1.1: Fix failure to take into account group permissions #19.
 * 0.1.0: Initial release
diff --git a/marge/gitlab.py b/marge/gitlab.py
index 1af1363..7ee00c0 100644
--- a/marge/gitlab.py
+++ b/marge/gitlab.py
@@ -204,6 +204,11 @@ class Resource(object):
 class Version(namedtuple('Version', 'release edition')):
     @classmethod
     def parse(cls, string):
-        release_string, edition = string.split('-', maxsplit=1)
+        maybe_split_string = string.split('-', maxsplit=1)
+        if len(maybe_split_string) == 2:
+            release_string, edition = maybe_split_string
+        else:
+            release_string, edition = string, None
+
         release = tuple(int(number) for number in release_string.split('.'))
         return cls(release=release, edition=edition)
diff --git a/version b/version
index 17e51c3..d917d3e 100644
--- a/version
+++ b/version
@@ -1,1 +1,1 @@
-0.1.1
+0.1.2


Test patch:
diff --git a/tests/test_gitlab.py b/tests/test_gitlab.py
index 3d261a8..249a95a 100644
--- a/tests/test_gitlab.py
+++ b/tests/test_gitlab.py
@@ -4,3 +4,6 @@ import marge.gitlab as gitlab
 class TestVersion(object):
     def test_parse(self):
         assert gitlab.Version.parse('9.2.2-ee') == gitlab.Version(release=(9, 2, 2), edition='ee')
+
+    def test_parse_no_edition(self):
+        assert gitlab.Version.parse('9.4.0')  == gitlab.Version(release=(9, 4, 0), edition=None)