Commit cf2d6cfe authored by Mehdi Dogguy's avatar Mehdi Dogguy

Initial import

parents
For the lazy people like me, here are a few simple scripts to interact with
gitlab's API and setup projects on Salsa (salsa.debian.org).
* import.sh https://anonscm.alioth.debian.org/git/pkg-foo/bar.git pkg-baz
Creates a new project 'bar' in group 'pkg-baz' from an old git repo hosted
in 'https://anonscm.alioth.debian.org/git/pkg-foo/bar.git'
* irker.sh foo \#debian-bar
Sets up IRC notifications for project 'foo' on IRC channel '#debian-bar'
* hook_tagpending.sh foo
Sets up a webhook for project 'foo' which marks bug appearing in commit
messages as 'pending' on Debian BTS.
* hook_close.sh
Sets up a webhook for project 'foo' which closes Debian BTS bugs appearing
in commit messages.
In order to use these scripts, you must create a 'salsarc' file with the
following content:
SALSA_URL="https://salsa.debian.org/api"
SALSA_TOKEN="...."
You may create API tokens by visiting your [personal access tokens](https://salsa.debian.org/profile/personal_access_tokens)
page.
Documentation of Salsa service can be found [here](https://wiki.debian.org/Salsa/Doc)
#!/bin/sh
# See https://wiki.debian.org/Salsa/Doc#Dealing_with_Debian_BTS_from_commit_messages
set -eu
. ./salsarc
if [ "$#" -ne 1 ] || [ -z "$1" ]; then
echo "Usage: $0 foo" >&2
echo " where 'foo' is the Salsa project name for which you want to setup the webhook" >&2
exit 1
fi
PROJECT_NAME="$1"
CLOSE_URL="https://webhook.salsa.debian.org/close/$PROJECT_NAME"
PROJECT_ID=$(curl --silent -f -XGET --header "PRIVATE-TOKEN: $SALSA_TOKEN" $SALSA_URL/v3/projects/owned | jq ".[] | select(.name == \"$PROJECT_NAME\") | .id")
if [ -z "$PROJECT_ID" ]; then
echo "Project $PROJECT_NAME not found among your owned projects on $SALSA_URL service" >&2
exit 1
else
echo "Setting up close webhook for $PROJECT_NAME ($PROJECT_ID)"
fi
ALREADY_HOOKED=$(curl --silent -f -XGET --header "PRIVATE-TOKEN: $SALSA_TOKEN" $SALSA_URL/v4/projects/$PROJECT_ID/hooks | jq ".[] | select(.url == \"$CLOSE_URL\") | .id")
case $ALREADY_HOOKED in
[0-9]*) echo "close service is already configured for $PROJECT_NAME" ;;
*) curl -XPOST --header "PRIVATE-TOKEN: $SALSA_TOKEN" \
$SALSA_URL/v4/projects/$PROJECT_ID/hooks \
--data "url=$CLOSE_URL&push_events=1&tag_push_events=1&merge_requests_events=1&enable_ssl_verification=1";
echo;
if [ $? -eq 0 ]; then
echo "All done."
else
echo "Something went wrong!"
fi;;
esac
#!/bin/sh
set -eu
. ./salsarc
if [ "$#" -ne 1 ] || [ -z "$1" ]; then
echo "Usage: $0 foo" >&2
echo " where 'foo' is the Salsa project name for which you want to setup the webhook" >&2
exit 1
fi
PROJECT_NAME="$1"
TAGPENDING_URL="https://webhook.salsa.debian.org/tagpending/$PROJECT_NAME"
PROJECT_ID=$(curl --silent -f -XGET --header "PRIVATE-TOKEN: $SALSA_TOKEN" $SALSA_URL/v3/projects/owned | jq ".[] | select(.name == \"$PROJECT_NAME\") | .id")
if [ -z "$PROJECT_ID" ]; then
echo "Project $PROJECT_NAME not found among your owned projects on $SALSA_URL service" >&2
exit 1
else
echo "Setting up tagpending webhook for $PROJECT_NAME ($PROJECT_ID)"
fi
ALREADY_HOOKED=$(curl --silent -f -XGET --header "PRIVATE-TOKEN: $SALSA_TOKEN" $SALSA_URL/v4/projects/$PROJECT_ID/hooks | jq ".[] | select(.url == \"$TAGPENDING_URL\") | .id")
case $ALREADY_HOOKED in
[0-9]*) echo "tagpending service is already configured for $PROJECT_NAME" ;;
*) curl -XPOST --header "PRIVATE-TOKEN: $SALSA_TOKEN" \
$SALSA_URL/v4/projects/$PROJECT_ID/hooks \
--data "url=$TAGPENDING_URL&push_events=1&tag_push_events=1&merge_requests_events=1&enable_ssl_verification=1";
echo;
if [ $? -eq 0 ]; then
echo "All done."
else
echo "Something went wrong!"
fi;;
esac
#!/bin/sh
set -eu
. ./salsarc
if [ "$#" -ne 2 ] || [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: $0 https://anonscm.alioth.debian.org/git/pkg-foo/bar.git pkg-baz" >&2
echo " where 'pkg-baz' is the name of the Salsa group which will host the new git" >&2
echo " repo for 'bar'" >&2
exit 1
fi
OLD_REPO_URL="$1"
SALSA_GROUP="$2"
REPO_NAME="${ALIOTH_URL##*/}"
PROJECT="${REPO_NAME%.git}"
DESCRIPTION="$PROJECT packaging"
SALSA_GROUP_ID=$(curl -f -XGET --header "PRIVATE-TOKEN: $SALSA_TOKEN" $SALSA_URL/v3/groups | jq ".[] | select(.path == \"$SALSA_GROUP\") | .id")
curl "$SALSA_URL/v4/projects?private_token=$SALSA_TOKEN" \
--data "path=$PROJECT&namespace_id=$SALSA_GROUP_ID&description=$DESCRIPTION&import_url=$OLD_REPO_URL&visibility=public"
#!/bin/sh
set -eu
. ./salsarc
if [ "$#" -ne 2 ] || [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: $0 foo \#debian-bar" >&2
echo " where 'foo' is the Salsa project name for which you want to setup irc notifications on channel #debian-bar" >&2
exit 1
fi
PROJECT_NAME="$1"
IRC_CHANNEL="$2"
IRKER_URL="ruprecht.snow-crash.org"
PROJECT_ID=$(curl --silent -f -XGET --header "PRIVATE-TOKEN: $SALSA_TOKEN" $SALSA_URL/v3/projects/owned | jq ".[] | select(.name == \"$PROJECT_NAME\") | .id")
if [ -z "$PROJECT_ID" ]; then
echo "Project $PROJECT_NAME not found among your owned projects on $SALSA_URL service" >&2
exit 1
else
echo "Setting up tagpending webhook for $PROJECT_NAME ($PROJECT_ID)"
fi
case $PROJECT_ID in
''|*[!0-9]*) echo "$PROJECT_NAME not found using $SALSA_URL service" ;;
*) curl -XPUT --header "PRIVATE-TOKEN: $SALSA_TOKEN" \
$SALSA_URL/v4/projects/$PROJECT_ID/services/irker \
--data "recipients=$IRC_CHANNEL&server_host=$IRKER_URL&colorize_messages=1";
echo;
if [ $? -eq 0 ]; then
echo "All done."
else
echo "Something went wrong!"
fi;;
esac
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment