[med-svn] [Git][med-team/community/helper-scripts][master] Set tag pending for all repositories of team

Andreas Tille gitlab at salsa.debian.org
Sat Mar 28 18:52:21 GMT 2020



Andreas Tille pushed to branch master at Debian Med / community / helper-scripts


Commits:
d64460c7 by Andreas Tille at 2020-03-28T19:51:55+01:00
Set tag pending for all repositories of team

- - - - -


1 changed file:

- + tag_pending


Changes:

=====================================
tag_pending
=====================================
@@ -0,0 +1,132 @@
+#!/bin/sh
+
+# Also, dpt-salsa (in pkg-perl-tools) might be able to do what you want
+
+set -e
+
+help() {
+  cat <<EOHELP
+
+Usage: $(basename $0)
+
+Run this script from within the root of a Debian package that is not yet
+uploaded to salsa.debian.org and for that yet no repository was created on that site.
+
+To read and write to that salsa gitlab site, this script needs an access token.
+This is retrieved from https://salsa.debian.org/profile/personal_access_tokens
+and requires a user account on salsa, obviously. To use that token, create
+
+cat > ~/.ssh/salsarc <<EOSALSATOKEN
+SALSA_URL="https://salsa.debian.org/api/v4"
+SALSA_TOKEN="YOUR_SALSA_TOKEN"
+EOSALSATOKEN
+
+and this will be found by this script when executed.
+See https://salsa.debian.org/profile/personal_access_tokens to learn how these
+can be created.
+
+EOHELP
+}
+
+if [ $# -gt 0 ] ; then
+  if [ "-h"="$1" -o "--help"="$1" ] ; then
+    help
+    exit
+  fi
+fi
+
+set -u
+
+SALSARC=~/.ssh/salsarc
+
+if [ ! -f $SALSARC ] ; then
+  echo "E: Missing ${SALSARC}. Reread help to create that file:"
+  echo
+  help
+  exit 1
+fi
+
+check_return_code() {
+    if [ $? -ne 0 ]; then
+        echo
+        echo "E: Something went wrong!"
+        exit 1
+    fi
+}
+
+if [ ! -d debian ]; then
+  echo "E: Missing 'debian' folder. Please execute this script from the root of a nascent Debian package."
+  exit 1
+fi
+
+if [ ! -d .git ]; then
+  echo "E: This Debian package is meant to be imported into git already. But there is no .git directory."
+  exit 1
+fi
+
+if [ ! -x /usr/bin/jq ]; then
+  echo "E: You need the 'jq' JSON command line processor from the cognate package."
+  exit 1
+fi
+
+. ${SALSARC}
+
+DEBPKGNAME=`dpkg-parsechangelog | awk '/^Source:/ {print $2}'`
+SHORTDESC=`grep "^Description: " debian/control | head -n 1 | sed 's/^Description: //'`
+VCSGIT=`grep "^Vcs-Git: " debian/control | sed -e 's/^Vcs-Git: //' -e 's#[githps]\+://anonscm.debian.org/#ssh://git.debian.org/#'`
+SALSA_GROUP=`echo $VCSGIT | sed -e 's#.*://salsa.debian.org/\([^/]\+\)/.*#\1#'`
+
+#echo $VCSGIT
+#echo $SALSA_GROUP
+
+SALSA_GROUP_ID=$(curl -s -f -XGET "$SALSA_URL/groups/$SALSA_GROUP?with_projects=false" | jq '.id')
+
+if [ "$SALSA_GROUP_ID" = "" ] ; then
+    echo "Failed to find group ID for $SALSA_GROUP"
+    exit 1
+fi
+
+# Did we already push to salsa?
+RESPONSE=$(curl "$SALSA_URL/projects?search=${DEBPKGNAME}")
+echo $RESPONSE | jq --exit-status "map(select(.path == \"${DEBPKGNAME}\")) | .[0].id" > /dev/null
+set -e
+if [ $? -eq 0 ]; then
+    # Seems like not, lets create a project
+    set -x
+    echo "Project ${DEBPKGNAME} does not exists on Salsa - just create the project"
+    echo "ATTENTION: If this fails for you ask for **Maintainer** permissions in your project"
+    RESPONSE=$(curl "$SALSA_URL/projects?private_token=$SALSA_TOKEN" \
+        --data "path=${DEBPKGNAME}&namespace_id=${SALSA_GROUP_ID}&description=${SHORTDESC}&visibility=public")
+
+    echo $RESPONSE | jq --exit-status .id > /dev/null
+    check_return_code
+
+    PROJECT_ID=$(echo $RESPONSE | jq '.id')
+    set +x
+else
+    set -x
+    echo "Project ${DEBPKGNAME} exists on Salsa - just update some metadata"
+    PROJECT_ID=$(echo $RESPONSE | jq "map(select(.path == \"${DEBPKGNAME}\")) | .[0].id")
+    set +x
+fi
+
+echo "Configuring the BTS tag pending hook..."
+
+TAGPENDING_URL="https://webhook.salsa.debian.org/tagpending/$DEBPKGNAME"
+curl --silent --output /dev/null -XPOST --header "PRIVATE-TOKEN: $SALSA_TOKEN" $SALSA_URL/projects/$PROJECT_ID/hooks \
+     --data "url=$TAGPENDING_URL&push_events=1&enable_ssl_verification=1"
+check_return_code
+
+if [ "$SALSA_GROUP" = "med-team" ] ; then
+    echo "Configuring the KGB hook for $SALSA_GROUP ..."
+    KGB_URL="http://kgb.debian.net:9418/webhook/?channel=debian-med%26network=oftc%26private=1%26use_color=1%26use_irc_notices=1%26squash_threshold=20"
+    curl --silent --output /dev/null -XPOST --header "PRIVATE-TOKEN: $SALSA_TOKEN" $SALSA_URL/projects/$PROJECT_ID/hooks \
+         --data "url=$KGB_URL&push_events=yes&issues_events=yes&merge_requests_events=yes&tag_push_events=yes&note_events=yes&job_events=yes&pipeline_events=yes&wiki_events=yes&enable_ssl_verification=yes"
+    check_return_code
+
+    echo "Configuring email notification on push to $SALSA_GROUP commit list ..."
+
+    curl --silent --output /dev/null -XPUT --header "PRIVATE-TOKEN: $SALSA_TOKEN" $SALSA_URL/projects/$PROJECT_ID/services/emails-on-push \
+         --data "recipients=debian-med-commit at lists.alioth.debian.org dispatch at tracker.debian.org"
+    check_return_code
+fi



View it on GitLab: https://salsa.debian.org/med-team/community/helper-scripts/-/commit/d64460c77dcba66d15bca46e470e3ab9002d92b8

-- 
View it on GitLab: https://salsa.debian.org/med-team/community/helper-scripts/-/commit/d64460c77dcba66d15bca46e470e3ab9002d92b8
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20200328/4fd4c0a2/attachment-0001.html>


More information about the debian-med-commit mailing list