From 8b93bf0218cf2097976159dab332dcaaff3f5eb4 Mon Sep 17 00:00:00 2001
From: Darko Poljak <darko.poljak@gmail.com>
Date: Sun, 30 Dec 2018 11:59:34 +0100
Subject: [PATCH] Migrate from github to ungleich gitlab

---
 bin/build-helper                              | 49 ++++++++----------
 bin/build-helper.freebsd                      | 48 ++++++++----------
 cdist/conf/type/__cdist/man.rst               |  4 +-
 .../type/__cdist/parameter/default/source     |  2 +-
 cdist/conf/type/__git/man.rst                 |  2 +-
 docs/dev/github-gitlab-migration/release      | 50 +++++++++++++++++++
 docs/src/cdist-hacker.rst                     | 20 ++++----
 docs/src/cdist-install.rst                    | 13 ++---
 docs/src/cdist-quickstart.rst                 |  2 +-
 9 files changed, 112 insertions(+), 78 deletions(-)
 create mode 100755 docs/dev/github-gitlab-migration/release

diff --git a/bin/build-helper b/bin/build-helper
index 963f02f9..72f683b9 100755
--- a/bin/build-helper
+++ b/bin/build-helper
@@ -209,35 +209,30 @@ eof
         fi
         gpg --armor --detach-sign "${archivename}" || exit 1
 
-        # make github release
-        curl -H "Authorization: token ${token}" \
-            --request POST \
-            --data "{ \"tag_name\":\"${tag}\", \
-                      \"target_commitish\":\"master\", \
-                      \"name\": \"${tag}\", \
-                      \"body\":\"${tag}\", \
-                      \"draft\":false, \
-                      \"prerelease\": false}" \
-            "https://api.github.com/repos/ungleich/cdist/releases" || exit 1
+        project="ungleich-public%2Fcdist"
+        sed_cmd='s/^.*"markdown":"\([^"]*\)".*$/\1/'
 
-        # get release ID
-        repoid=$(curl "https://api.github.com/repos/ungleich/cdist/releases/tags/${tag}" \
-            | python3 -c 'import json; import sys; print(json.loads(sys.stdin.read())["id"])') \
+        # upload archive
+        response_archive=$(curl -f -X POST \
+             -H "PRIVATE-TOKEN: ${token}" \
+             -F "file=@${archivename}" \
+             "https://code.ungleich.ch/api/v4/projects/${project}/uploads" \
+             | sed "${sed_cmd}") || exit 1
+
+        # upload archive signature
+        response_archive_sig=$(curl -f -X POST \
+             -H "PRIVATE-TOKEN: ${token}" \
+             -F "file=@${archivename}.asc" \
+            "https://code.ungleich.ch/api/v4/projects/${project}/uploads" \
+             | sed "${sed_cmd}") || exit 1
+
+        # make release
+        curl -f -X POST \
+             -H "PRIVATE-TOKEN: ${token}" \
+             -F "description=Release ${tag}<br/>${response_archive}<br/>${response_archive_sig}" \
+            "https://code.ungleich.ch/api/v4/projects/${project}/repository/tags/${tag}/release" \
             || exit 1
 
