From 74d4ea62abb9cc42bc694f7c1812050589da0beb Mon Sep 17 00:00:00 2001
From: Kirill Smelkov <kirr@nexedi.com>
Date: Fri, 8 Jan 2016 13:48:40 +0300
Subject: [PATCH] gitlab: Switch to "GitLab Nexedi Edition"

GitLab Nexedi Edition is currently upstream 8.2.X + the following
patches:

    - HTTP(S) is made to be default clone protocol

        https://lab.nexedi.com/kirr/gitlab-ce/commit/5c1f2fb3

      and SSH info is completely removed from UI

        https://lab.nexedi.com/kirr/gitlab-ce/commit/dfe9fb16
        https://lab.nexedi.com/kirr/gitlab-ce/commit/f3f84743

      so essentially the only way to access a repository is via HTTP(S).

    - Rake check tasks are adjusted to exit with non-zero code if there
      is a failure

        https://lab.nexedi.com/kirr/gitlab-ce/commit/a93ae418

      We need this for promises to work correctly with failures being
      detected, not silently skipped. The patch was sent upstream:

        https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/1885

    - GitLab supports setting up site's ICP License in gitlab.yml and
      shows it in appropriate places together with info about GitLab
      itself:

        https://lab.nexedi.com/kirr/gitlab-ce/commit/e7e0fd88
        https://lab.nexedi.com/kirr/gitlab-ce/commit/79c127e6

    + other cosmetic/minor changes.

More patches will probably come (e.g. apply a single patch from a
merge-request with `git am` without creating merge commit for just 1
patch, etc) but for now that's all.

NOTE ICP is non-ascii text with hieroglyphs. slapos.core was taught to
    be able to pass parameters with non-ascii values to instance:

        https://lab.nexedi.com/nexedi/slapos.core/commit/347d33d6

    That patch is included in slapos.core 1.3.15, but as we currently
    have a lot of older slapos.core deployed (e.g. 1.3.5 on my
    development webrunner) a workaround is (hopefully temporarily) used
    to pass non-ascii values as URL-encoded strings.

/cc @kazuhiko, @jerome, @rafael
---
 software/gitlab/instance-gitlab.cfg.in |  5 +++++
 software/gitlab/software.cfg           |  7 ++++---
 software/gitlab/template/gitlab.yml.in | 10 ++++++++++
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/software/gitlab/instance-gitlab.cfg.in b/software/gitlab/instance-gitlab.cfg.in
index 1f9cce07f..3d2548bb0 100644
--- a/software/gitlab/instance-gitlab.cfg.in
+++ b/software/gitlab/instance-gitlab.cfg.in
@@ -62,6 +62,10 @@ configuration.unicorn_worker_processes  = {{ multiprocessing.cpu_count() + 1 }}
 configuration.nginx_worker_processes    = {{ multiprocessing.cpu_count() }}
 
 
+# gitlab non-native parameters
+configuration.icp_license  =
+
+
 
 # for convenience
 [external-url]
@@ -217,6 +221,7 @@ context-extra =
 <= gitlab-etc-template
 template= {{ gitlab_yml_in }}
 context-extra =
+    import  urllib                  urllib
     section gitlab                  gitlab
     section gitlab_shell            gitlab-shell
     section gitlab_shell_work       gitlab-shell-work
diff --git a/software/gitlab/software.cfg b/software/gitlab/software.cfg
index be6b2ebdb..97d458fb5 100644
--- a/software/gitlab/software.cfg
+++ b/software/gitlab/software.cfg
@@ -93,9 +93,10 @@ git-executable = ${git:location}/bin/git
 
 [gitlab-repository]
 <= git-repository
-repository = https://gitlab.com/gitlab-org/gitlab-ce.git
-# 8.2.X
-revision = v8.2.3-0-g19daba8a6f170e38bcd7371bab2d582d5324b215
+#repository = https://gitlab.com/gitlab-org/gitlab-ce.git
+repository = https://lab.nexedi.com/kirr/gitlab-ce.git
+# 8.2.X + NXD patches:
+revision = v8.2.3-9-g79c127e6e068a619c53a8c22f1db8c1e28ec87d2
 location = ${buildout:parts-directory}/gitlab
 
 [gitlab-shell-repository]
diff --git a/software/gitlab/template/gitlab.yml.in b/software/gitlab/template/gitlab.yml.in
index 822b80360..8f85e9641 100644
--- a/software/gitlab/template/gitlab.yml.in
+++ b/software/gitlab/template/gitlab.yml.in
@@ -370,6 +370,16 @@ production: &base
     #}
 
 
+    ## Site ICP License
+    # XXX unquote needed only for slapos.core earlier than
+    #   https://lab.nexedi.com/nexedi/slapos.core/commit/347d33d6
+    # for now we have a lot of old slapos.core deployed...
+    {% if cfg('icp_license') != '' -%}
+    ICP: {{ urllib.unquote_plus( str(cfg('icp_license')) ).decode('utf-8') }}
+    {# ICP: '{{ cfg("icp_license") }}' #}
+    {% endif %}
+
+
 development:
   <<: *base
 
-- 
2.30.9