[med-svn] [Git][med-team/community/helper-scripts][master] Restore old working inject-into-salsa-git and rename the attempt to work with subgroups
Andreas Tille (@tille)
gitlab at salsa.debian.org
Tue Jun 28 14:40:40 BST 2022
Andreas Tille pushed to branch master at Debian Med / community / helper-scripts
Commits:
0f4f30d9 by Andreas Tille at 2022-06-28T15:39:50+02:00
Restore old working inject-into-salsa-git and rename the attempt to work with subgroups
- - - - -
2 changed files:
- inject-into-salsa-git
- + inject-into-salsa-git_subgroups_but_private_repository
Changes:
=====================================
inject-into-salsa-git
=====================================
@@ -80,22 +80,11 @@ 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#'`
-SUBGROUP=`echo $VCSGIT | sed -e 's#.*://salsa.debian.org/[^/]\+/\([^/]\+\)/.*#\1#'`
-if [ "$VCSGIT" = "$SUBGROUP" ] ; then
- SUBGROUP=""
-fi
#echo $VCSGIT
#echo $SALSA_GROUP
-#echo $SUBGROUP
-if [ "$SUBGROUP" = "" ] ; then
- # no subgroup
- SALSA_GROUP_ID=$(curl -s -f -XGET "$SALSA_URL/groups/$SALSA_GROUP?with_projects=false" | jq '.id')
-else
- # curl -s -f -XGET "$SALSA_URL/groups/$SALSA_GROUP/subgroups?with_projects=false" | jq '.[] | "\(.id) \(.name)"'
- SALSA_GROUP_ID=$(curl -s -f -XGET "$SALSA_URL/groups/$SALSA_GROUP/subgroups?with_projects=false" | jq '.[] | "\(.id) \(.name)"' | grep $SUBGROUP | sed 's/^"\([0-9]\+\) \+.*"$/\1/')
-fi
+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"
@@ -106,10 +95,9 @@ fi
set +e
set -x
RESPONSE=$(curl "$SALSA_URL/projects?search=${DEBPKGNAME}")
-PROJECT_ID=`echo $RESPONSE | jq --exit-status "map(select(.path == \"${DEBPKGNAME}\")) | .[0].id"` # > /dev/null
-#echo "$PROJECT_ID"
+echo $RESPONSE | jq --exit-status "map(select(.path == \"${DEBPKGNAME}\")) | .[0].id" > /dev/null
set -e
-if [ "$PROJECT_ID" = "" ]; then
+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"
@@ -122,9 +110,14 @@ if [ "$PROJECT_ID" = "" ]; then
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
-remoteOrigin=`echo $VCSGIT | sed 's#^https://salsa.debian.org/#git@salsa.debian.org:#'`
+remoteOrigin="git at salsa.debian.org:${SALSA_GROUP}/${DEBPKGNAME}.git"
if git remote | grep -q origin ; then
echo "I: remote repository 'origin' is already existing"
if git remote -v | grep origin | grep -q "$remoteOrigin"; then
=====================================
inject-into-salsa-git_subgroups_but_private_repository
=====================================
@@ -0,0 +1,179 @@
+#!/bin/sh
+
+# Also, dpt-salsa (in pkg-perl-tools) might be able to do what you want
+
+# This is an attempt to teach inject-into-salsa-git to respect subgroups
+# Unfortunately the repositories created with this script ending up with private
+# permissions which is totally unwanted. It needs further debugging to fix this.
+
+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
+
+if [ ! -x /usr/bin/curl ]; then
+ echo "E: This package needs 'curl' 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#'`
+SUBGROUP=`echo $VCSGIT | sed -e 's#.*://salsa.debian.org/[^/]\+/\([^/]\+\)/.*#\1#'`
+if [ "$VCSGIT" = "$SUBGROUP" ] ; then
+ SUBGROUP=""
+fi
+
+#echo $VCSGIT
+#echo $SALSA_GROUP
+#echo $SUBGROUP
+
+if [ "$SUBGROUP" = "" ] ; then
+ # no subgroup
+ SALSA_GROUP_ID=$(curl -s -f -XGET "$SALSA_URL/groups/$SALSA_GROUP?with_projects=false" | jq '.id')
+else
+ # curl -s -f -XGET "$SALSA_URL/groups/$SALSA_GROUP/subgroups?with_projects=false" | jq '.[] | "\(.id) \(.name)"'
+ SALSA_GROUP_ID=$(curl -s -f -XGET "$SALSA_URL/groups/$SALSA_GROUP/subgroups?with_projects=false" | jq '.[] | "\(.id) \(.name)"' | grep $SUBGROUP | sed 's/^"\([0-9]\+\) \+.*"$/\1/')
+fi
+
+if [ "$SALSA_GROUP_ID" = "" ] ; then
+ echo "Failed to find group ID for $SALSA_GROUP"
+ exit 1
+fi
+
+# Did we already push to salsa?
+set +e
+set -x
+RESPONSE=$(curl "$SALSA_URL/projects?search=${DEBPKGNAME}")
+PROJECT_ID=`echo $RESPONSE | jq --exit-status "map(select(.path == \"${DEBPKGNAME}\")) | .[0].id"` # > /dev/null
+#echo "$PROJECT_ID"
+set -e
+if [ "$PROJECT_ID" = "" ]; 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
+fi
+
+remoteOrigin=`echo $VCSGIT | sed 's#^https://salsa.debian.org/#git@salsa.debian.org:#'`
+if git remote | grep -q origin ; then
+ echo "I: remote repository 'origin' is already existing"
+ if git remote -v | grep origin | grep -q "$remoteOrigin"; then
+ echo " But already set as wanted ($remoteOrigin) - nothing to do."
+ else
+ git remote rename origin origin-$(date +"%Y%m%dT%H%M%S")
+ git remote add origin $remoteOrigin
+ fi
+else
+ git remote add origin $remoteOrigin
+fi
+
+# Change config file - salsa tool does not find our token in ~/.ssh
+if ! SALSA_TOKEN=$SALSA_TOKEN salsa update_repo --ci-config-path debian/salsa-ci.yml ${SALSA_GROUP}/${DEBPKGNAME}; then
+ echo "W: Could not initiate CI for ${DEBPKGNAME}, please initiate"
+ echo " cd $(pwd) && salsa update_repo --ci-config-path debian/salsa-ci.yml ${SALSA_GROUP}/${DEBPKGNAME}"
+ echo " at a later time, e.g. after having been granted the permissions in ${SALSA_GROUP} reposiotry."
+fi
+
+echo "I: pushing to salsa"
+git push origin master
+git push --all --set-upstream
+git push --tags
+
+# Stolen from ~/debian-maintain/salsa/java-team/pkg-java-scripts/setup-salsa-repository"
+
+# -----------------------------------------------------------------------------
+
+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¬e_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/0f4f30d97396a39d5f3eb40615417ec9d05a8663
--
View it on GitLab: https://salsa.debian.org/med-team/community/helper-scripts/-/commit/0f4f30d97396a39d5f3eb40615417ec9d05a8663
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/20220628/800d3b18/attachment-0001.htm>
More information about the debian-med-commit
mailing list