-        # upload archive and then signature
-        curl -H "Authorization: token ${token}" \
-             -H "Accept: application/vnd.github.manifold-preview" \
-             -H "Content-Type: application/x-gtar" \
-             --data-binary @${archivename} \
-            "https://uploads.github.com/repos/ungleich/cdist/releases/${repoid}/assets?name=${archivename}" \
-            || exit 1
-        curl -H "Authorization: token ${token}" \
-             -H "Accept: application/vnd.github.manifold-preview" \
-             -H "Content-Type: application/pgp-signature" \
-             --data-binary @${archivename}.asc \
-            "https://uploads.github.com/repos/ungleich/cdist/releases/${repoid}/assets?name=${archivename}.asc" \
-            || exit 1
 
         # remove generated files (archive and asc)
         if [ $# -eq 2 ]
@@ -314,7 +309,7 @@ eof
         "$0" release-git-tag
 
         # sign git tag
-        printf "Enter github authentication token: "
+        printf "Enter upstream repository authentication token: "
         read token
         "$0" sign-git-release "${target_version}" "${token}"
 
diff --git a/bin/build-helper.freebsd b/bin/build-helper.freebsd
index ea16ef42..cb8e5397 100755
--- a/bin/build-helper.freebsd
+++ b/bin/build-helper.freebsd
@@ -244,34 +244,28 @@ eof
         fi
         gpg --armor --detach-sign "${archivename}" || exit 1
 
-        # make github release
-        curl -H "Authorization: token ${token}" \
-            --request POST \
-            --data "{ \"tag_name\":\"${tag}\", \
-                      \"target_commitish\":\"master\", \
-                      \"name\": \"${tag}\", \
-                      \"body\":\"${tag}\", \
-                      \"draft\":false, \
-                      \"prerelease\": false}" \
-            "https://api.github.com/repos/ungleich/cdist/releases" || exit 1
+        project="ungleich-public%2Fcdist"
+        sed_cmd='s/^.*"markdown":"\([^"]*\)".*$/\1/'
 
-        # get release ID
-        repoid=$(curl "https://api.github.com/repos/ungleich/cdist/releases/tags/${tag}" \
-            | python3 -c 'import json; import sys; print(json.loads(sys.stdin.read())["id"])') \
-            || exit 1
+        # upload archive
+        response_archive=$(curl -f -X POST \
+             -H "PRIVATE-TOKEN: ${token}" \
+             -F "file=@${archivename}" \
+             "https://code.ungleich.ch/api/v4/projects/${project}/uploads" \
+             | sed "${sed_cmd}") || exit 1
 
-        # upload archive and then signature
-        curl -H "Authorization: token ${token}" \
-             -H "Accept: application/vnd.github.manifold-preview" \
-             -H "Content-Type: application/x-gtar" \
-             --data-binary @${archivename} \
-            "https://uploads.github.com/repos/ungleich/cdist/releases/${repoid}/assets?name=${archivename}" \
-            || exit 1
-        curl -H "Authorization: token ${token}" \
-             -H "Accept: application/vnd.github.manifold-preview" \
-             -H "Content-Type: application/pgp-signature" \
-             --data-binary @${archivename}.asc \
-            "https://uploads.github.com/repos/ungleich/cdist/releases/${repoid}/assets?name=${archivename}.asc" \
+        # upload archive signature
+        response_archive_sig=$(curl -f -X POST \
+             -H "PRIVATE-TOKEN: ${token}" \
+             -F "file=@${archivename}.asc" \
+            "https://code.ungleich.ch/api/v4/projects/${project}/uploads" \
+             | sed "${sed_cmd}") || exit 1
+
+        # make release
+        curl -f -X POST \
+             -H "PRIVATE-TOKEN: ${token}" \
+             -F "description=Release ${tag}<br/>${response_archive}<br/>${response_archive_sig}" \
+            "https://code.ungleich.ch/api/v4/projects/${project}/repository/tags/${tag}/release" \
             || exit 1
 
         # remove generated files (archive and asc)
@@ -349,7 +343,7 @@ eof
         "$0" release-git-tag
 
         # sign git tag
-        printf "Enter github authentication token: "
+        printf "Enter upstream repository authentication token: "
         read token
         "$0" sign-git-release "${target_version}" "${token}"
 
diff --git a/cdist/conf/type/__cdist/man.rst b/cdist/conf/type/__cdist/man.rst
index 9e1c72cb..15c77d7f 100644
--- a/cdist/conf/type/__cdist/man.rst
+++ b/cdist/conf/type/__cdist/man.rst
@@ -30,7 +30,7 @@ username
 
 source
     Select the source from which to clone cdist from.
-    Defaults to "git://github.com/ungleich/cdist.git".
+    Defaults to "git://code.ungleich.ch/ungleich-public/cdist.git".
 
 
 branch
@@ -47,7 +47,7 @@ EXAMPLES
     __cdist /home/cdist/cdist
 
     # Use alternative source
-    __cdist --source "git://github.com/ungleich/cdist" /home/cdist/cdist
+    __cdist --source "git://code.ungleich.ch/ungleich-public/cdist" /home/cdist/cdist
 
 
 AUTHORS
diff --git a/cdist/conf/type/__cdist/parameter/default/source b/cdist/conf/type/__cdist/parameter/default/source
index 3f8e31ad..5f44a285 100644
--- a/cdist/conf/type/__cdist/parameter/default/source
+++ b/cdist/conf/type/__cdist/parameter/default/source
@@ -1 +1 @@
-git://github.com/ungleich/cdist.git
+git://code.ungleich.ch/ungleich-public/cdist.git
diff --git a/cdist/conf/type/__git/man.rst b/cdist/conf/type/__git/man.rst
index 17e9c623..aa704d2b 100644
--- a/cdist/conf/type/__git/man.rst
+++ b/cdist/conf/type/__git/man.rst
@@ -44,7 +44,7 @@ EXAMPLES
     __git /home/services/dokuwiki --source git://github.com/splitbrain/dokuwiki.git
 
     # Checkout cdist, stay on branch 2.1
-    __git /home/nico/cdist --source git://github.com/ungleich/cdist.git --branch 2.1
+    __git /home/nico/cdist --source git://code.ungleich.ch/ungleich-public/cdist.git --branch 2.1
 
 
 AUTHORS
diff --git a/docs/dev/github-gitlab-migration/release b/docs/dev/github-gitlab-migration/release
new file mode 100755
index 00000000..c973f0f1
--- /dev/null
+++ b/docs/dev/github-gitlab-migration/release
@@ -0,0 +1,50 @@
+#!/bin/sh -e
+
+set -x
+
+printf "Enter tag name: "
+read tag
+printf "Enter repository authentication token: "
+read token
+
+git tag -d "${tag}" || :
+
+git tag "${tag}" -m "Release ${tag}"
+git push origin "${tag}"
+
+echo 'foo' > foo
+echo 'foo signature' > foo.asc
+
+archivename="foo"
+
+project="poljakowski%2Fmy-cdist-testing"
+sed_cmd='s/^.*"markdown":"\([^"]*\)".*$/\1/'
+
+# upload archive
+response_archive=$(curl -f -X POST \
+     -H "PRIVATE-TOKEN: ${token}" \
+     -F "file=@${archivename}" \
+     "https://code.ungleich.ch/api/v4/projects/${project}/uploads" \
+     | sed "${sed_cmd}") || exit 1
+
+# upload archive signature
+response_archive_sig=$(curl -f -X POST \
+     -H "PRIVATE-TOKEN: ${token}" \
+     -F "file=@${archivename}.asc" \
+    "https://code.ungleich.ch/api/v4/projects/${project}/uploads" \
+     | sed "${sed_cmd}") || exit 1
+
+# make release
+curl -f -X POST \
+     -H "PRIVATE-TOKEN: ${token}" \
+     -F "description=Release ${tag}<br/>${response_archive}<br/>${response_archive_sig}" \
+    "https://code.ungleich.ch/api/v4/projects/${project}/repository/tags/${tag}/release" \
+    || exit 1
+
+# get tag
+curl -f -X GET \
+     -H "PRIVATE-TOKEN: ${token}" \
+    "https://code.ungleich.ch/api/v4/projects/${project}/repository/tags/${tag}" \
+    || exit 1
+
+rm -f foo foo.asc
diff --git a/docs/src/cdist-hacker.rst b/docs/src/cdist-hacker.rst
index d65c41a6..e4252e19 100644
--- a/docs/src/cdist-hacker.rst
+++ b/docs/src/cdist-hacker.rst
@@ -16,7 +16,7 @@ Reporting bugs
 --------------
 If you believe you've found a bug and verified that it is
 in the latest version, drop a mail to the cdist mailing list,
-subject prefixed with "[BUG] " or create an issue on github.
+subject prefixed with "[BUG] " or create an issue on code.ungleich.ch.
 
 
 Coding conventions (everywhere)
@@ -51,7 +51,7 @@ work nor kill the authors brain:
 
 As soon as your work meets these requirements, write a mail
 for inclusion to the mailinglist **cdist-configuration-management at googlegroups.com**
-or open a pull request at http://github.com/ungleich/cdist.
+or open a merge request at https://code.ungleich.ch/ungleich-public/cdist.
 
 
 How to submit a new type
@@ -76,7 +76,7 @@ The following workflow works fine for most developers
 .. code-block:: sh
 
     # get latest upstream master branch
-    git clone https://github.com/ungleich/cdist.git
+    git clone https://code.ungleich.ch/ungleich-public/cdist.git
 
     # update if already existing
     cd cdist; git fetch -v; git merge origin/master
@@ -88,22 +88,22 @@ The following workflow works fine for most developers
     # *hack*
     *hack*
 
-    # clone the cdist repository on github if you haven't done so
+    # clone the cdist repository on code.ungleich.ch if you haven't done so
 
     # configure your repo to know about your clone (only once)
-    git remote add github git@github.com:YOURUSERNAME/cdist.git
+    git remote add ungleich git@code.ungleich.ch:YOURUSERNAME/cdist.git
 
-    # push the new branch to github 
-    git push github documentation_cleanup
+    # push the new branch to ungleich gitlab
+    git push ungleich documentation_cleanup
 
     # (or everything)
-    git push --mirror github
+    git push --mirror ungleich
 
-    # create a pull request at github (use a browser)
+    # create a merge request at ungleich gitlab (use a browser)
     # *fixthingsbecausequalityassurancefoundissuesinourpatch*
     *hack*
 
-    # push code to github again
+    # push code to ungleich gitlab again
     git push ... # like above
 
     # add comment that everything should be green now (use a browser)
diff --git a/docs/src/cdist-install.rst b/docs/src/cdist-install.rst
index afc50016..c05036b0 100644
--- a/docs/src/cdist-install.rst
+++ b/docs/src/cdist-install.rst
@@ -36,10 +36,13 @@ To install cdist, execute the following commands:
 
 .. code-block:: sh
 
-    git clone https://github.com/ungleich/cdist.git
+    git clone https://code.ungleich.ch/ungleich-public/cdist.git
     cd cdist
     export PATH=$PATH:$(pwd -P)/bin
 
+From version 4.2.0 cdist tags and releases are signed.
+You can get GPG public key used for signing `here <_static/pgp-key-EFD2AE4EC36B6901.asc>`_.
+
 To install cdist with distutils from cloned repository, first you have to
 create version.py:
 
@@ -74,14 +77,6 @@ So for instance if you want to use and stay with version 4.1, you can use
 
     git checkout -b 4.1 origin/4.1
 
-Git mirrors
-^^^^^^^^^^^
-
-If the main site is down, you can acquire cdist from one of the following sites:
-
- * git://github.com/telmich/cdist.git `github <https://github.com/telmich/cdist>`_
- * git://git.code.sf.net/p/cdist/code `sourceforge <https://sourceforge.net/p/cdist/code>`_
-
 Building and using documentation (man and html)
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
diff --git a/docs/src/cdist-quickstart.rst b/docs/src/cdist-quickstart.rst
index 0020568d..b9220b67 100644
--- a/docs/src/cdist-quickstart.rst
+++ b/docs/src/cdist-quickstart.rst
@@ -56,7 +56,7 @@ code into your shell to get started and configure localhost::
     # Get cdist 
     # Mirrors can be found on
     # http://www.nico.schottelius.org/software/cdist/install/#index2h4
-    git clone git://github.com/ungleich/cdist
+    git clone git://code.ungleich.ch/ungleich-public/cdist
 
     # Create manifest (maps configuration to host(s)
     cd cdist