Repository: akvo/akvo-rsr

Issue:
Branch names with a single quote in the name fail the CI
Example #4794 has a branch name `feature/4788-Clean-dev-envs-can't-create-programs-in-the-frontend`. The resulting [CI job](https://akvo.semaphoreci.com/jobs/db9ac57c-e97e-4b05-af76-0e6e0f0b2515#L9529) fails because of 

```
 00:00
django-prod_1    | Waiting for PostgreSQL ... 00:00
django-prod_1    | PostgreSQL is ready! 00:00
django-prod_1    | 15:41:22 - START INFO - Migrating 00:00
django-prod_1    | Traceback (most recent call last): 00:00
django-prod_1    |   File "manage.py", line 27, in <module> 00:00
django-prod_1    |     execute_from_command_line(sys.argv) 00:00
django-prod_1    |   File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line 00:00
django-prod_1    |     utility.execute() 00:00
django-prod_1    |   File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 363, in execute 00:00
django-prod_1    |     settings.INSTALLED_APPS 00:00
django-prod_1    |   File "/usr/local/lib/python3.8/site-packages/django/conf/__init__.py", line 82, in __getattr__ 00:00
django-prod_1    |     self._setup(name) 00:00
django-prod_1    |   File "/usr/local/lib/python3.8/site-packages/django/conf/__init__.py", line 69, in _setup 00:00
django-prod_1    |     self._wrapped = Settings(settings_module) 00:00
django-prod_1    |   File "/usr/local/lib/python3.8/site-packages/django/conf/__init__.py", line 170, in __init__ 00:00
django-prod_1    |     mod = importlib.import_module(self.SETTINGS_MODULE) 00:00
django-prod_1    |   File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module 00:00
django-prod_1    |     return _bootstrap._gcd_import(name[level:], package, level) 00:00
django-prod_1    |   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import 00:00
django-prod_1    |   File "<frozen importlib._bootstrap>", line 991, in _find_and_load 00:00
django-prod_1    |   File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked 00:00
django-prod_1    |   File "<frozen importlib._bootstrap>", line 671, in _load_unlocked 00:00
django-prod_1    |   File "<frozen importlib._bootstrap_external>", line 783, in exec_module 00:00
django-prod_1    |   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed 00:00
django-prod_1    |   File "/var/akvo/rsr/code/akvo/settings/__init__.py", line 41, in <module> 00:00
django-prod_1    |     exec(compile(g.read(), path, 'exec')) 00:00
django-prod_1    |   File "/var/akvo/rsr/code/akvo/settings/66_deploy_info.conf", line 3 00:00
django-prod_1    |     DEPLOY_BRANCH = 'feature/4788-Clean-dev-envs-can't-create-programs-in-the-frontend'
```

`66_deploy_info.conf` is interpreted as python and the branch name is inserted into a single-quoted string.


Discussion:

Resolving patch:
diff --git a/ci/quote.py b/ci/quote.py
new file mode 100755
--- /dev/null
+++ b/ci/quote.py
@@ -0,0 +1,15 @@
+#!/usr/bin/env python3
+"""
+Outputs a valid python string from the given input
+
+Only one parameter is accepted
+"""
+
+import shlex
+import sys
+
+quote = shlex.quote(sys.argv[1])
+if not (quote.startswith("'") or quote.startswith('"')):
+    quote = f"'{quote}'"
+
+print(quote)


Test patch: