forgejo-notifications-core/integration/lib.sh

172 lines
4.4 KiB
Bash
Raw Normal View History

is_ci(){
if [ -z ${CI+x} ];
then
return 1
else
return 0
fi
}
if is_ci
then
FORGEJO_URL="http://forgejo:3000"
FORGEJO_SSH_URL="ssh://git@forgejo:22"
else
FORGEJO_URL="http://localhost:3000"
FORGEJO_SSH_URL="ssh://git@localhost:22"
fi
readonly FORGEJO_ROOT_USERNAME=root
readonly FORGEJO_ROOT_EMAIL="$FORGEJO_ROOT_USERNAME@example.org"
readonly FORGEJO_ROOT_PASSOWRD=supercomplicatedpassword
readonly FORGEJO_USER1_USERNAME=owner_user
readonly FORGEJO_USER1_PASSWORD=supercomplicatedpassword
readonly FORGEJO_USER1_EMAIL="$FORGEJO_USER1_USERNAME@example.org"
readonly FORGEJO_USER1_SUPPORT_REPO="support"
2023-09-18 17:14:19 +05:30
readonly FORGEJO_USER1_ACCESS_TOKEN_NAME="coreaccesstoken"
readonly FORGEJO_USER1_ACCESS_TOKEN_FILE_PATH=$(realpath secrets/user1-accesstoken)
readonly FORGEJO_TESTUSER_USERNAME=test_user
readonly FORGEJO_TESTUSER_PASSWORD=supercomplicatedpassword
readonly FORGEJO_TESTUSER_EMAIL="$FORGEJO_TESTUSER_USERNAME@example.org"
wait_for_env() {
python -m integration \
check_env $FORGEJO_URL
}
# register root user on Forgejo to simulate Hoste admin and integrate SSO
forgejo_root(){
python -m integration \
forgejo install \
$FORGEJO_ROOT_USERNAME $FORGEJO_ROOT_PASSOWRD \
$FORGEJO_ROOT_EMAIL \
$FORGEJO_URL
python -m integration \
forgejo register \
$FORGEJO_ROOT_USERNAME $FORGEJO_ROOT_PASSOWRD \
$FORGEJO_ROOT_EMAIL \
$FORGEJO_URL
python -m integration \
forgejo login \
$FORGEJO_ROOT_USERNAME $FORGEJO_ROOT_PASSOWRD \
$FORGEJO_ROOT_EMAIL \
$FORGEJO_URL
}
# register user "Hostea" on Forgejo and create support repository
init_users_repo() {
python -m integration \
forgejo register \
$FORGEJO_USER1_USERNAME $FORGEJO_USER1_PASSWORD \
$FORGEJO_USER1_EMAIL \
$FORGEJO_URL
python -m integration \
forgejo login \
$FORGEJO_USER1_USERNAME $FORGEJO_USER1_PASSWORD \
$FORGEJO_USER1_EMAIL \
$FORGEJO_URL
python -m integration \
forgejo create_repo \
$FORGEJO_USER1_USERNAME $FORGEJO_USER1_PASSWORD \
$FORGEJO_USER1_EMAIL \
$FORGEJO_URL \
$FORGEJO_USER1_SUPPORT_REPO
python -m integration \
forgejo register \
$FORGEJO_TESTUSER_USERNAME $FORGEJO_TESTUSER_PASSWORD \
$FORGEJO_TESTUSER_EMAIL \
$FORGEJO_URL
python -m integration \
forgejo create_issue \
$FORGEJO_TESTUSER_USERNAME $FORGEJO_TESTUSER_PASSWORD \
$FORGEJO_USER1_EMAIL \
$FORGEJO_URL \
$FORGEJO_USER1_USERNAME \
$FORGEJO_USER1_SUPPORT_REPO \
"normal issue title" "normal issue body"
python -m integration \
forgejo create_comment \
$FORGEJO_TESTUSER_USERNAME $FORGEJO_TESTUSER_PASSWORD \
$FORGEJO_USER1_EMAIL \
$FORGEJO_URL \
$FORGEJO_USER1_USERNAME \
$FORGEJO_USER1_SUPPORT_REPO \
1 "normal body"
python -m integration \
forgejo create_comment \
$FORGEJO_TESTUSER_USERNAME $FORGEJO_TESTUSER_PASSWORD \
$FORGEJO_USER1_EMAIL \
$FORGEJO_URL \
$FORGEJO_USER1_USERNAME \
$FORGEJO_USER1_SUPPORT_REPO \
1 "mention body @$FORGEJO_USER1_USERNAME"
python -m integration \
forgejo create_issue \
$FORGEJO_TESTUSER_USERNAME $FORGEJO_TESTUSER_PASSWORD \
$FORGEJO_USER1_EMAIL \
$FORGEJO_URL \
$FORGEJO_USER1_USERNAME \
$FORGEJO_USER1_SUPPORT_REPO \
"normal issue title" "mention issue @$FORGEJO_USER1_USERNAME"
python -m integration \
forgejo create_issue \
$FORGEJO_TESTUSER_USERNAME $FORGEJO_TESTUSER_PASSWORD \
$FORGEJO_USER1_EMAIL \
$FORGEJO_URL \
$FORGEJO_USER1_USERNAME \
$FORGEJO_USER1_SUPPORT_REPO \
"mention issue @$FORGEJO_USER1_USERNAME" "normal issue body"
python -m integration \
forgejo create_issue \
$FORGEJO_TESTUSER_USERNAME $FORGEJO_TESTUSER_PASSWORD \
$FORGEJO_USER1_EMAIL \
$FORGEJO_URL \
$FORGEJO_USER1_USERNAME \
$FORGEJO_USER1_SUPPORT_REPO \
"mention issue @$FORGEJO_USER1_USERNAME" "mention issue @$FORGEJO_USER1_USERNAME"
2023-09-18 17:14:19 +05:30
python -m integration \
forgejo create_access_token \
$FORGEJO_TESTUSER_USERNAME $FORGEJO_TESTUSER_PASSWORD \
$FORGEJO_USER1_EMAIL \
$FORGEJO_URL \
$FORGEJO_USER1_ACCESS_TOKEN_NAME \
$FORGEJO_USER1_ACCESS_TOKEN_FILE_PATH
}
setup_env() {
# mkdir tmp/ || true
# nohup python manage.py runserver > /dev/null 2>&1 &
# SERVER_PID=$!
# echo $SERVER_PID > $SERVER_PID_FILE
echo "TODO"
}
teardown_env() {
echo "TODO"
#kill $(cat $SERVER_PID_FILE)
}
docker_compose_up() {
echo "[*] Starting Forgejo"
docker-compose -f docker-compose-dev-deps.yml up
}
docker_compose_down() {
docker-compose -f docker-compose-dev-deps.yml down
docker-compose -f docker-compose-dev-deps.yml down --remove-orphans
}