Commit 7fecf29e authored by Mehdi Dogguy's avatar Mehdi Dogguy

Optimize API queries (and use v4 only)

parent a29728f4
......@@ -28,7 +28,7 @@ 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_URL="https://salsa.debian.org/api/v4"
SALSA_TOKEN="...."
You may create API tokens by visiting your [personal access tokens](https://salsa.debian.org/profile/personal_access_tokens)
......
......@@ -18,7 +18,7 @@ else
RECIPIENTS="$2"
fi
PROJECT_ID=$(curl --silent -f -XGET --header "PRIVATE-TOKEN: $SALSA_TOKEN" $SALSA_URL/v3/projects/owned | jq ".[] | select(.name == \"$PROJECT_NAME\") | .id")
PROJECT_ID=$(curl --silent -f -XGET --header "PRIVATE-TOKEN: $SALSA_TOKEN" "$SALSA_URL/projects?membership=true&simple=true&search=$PROJECT_NAME" | 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
......@@ -29,7 +29,7 @@ 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/emails-on-push \
$SALSA_URL/projects/$PROJECT_ID/services/emails-on-push \
--data "recipients=$RECIPIENTS";
echo;
if [ $? -eq 0 ]; then
......
......@@ -14,7 +14,7 @@ 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")
PROJECT_ID=$(curl --silent -f -XGET --header "PRIVATE-TOKEN: $SALSA_TOKEN" "$SALSA_URL/projects?membership=true&simple=true&search=$PROJECT_NAME" | 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
......@@ -22,12 +22,12 @@ 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")
ALREADY_HOOKED=$(curl --silent -f -XGET --header "PRIVATE-TOKEN: $SALSA_TOKEN" $SALSA_URL/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 \
$SALSA_URL/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
......
......@@ -13,7 +13,7 @@ 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")
PROJECT_ID=$(curl --silent -f -XGET --header "PRIVATE-TOKEN: $SALSA_TOKEN" "$SALSA_URL/projects?membership=true&simple=true&search=$PROJECT_NAME" | 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
......@@ -21,12 +21,12 @@ 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")
ALREADY_HOOKED=$(curl --silent -f -XGET --header "PRIVATE-TOKEN: $SALSA_TOKEN" $SALSA_URL/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 \
$SALSA_URL/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
......
......@@ -17,9 +17,9 @@ REPO_NAME="${OLD_REPO_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")
SALSA_GROUP_ID=$(curl -f -XGET --header "PRIVATE-TOKEN: $SALSA_TOKEN" "$SALSA_URL/groups?all_available=false" | jq ".[] | select(.path == \"$SALSA_GROUP\") | .id")
curl "$SALSA_URL/v4/projects?private_token=$SALSA_TOKEN" \
curl "$SALSA_URL/projects?private_token=$SALSA_TOKEN" \
--data "path=$PROJECT&namespace_id=$SALSA_GROUP_ID&description=$DESCRIPTION&import_url=$OLD_REPO_URL&visibility=public"
if [ $? -ne 0 ]; then
echo
......
......@@ -14,7 +14,7 @@ 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")
PROJECT_ID=$(curl --silent -f -XGET --header "PRIVATE-TOKEN: $SALSA_TOKEN" "$SALSA_URL/projects?membership=true&simple=true&search=$PROJECT_NAME" | 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
......@@ -25,7 +25,7 @@ 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 \
$SALSA_URL/projects/$PROJECT_ID/services/irker \
--data "recipients=$IRC_CHANNEL&server_host=$IRKER_URL&colorize_messages=1";
echo;
if [ $? -eq 0 ]; then
......
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