#!/bin/bash # SPDX-License-Identifier: MIT set -e SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source $SELF_DIR/../cascading-pr-lib.sh TMPDIR=/tmp/cascading-pr function push_self() { local host_port=$1 forgejo-test-helper.sh push_self_action http://root:admin1234@$host_port root cascading-pr vTest } function user_login() { local username=$1 ( export DOT=$TMPDIR/$username forgejo-curl.sh logout forgejo-curl.sh --user $username --password "${options[password]}" login ${options[url]} ) } function user_curl() { local username=$1 shift ( export DOT=$TMPDIR/$username forgejo-curl.sh "$@" ) } function create_user() { local username="$1" email="$2" forgejo-curl.sh api_json -X DELETE --data-raw '{"purge":true}' ${options[url]}/api/v1/admin/users/$username >& /dev/null || true forgejo-curl.sh api_json --data-raw '{"username":"'$username'","email":"'$email'","password":"'${options[password]}'","must_change_password":false}' ${options[url]}/api/v1/admin/users user_login $username } function run() { push_self ${options[host_port]} create_user user1 user1@example.com create_user user2 user2@example.com echo do something } function main() { local command=run options[host_port]=$(cat forgejo-ip):3000 options[url]=http://${options[host_port]} options[token]=$(cat forgejo-token) options[password]=admin1234 while true; do case "$1" in --verbose) shift verbose ;; --debug) shift debug ;; --host_port) shift options[host_port]=$1 ;; --url) shift options[url]=$1 ;; --token) shift options[token]=$1 ;; *) "${1:-run}" return 0 ;; esac done } ${MAIN:-main} "${@}"