forgejo-init-script/lib.sh
Aravinth Manivannan 02cef0aeaf
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
feat: skip installation
ref: ForgeFlux/ftest-control#2
2023-10-13 15:54:42 +05:30

165 lines
4.4 KiB
Bash
Executable file

# SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
is_ci(){
if [ -z ${CI+x} ];
then
return 1
else
return 0
fi
}
if is_ci
then
mkdir /tmp/forgejo-init-script
FORGEJO_USER1_ACCESS_TOKEN_FILE_PATH=/tmp/forgeo-init-scrit/user1-accesstoken.json
else
FORGEJO_USER1_ACCESS_TOKEN_FILE_PATH=tmp/user1-accesstoken.json
fi
readonly FORGEJO_ROOT_USERNAME=root
readonly FORGEJO_ROOT_EMAIL="$FORGEJO_ROOT_USERNAME@example.org"
readonly FORGEJO_ROOT_PASSOWRD=supercomplicatedpassword
readonly FORGEJO_USER1_USERNAME=john
readonly FORGEJO_USER1_PASSWORD=supercomplicatedpassword
readonly FORGEJO_USER1_EMAIL="$FORGEJO_USER1_USERNAME@example.org"
readonly FORGEJO_USER1_SUPPORT_REPO="test_repo"
readonly FORGEJO_USER1_ACCESS_TOKEN_NAME="coreaccesstoken"
rm $FORGEJO_USER1_ACCESS_TOKEN_FILE_PATH || true
readonly FORGEJO_TESTUSER_USERNAME=alice
readonly FORGEJO_TESTUSER_PASSWORD=supercomplicatedpassword
readonly FORGEJO_TESTUSER_EMAIL="$FORGEJO_TESTUSER_USERNAME@example.org"
wait_for_env() {
python -m forgejo \
check_env $FORGEJO_URL
}
# register root user on Forgejo to simulate Hoste admin and integrate SSO
forgejo_root(){
python -m forgejo \
forgejo register \
$FORGEJO_ROOT_USERNAME $FORGEJO_ROOT_PASSOWRD \
$FORGEJO_ROOT_EMAIL \
$FORGEJO_URL
python -m forgejo \
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 forgejo \
forgejo register \
$FORGEJO_USER1_USERNAME $FORGEJO_USER1_PASSWORD \
$FORGEJO_USER1_EMAIL \
$FORGEJO_URL
python -m forgejo \
forgejo login \
$FORGEJO_USER1_USERNAME $FORGEJO_USER1_PASSWORD \
$FORGEJO_USER1_EMAIL \
$FORGEJO_URL
python -m forgejo \
forgejo create_repo \
$FORGEJO_USER1_USERNAME $FORGEJO_USER1_PASSWORD \
$FORGEJO_USER1_EMAIL \
$FORGEJO_URL \
$FORGEJO_USER1_SUPPORT_REPO
python -m forgejo \
forgejo register \
$FORGEJO_TESTUSER_USERNAME $FORGEJO_TESTUSER_PASSWORD \
$FORGEJO_TESTUSER_EMAIL \
$FORGEJO_URL
python -m forgejo \
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 forgejo \
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 forgejo \
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 forgejo \
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 forgejo \
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 forgejo \
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"
python -m forgejo \
forgejo create_issue \
$FORGEJO_TESTUSER_USERNAME $FORGEJO_TESTUSER_PASSWORD \
$FORGEJO_USER1_EMAIL \
$FORGEJO_URL \
$FORGEJO_USER1_USERNAME \
$FORGEJO_USER1_SUPPORT_REPO \
"normal issue title and normal body" "normal body"
python -m forgejo \
forgejo create_access_token \
$FORGEJO_USER1_USERNAME $FORGEJO_USER1_PASSWORD \
$FORGEJO_USER1_EMAIL \
$FORGEJO_URL \
$FORGEJO_USER1_ACCESS_TOKEN_NAME \
$FORGEJO_USER1_ACCESS_TOKEN_FILE_PATH \
$FORGEJO_USER1_SUPPORT_REPO
}
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
}