From 7d59da852a19d258d2ba241fcb4ad724a374759b Mon Sep 17 00:00:00 2001 From: Ambrose Chua Date: Thu, 18 Jun 2020 12:43:48 +0800 Subject: [PATCH] Bump some things --- .brewfile | 2 +- .local/bin/update-drone-gitea-release | 52 +++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100755 .local/bin/update-drone-gitea-release diff --git a/.brewfile b/.brewfile index cf1cead..b9f9a13 100644 --- a/.brewfile +++ b/.brewfile @@ -15,7 +15,7 @@ brew "pinentry" # languages #brew "python3" #brew "go" -#brew "node" +brew "node" #brew "deno" # system #brew "grpc" diff --git a/.local/bin/update-drone-gitea-release b/.local/bin/update-drone-gitea-release new file mode 100755 index 0000000..ed00577 --- /dev/null +++ b/.local/bin/update-drone-gitea-release @@ -0,0 +1,52 @@ +#!/bin/bash + +DRONE_SERVER=${DRONE_SERVER:="https://ci.makerforce.io"} +DRONE_TOKEN=${DRONE_TOKEN:=""} + +echo +echo "This script updates drone-gitea-release token on all Drone repos" +echo + +path_to_httpie=$(which http) +if [ ! -x "$path_to_httpie" ] ; then + echo "HTTPie not installed. Please install it at (https://httpie.org/doc#installation)" +fi + +path_to_jq=$(which jq) +if [ ! -x "$path_to_jq" ] ; then + echo "JQ not installed. Please install it at (https://stedolan.github.io/jq/download/)" +fi + +if [ -z $DRONE_TOKEN ]; then + echo "Enter Drone token ($DRONE_SERVER/account/token)" + echo -n "> " + read DRONE_TOKEN + echo +fi + +echo "Enter drone-gitea-release token" +echo -n "> " +read gitea_token +echo +echo + +echo "Fetching repo list..." +repo_list=$(http GET $DRONE_SERVER/api/user/repos Authorization:"Bearer $DRONE_TOKEN" | jq .[].slug -r) + +for r in $repo_list; do + + echo "Updating gitea_token in $r..." + http --check-status -b PATCH \ + $DRONE_SERVER/api/repos/$r/secrets/gitea_token \ + Authorization:"Bearer $DRONE_TOKEN" \ + data="$gitea_token" \ + pull_request:=false \ + || http --check-status -b POST \ + $DRONE_SERVER/api/repos/$r/secrets \ + Authorization:"Bearer $DRONE_TOKEN" \ + name="gitea_token" \ + data="$gitea_token" \ + pull_request:=false + +done +